1 // RUN: tblgen-to-irdl %s -I=%S/../../include --gen-dialect-irdl-defs --dialect=test | FileCheck %s
3 include "mlir/IR/OpBase.td"
4 include "mlir/IR/AttrTypeBase.td"
6 // CHECK-LABEL: irdl.dialect @test {
7 def Test_Dialect : Dialect {
11 class Test_Type<string name, string typeMnemonic, list<Trait> traits = []>
12 : TypeDef<Test_Dialect, name, traits> {
13 let mnemonic = typeMnemonic;
16 class Test_Attr<string name, string attrMnemonic> : AttrDef<Test_Dialect, name> {
17 let mnemonic = attrMnemonic;
20 class Test_Op<string mnemonic, list<Trait> traits = []>
21 : Op<Test_Dialect, mnemonic, traits>;
23 // CHECK: irdl.type @"!singleton_a"
24 def Test_SingletonAType : Test_Type<"SingletonAType", "singleton_a"> {}
25 // CHECK: irdl.type @"!singleton_b"
26 def Test_SingletonBType : Test_Type<"SingletonBType", "singleton_b"> {}
27 // CHECK: irdl.type @"!singleton_c"
28 def Test_SingletonCType : Test_Type<"SingletonCType", "singleton_c"> {}
29 // CHECK: irdl.attribute @"#test"
30 def Test_TestAttr : Test_Attr<"Test", "test"> {}
33 // Check that AllOfType is converted correctly.
34 def Test_AndOp : Test_Op<"and"> {
35 let arguments = (ins AllOfType<[Test_SingletonAType, AnyType]>:$in);
37 // CHECK-LABEL: irdl.operation @and {
38 // CHECK-NEXT: %[[v0:[^ ]*]] = irdl.base @test::@"!singleton_a"
39 // CHECK-NEXT: %[[v1:[^ ]*]] = irdl.any
40 // CHECK-NEXT: %[[v2:[^ ]*]] = irdl.all_of(%[[v0]], %[[v1]])
41 // CHECK-NEXT: irdl.operands(%[[v2]])
45 // Check that AnyType is converted correctly.
46 def Test_AnyOp : Test_Op<"any"> {
47 let arguments = (ins AnyType:$in);
49 // CHECK-LABEL: irdl.operation @any {
50 // CHECK-NEXT: %[[v0:[^ ]*]] = irdl.any
51 // CHECK-NEXT: irdl.operands(%[[v0]])
54 // Check attributes are converted correctly.
55 def Test_AttributesOp : Test_Op<"attributes"> {
56 let arguments = (ins I16Attr:$int_attr,
57 Test_TestAttr:$test_attr);
59 // CHECK-LABEL: irdl.operation @attributes {
60 // CHECK-NEXT: %[[v0:[^ ]*]] = irdl.base "!builtin.integer"
61 // CHECK-NEXT: %[[v1:[^ ]*]] = irdl.base @test::@"#test"
62 // CHECK-NEXT: irdl.attributes {"int_attr" = %[[v0]], "test_attr" = %[[v1]]}
65 // Check confined types are converted correctly.
66 def Test_ConfinedOp : Test_Op<"confined"> {
67 let arguments = (ins ConfinedType<AnyType, [CPred<"::llvm::isa<::mlir::TensorType>($_self)">]>:$tensor,
68 ConfinedType<AnyType, [And<[CPred<"::llvm::isa<::mlir::VectorType>($_self)">
69 , CPred<"::llvm::cast<::mlir::VectorType>($_self).getRank() > 0">]>]>:$vector);
71 // CHECK-LABEL: irdl.operation @confined {
72 // CHECK-NEXT: %[[v0:[^ ]*]] = irdl.any
73 // CHECK-NEXT: %[[v1:[^ ]*]] = irdl.c_pred "(::llvm::isa<::mlir::TensorType>($_self))"
74 // CHECK-NEXT: %[[v2:[^ ]*]] = irdl.all_of(%[[v0]], %[[v1]])
75 // CHECK-NEXT: %[[v3:[^ ]*]] = irdl.any
76 // CHECK-NEXT: %[[v4:[^ ]*]] = irdl.c_pred "(::llvm::isa<::mlir::VectorType>($_self))"
77 // CHECK-NEXT: %[[v5:[^ ]*]] = irdl.c_pred "(::llvm::cast<::mlir::VectorType>($_self).getRank() > 0)"
78 // CHECK-NEXT: %[[v6:[^ ]*]] = irdl.all_of(%[[v4]], %[[v5]])
79 // CHECK-NEXT: %[[v7:[^ ]*]] = irdl.all_of(%[[v3]], %[[v6]])
80 // CHECK-NEXT: irdl.operands(%[[v2]], %[[v7]])
83 // Check generic integer types are converted correctly.
84 def Test_Integers : Test_Op<"integers"> {
85 let arguments = (ins AnyI8:$any_int,
86 AnyInteger:$any_integer);
88 // CHECK-LABEL: irdl.operation @integers {
89 // CHECK-NEXT: %[[v0:[^ ]*]] = irdl.is i8
90 // CHECK-NEXT: %[[v1:[^ ]*]] = irdl.is si8
91 // CHECK-NEXT: %[[v2:[^ ]*]] = irdl.is ui8
92 // CHECK-NEXT: %[[v3:[^ ]*]] = irdl.any_of(%[[v0]], %[[v1]], %[[v2]])
93 // CHECK-NEXT: %[[v4:[^ ]*]] = irdl.base "!builtin.integer"
94 // CHECK-NEXT: irdl.operands(%[[v3]], %[[v4]])
97 // Check that AnyTypeOf is converted correctly.
98 def Test_OrOp : Test_Op<"or"> {
99 let arguments = (ins AnyTypeOf<[Test_SingletonAType, Test_SingletonBType, Test_SingletonCType]>:$in);
101 // CHECK-LABEL: irdl.operation @or {
102 // CHECK-NEXT: %[[v0:[^ ]*]] = irdl.base @test::@"!singleton_a"
103 // CHECK-NEXT: %[[v1:[^ ]*]] = irdl.base @test::@"!singleton_b"
104 // CHECK-NEXT: %[[v2:[^ ]*]] = irdl.base @test::@"!singleton_c"
105 // CHECK-NEXT: %[[v3:[^ ]*]] = irdl.any_of(%[[v0]], %[[v1]], %[[v2]])
106 // CHECK-NEXT: irdl.operands(%[[v3]])
109 // Check regions are converted correctly.
110 def Test_RegionsOp : Test_Op<"regions"> {
111 let regions = (region AnyRegion:$any_region,
112 SizedRegion<1>:$single_block_region);
114 // CHECK-LABEL: irdl.operation @regions {
115 // CHECK-NEXT: %[[v0:[^ ]*]] = irdl.region
116 // CHECK-NEXT: %[[v1:[^ ]*]] = irdl.region with size 1
117 // CHECK-NEXT: irdl.regions(%[[v0]], %[[v1]])
120 // Check that various types are converted correctly.
121 def Test_TypesOp : Test_Op<"types"> {
122 let arguments = (ins I32:$a,
130 // CHECK-LABEL: irdl.operation @types {
131 // CHECK-NEXT: %{{.*}} = irdl.is i32
132 // CHECK-NEXT: %{{.*}} = irdl.is si64
133 // CHECK-NEXT: %{{.*}} = irdl.is ui8
134 // CHECK-NEXT: %{{.*}} = irdl.is index
135 // CHECK-NEXT: %{{.*}} = irdl.is f32
136 // CHECK-NEXT: %{{.*}} = irdl.is none
137 // CHECK-NEXT: %{{.*}} = irdl.is complex<f8E4M3FN>
138 // CHECK-NEXT: irdl.operands({{.*}})
141 // Check that variadics and optionals are converted correctly.
142 def Test_VariadicityOp : Test_Op<"variadicity"> {
143 let arguments = (ins Variadic<Test_SingletonAType>:$variadic,
144 Optional<Test_SingletonBType>:$optional,
145 Test_SingletonCType:$required);
147 // CHECK-LABEL: irdl.operation @variadicity {
148 // CHECK-NEXT: %[[v0:[^ ]*]] = irdl.base @test::@"!singleton_a"
149 // CHECK-NEXT: %[[v1:[^ ]*]] = irdl.base @test::@"!singleton_b"
150 // CHECK-NEXT: %[[v2:[^ ]*]] = irdl.base @test::@"!singleton_c"
151 // CHECK-NEXT: irdl.operands(variadic %[[v0]], optional %[[v1]], %[[v2]])