mirror of
https://github.com/intel/llvm.git
synced 2026-01-19 17:45:07 +08:00
Introduce the initial support for operation interfaces in C API and Python bindings. Interfaces are a key component of MLIR's extensibility and should be available in bindings to make use of full potential of MLIR. This initial implementation exposes InferTypeOpInterface all the way to the Python bindings since it can be later used to simplify the operation construction methods by inferring their return types instead of requiring the user to do so. The general infrastructure for binding interfaces is defined and InferTypeOpInterface can be used as an example for binding other interfaces. Reviewed By: gysit Differential Revision: https://reviews.llvm.org/D111656
56 lines
1.8 KiB
TableGen
56 lines
1.8 KiB
TableGen
//===-- python_test_ops.td - Python test Op definitions ----*- tablegen -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef PYTHON_TEST_OPS
|
|
#define PYTHON_TEST_OPS
|
|
|
|
include "mlir/Bindings/Python/Attributes.td"
|
|
include "mlir/IR/OpBase.td"
|
|
include "mlir/Interfaces/InferTypeOpInterface.td"
|
|
|
|
def Python_Test_Dialect : Dialect {
|
|
let name = "python_test";
|
|
let cppNamespace = "python_test";
|
|
}
|
|
class TestOp<string mnemonic, list<OpTrait> traits = []>
|
|
: Op<Python_Test_Dialect, mnemonic, traits>;
|
|
|
|
def AttributedOp : TestOp<"attributed_op"> {
|
|
let arguments = (ins I32Attr:$mandatory_i32,
|
|
OptionalAttr<I32Attr>:$optional_i32,
|
|
UnitAttr:$unit);
|
|
}
|
|
|
|
def PropertyOp : TestOp<"property_op"> {
|
|
let arguments = (ins I32Attr:$property,
|
|
I32:$idx);
|
|
}
|
|
|
|
def DummyOp : TestOp<"dummy_op"> {
|
|
}
|
|
|
|
def InferResultsOp : TestOp<"infer_results_op", [InferTypeOpInterface]> {
|
|
let arguments = (ins);
|
|
let results = (outs AnyInteger:$single, AnyInteger:$doubled);
|
|
|
|
let extraClassDeclaration = [{
|
|
static ::mlir::LogicalResult inferReturnTypes(
|
|
::mlir::MLIRContext *context, ::llvm::Optional<::mlir::Location> location,
|
|
::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes,
|
|
::mlir::RegionRange regions,
|
|
::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) {
|
|
::mlir::Builder b(context);
|
|
inferredReturnTypes.push_back(b.getI32Type());
|
|
inferredReturnTypes.push_back(b.getI64Type());
|
|
return ::mlir::success();
|
|
}
|
|
}];
|
|
}
|
|
|
|
#endif // PYTHON_TEST_OPS
|