comparison mlir/test/python/python_test_ops.td @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 5f17cb93ff66
children 1f2b6ac9f198
comparison
equal deleted inserted replaced
232:70dce7da266c 236:c4bab56944e8
7 //===----------------------------------------------------------------------===// 7 //===----------------------------------------------------------------------===//
8 8
9 #ifndef PYTHON_TEST_OPS 9 #ifndef PYTHON_TEST_OPS
10 #define PYTHON_TEST_OPS 10 #define PYTHON_TEST_OPS
11 11
12 include "mlir/IR/AttrTypeBase.td"
12 include "mlir/Bindings/Python/Attributes.td" 13 include "mlir/Bindings/Python/Attributes.td"
13 include "mlir/IR/OpBase.td" 14 include "mlir/IR/OpBase.td"
15 include "mlir/Interfaces/InferTypeOpInterface.td"
14 16
15 def Python_Test_Dialect : Dialect { 17 def Python_Test_Dialect : Dialect {
16 let name = "python_test"; 18 let name = "python_test";
17 let cppNamespace = "PythonTest"; 19 let cppNamespace = "python_test";
20
21 let useDefaultTypePrinterParser = 1;
22 let useDefaultAttributePrinterParser = 1;
18 } 23 }
19 class TestOp<string mnemonic, list<OpTrait> traits = []> 24
25 class TestType<string name, string typeMnemonic>
26 : TypeDef<Python_Test_Dialect, name> {
27 let mnemonic = typeMnemonic;
28 }
29
30 class TestAttr<string name, string attrMnemonic>
31 : AttrDef<Python_Test_Dialect, name> {
32 let mnemonic = attrMnemonic;
33 }
34
35 class TestOp<string mnemonic, list<Trait> traits = []>
20 : Op<Python_Test_Dialect, mnemonic, traits>; 36 : Op<Python_Test_Dialect, mnemonic, traits>;
37
38 //===----------------------------------------------------------------------===//
39 // Type definitions.
40 //===----------------------------------------------------------------------===//
41
42 def TestType : TestType<"TestType", "test_type">;
43
44 //===----------------------------------------------------------------------===//
45 // Attribute definitions.
46 //===----------------------------------------------------------------------===//
47
48 def TestAttr : TestAttr<"TestAttr", "test_attr">;
49
50 //===----------------------------------------------------------------------===//
51 // Operation definitions.
52 //===----------------------------------------------------------------------===//
21 53
22 def AttributedOp : TestOp<"attributed_op"> { 54 def AttributedOp : TestOp<"attributed_op"> {
23 let arguments = (ins I32Attr:$mandatory_i32, 55 let arguments = (ins I32Attr:$mandatory_i32,
24 OptionalAttr<I32Attr>:$optional_i32, 56 OptionalAttr<I32Attr>:$optional_i32,
25 UnitAttr:$unit); 57 UnitAttr:$unit);
28 def PropertyOp : TestOp<"property_op"> { 60 def PropertyOp : TestOp<"property_op"> {
29 let arguments = (ins I32Attr:$property, 61 let arguments = (ins I32Attr:$property,
30 I32:$idx); 62 I32:$idx);
31 } 63 }
32 64
65 def DummyOp : TestOp<"dummy_op"> {
66 }
67
68 def InferResultsOp : TestOp<"infer_results_op", [InferTypeOpInterface]> {
69 let arguments = (ins);
70 let results = (outs AnyInteger:$single, AnyInteger:$doubled);
71
72 let extraClassDeclaration = [{
73 static ::mlir::LogicalResult inferReturnTypes(
74 ::mlir::MLIRContext *context, ::llvm::Optional<::mlir::Location> location,
75 ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes,
76 ::mlir::RegionRange regions,
77 ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) {
78 ::mlir::Builder b(context);
79 inferredReturnTypes.push_back(b.getI32Type());
80 inferredReturnTypes.push_back(b.getI64Type());
81 return ::mlir::success();
82 }
83 }];
84 }
85
86 // If all result types are buildable, the InferTypeOpInterface is implied and is
87 // autogenerated by C++ ODS.
88 def InferResultsImpliedOp : TestOp<"infer_results_implied_op"> {
89 let results = (outs I32:$integer, F64:$flt, Index:$index);
90 }
91
92 def SameOperandAndResultTypeOp : TestOp<"same_operand_and_result_type_op",
93 [SameOperandsAndResultType]> {
94 let arguments = (ins Variadic<AnyType>);
95 let results = (outs AnyType:$one, AnyType:$two);
96 }
97
98 def FirstAttrDeriveTypeAttrOp : TestOp<"first_attr_derive_type_attr_op",
99 [FirstAttrDerivedResultType]> {
100 let arguments = (ins AnyType:$input, TypeAttr:$type);
101 let results = (outs AnyType:$one, AnyType:$two);
102 }
103
104 def FirstAttrDeriveAttrOp : TestOp<"first_attr_derive_attr_op",
105 [FirstAttrDerivedResultType]> {
106 let arguments = (ins AnyAttr:$iattr);
107 let results = (outs AnyType:$one, AnyType:$two, AnyType:$three);
108 }
109
110 def OptionalOperandOp : TestOp<"optional_operand_op"> {
111 let arguments = (ins Optional<AnyType>:$input);
112 let results = (outs I32:$result);
113 }
114
33 #endif // PYTHON_TEST_OPS 115 #endif // PYTHON_TEST_OPS