1a64975f9SFehr Mathieu// RUN: tblgen-to-irdl %s -I=%S/../../include --gen-dialect-irdl-defs --dialect=test | FileCheck %s 2a64975f9SFehr Mathieu 3a64975f9SFehr Mathieuinclude "mlir/IR/OpBase.td" 4a64975f9SFehr Mathieuinclude "mlir/IR/AttrTypeBase.td" 5a64975f9SFehr Mathieu 6a64975f9SFehr Mathieu// CHECK-LABEL: irdl.dialect @test { 7a64975f9SFehr Mathieudef Test_Dialect : Dialect { 8a64975f9SFehr Mathieu let name = "test"; 9a64975f9SFehr Mathieu} 10a64975f9SFehr Mathieu 11a64975f9SFehr Mathieuclass Test_Type<string name, string typeMnemonic, list<Trait> traits = []> 12a64975f9SFehr Mathieu: TypeDef<Test_Dialect, name, traits> { 13a64975f9SFehr Mathieu let mnemonic = typeMnemonic; 14a64975f9SFehr Mathieu} 15a64975f9SFehr Mathieu 16159470deSAlex Riceclass Test_Attr<string name, string attrMnemonic> : AttrDef<Test_Dialect, name> { 17159470deSAlex Rice let mnemonic = attrMnemonic; 18159470deSAlex Rice} 19159470deSAlex Rice 20a64975f9SFehr Mathieuclass Test_Op<string mnemonic, list<Trait> traits = []> 21a64975f9SFehr Mathieu : Op<Test_Dialect, mnemonic, traits>; 22a64975f9SFehr Mathieu 2304575dceSAlex Rice// CHECK: irdl.type @"!singleton_a" 24a64975f9SFehr Mathieudef Test_SingletonAType : Test_Type<"SingletonAType", "singleton_a"> {} 2504575dceSAlex Rice// CHECK: irdl.type @"!singleton_b" 26a64975f9SFehr Mathieudef Test_SingletonBType : Test_Type<"SingletonBType", "singleton_b"> {} 2704575dceSAlex Rice// CHECK: irdl.type @"!singleton_c" 28a64975f9SFehr Mathieudef Test_SingletonCType : Test_Type<"SingletonCType", "singleton_c"> {} 29159470deSAlex Rice// CHECK: irdl.attribute @"#test" 30159470deSAlex Ricedef Test_TestAttr : Test_Attr<"Test", "test"> {} 31a64975f9SFehr Mathieu 32a64975f9SFehr Mathieu 33a64975f9SFehr Mathieu// Check that AllOfType is converted correctly. 34a64975f9SFehr Mathieudef Test_AndOp : Test_Op<"and"> { 35a64975f9SFehr Mathieu let arguments = (ins AllOfType<[Test_SingletonAType, AnyType]>:$in); 36a64975f9SFehr Mathieu} 37a64975f9SFehr Mathieu// CHECK-LABEL: irdl.operation @and { 3804575dceSAlex Rice// CHECK-NEXT: %[[v0:[^ ]*]] = irdl.base @test::@"!singleton_a" 39a64975f9SFehr Mathieu// CHECK-NEXT: %[[v1:[^ ]*]] = irdl.any 40a64975f9SFehr Mathieu// CHECK-NEXT: %[[v2:[^ ]*]] = irdl.all_of(%[[v0]], %[[v1]]) 41*69d3ba3dSThéo Degioanni// CHECK-NEXT: irdl.operands(in: %[[v2]]) 42a64975f9SFehr Mathieu// CHECK-NEXT: } 43a64975f9SFehr Mathieu 44a64975f9SFehr Mathieu 45a64975f9SFehr Mathieu// Check that AnyType is converted correctly. 46a64975f9SFehr Mathieudef Test_AnyOp : Test_Op<"any"> { 47a64975f9SFehr Mathieu let arguments = (ins AnyType:$in); 48a64975f9SFehr Mathieu} 49a64975f9SFehr Mathieu// CHECK-LABEL: irdl.operation @any { 50a64975f9SFehr Mathieu// CHECK-NEXT: %[[v0:[^ ]*]] = irdl.any 51*69d3ba3dSThéo Degioanni// CHECK-NEXT: irdl.operands(in: %[[v0]]) 52a64975f9SFehr Mathieu// CHECK-NEXT: } 53a64975f9SFehr Mathieu 54159470deSAlex Rice// Check attributes are converted correctly. 55159470deSAlex Ricedef Test_AttributesOp : Test_Op<"attributes"> { 56159470deSAlex Rice let arguments = (ins I16Attr:$int_attr, 57159470deSAlex Rice Test_TestAttr:$test_attr); 58159470deSAlex Rice} 59159470deSAlex Rice// CHECK-LABEL: irdl.operation @attributes { 60159470deSAlex Rice// CHECK-NEXT: %[[v0:[^ ]*]] = irdl.base "!builtin.integer" 61159470deSAlex Rice// CHECK-NEXT: %[[v1:[^ ]*]] = irdl.base @test::@"#test" 62159470deSAlex Rice// CHECK-NEXT: irdl.attributes {"int_attr" = %[[v0]], "test_attr" = %[[v1]]} 63159470deSAlex Rice// CHECK-NEXT: } 64159470deSAlex Rice 65135bd319SAlex Rice// Check confined types are converted correctly. 66135bd319SAlex Ricedef Test_ConfinedOp : Test_Op<"confined"> { 67135bd319SAlex Rice let arguments = (ins ConfinedType<AnyType, [CPred<"::llvm::isa<::mlir::TensorType>($_self)">]>:$tensor, 68135bd319SAlex Rice ConfinedType<AnyType, [And<[CPred<"::llvm::isa<::mlir::VectorType>($_self)"> 69135bd319SAlex Rice , CPred<"::llvm::cast<::mlir::VectorType>($_self).getRank() > 0">]>]>:$vector); 70135bd319SAlex Rice} 71135bd319SAlex Rice// CHECK-LABEL: irdl.operation @confined { 72135bd319SAlex Rice// CHECK-NEXT: %[[v0:[^ ]*]] = irdl.any 73135bd319SAlex Rice// CHECK-NEXT: %[[v1:[^ ]*]] = irdl.c_pred "(::llvm::isa<::mlir::TensorType>($_self))" 74135bd319SAlex Rice// CHECK-NEXT: %[[v2:[^ ]*]] = irdl.all_of(%[[v0]], %[[v1]]) 75135bd319SAlex Rice// CHECK-NEXT: %[[v3:[^ ]*]] = irdl.any 76135bd319SAlex Rice// CHECK-NEXT: %[[v4:[^ ]*]] = irdl.c_pred "(::llvm::isa<::mlir::VectorType>($_self))" 77135bd319SAlex Rice// CHECK-NEXT: %[[v5:[^ ]*]] = irdl.c_pred "(::llvm::cast<::mlir::VectorType>($_self).getRank() > 0)" 78135bd319SAlex Rice// CHECK-NEXT: %[[v6:[^ ]*]] = irdl.all_of(%[[v4]], %[[v5]]) 79135bd319SAlex Rice// CHECK-NEXT: %[[v7:[^ ]*]] = irdl.all_of(%[[v3]], %[[v6]]) 80*69d3ba3dSThéo Degioanni// CHECK-NEXT: irdl.operands(tensor: %[[v2]], vector: %[[v7]]) 81135bd319SAlex Rice// CHECK-NEXT: } 82135bd319SAlex Rice 83135bd319SAlex Rice// Check generic integer types are converted correctly. 84135bd319SAlex Ricedef Test_Integers : Test_Op<"integers"> { 85135bd319SAlex Rice let arguments = (ins AnyI8:$any_int, 86135bd319SAlex Rice AnyInteger:$any_integer); 87135bd319SAlex Rice} 88135bd319SAlex Rice// CHECK-LABEL: irdl.operation @integers { 89135bd319SAlex Rice// CHECK-NEXT: %[[v0:[^ ]*]] = irdl.is i8 90135bd319SAlex Rice// CHECK-NEXT: %[[v1:[^ ]*]] = irdl.is si8 91135bd319SAlex Rice// CHECK-NEXT: %[[v2:[^ ]*]] = irdl.is ui8 92135bd319SAlex Rice// CHECK-NEXT: %[[v3:[^ ]*]] = irdl.any_of(%[[v0]], %[[v1]], %[[v2]]) 93135bd319SAlex Rice// CHECK-NEXT: %[[v4:[^ ]*]] = irdl.base "!builtin.integer" 94*69d3ba3dSThéo Degioanni// CHECK-NEXT: irdl.operands(any_int: %[[v3]], any_integer: %[[v4]]) 95*69d3ba3dSThéo Degioanni// CHECK-NEXT: } 96*69d3ba3dSThéo Degioanni 97*69d3ba3dSThéo Degioanni// Check that IRDL names are properly generated when needed. 98*69d3ba3dSThéo Degioannidef Test_NamesOp : Test_Op<"names"> { 99*69d3ba3dSThéo Degioanni let arguments = (ins I32:$a, 100*69d3ba3dSThéo Degioanni I32:$_hello, 101*69d3ba3dSThéo Degioanni I32:$unnamed0, 102*69d3ba3dSThéo Degioanni I32); 103*69d3ba3dSThéo Degioanni let regions = (region AnyRegion:$unnamed1); 104*69d3ba3dSThéo Degioanni let results = (outs I32:$unnamed2); 105*69d3ba3dSThéo Degioanni} 106*69d3ba3dSThéo Degioanni// CHECK-LABEL: irdl.operation @names { 107*69d3ba3dSThéo Degioanni// CHECK-NEXT: %[[v0:[^ ]*]] = irdl.is i32 108*69d3ba3dSThéo Degioanni// CHECK-NEXT: %[[v1:[^ ]*]] = irdl.is i32 109*69d3ba3dSThéo Degioanni// CHECK-NEXT: %[[v2:[^ ]*]] = irdl.is i32 110*69d3ba3dSThéo Degioanni// CHECK-NEXT: %[[v3:[^ ]*]] = irdl.is i32 111*69d3ba3dSThéo Degioanni// CHECK-NEXT: %[[v4:[^ ]*]] = irdl.is i32 112*69d3ba3dSThéo Degioanni// CHECK-NEXT: %[[reg:[^ ]*]] = irdl.region 113*69d3ba3dSThéo Degioanni// CHECK-NEXT: irdl.operands(a: %[[v0]], _hello: %[[v1]], unnamed0: %[[v2]], unnamed3: %[[v3]]) 114*69d3ba3dSThéo Degioanni// CHECK-NEXT: irdl.results(unnamed2: %[[v4]]) 115*69d3ba3dSThéo Degioanni// CHECK-NEXT: irdl.regions(unnamed1: %[[reg]]) 116135bd319SAlex Rice// CHECK-NEXT: } 117a64975f9SFehr Mathieu 118a64975f9SFehr Mathieu// Check that AnyTypeOf is converted correctly. 119a64975f9SFehr Mathieudef Test_OrOp : Test_Op<"or"> { 120a64975f9SFehr Mathieu let arguments = (ins AnyTypeOf<[Test_SingletonAType, Test_SingletonBType, Test_SingletonCType]>:$in); 121a64975f9SFehr Mathieu} 122a64975f9SFehr Mathieu// CHECK-LABEL: irdl.operation @or { 12304575dceSAlex Rice// CHECK-NEXT: %[[v0:[^ ]*]] = irdl.base @test::@"!singleton_a" 12404575dceSAlex Rice// CHECK-NEXT: %[[v1:[^ ]*]] = irdl.base @test::@"!singleton_b" 12504575dceSAlex Rice// CHECK-NEXT: %[[v2:[^ ]*]] = irdl.base @test::@"!singleton_c" 126a64975f9SFehr Mathieu// CHECK-NEXT: %[[v3:[^ ]*]] = irdl.any_of(%[[v0]], %[[v1]], %[[v2]]) 127*69d3ba3dSThéo Degioanni// CHECK-NEXT: irdl.operands(in: %[[v3]]) 128a64975f9SFehr Mathieu// CHECK-NEXT: } 129a64975f9SFehr Mathieu 1305762bd60SAlex Rice// Check regions are converted correctly. 1315762bd60SAlex Ricedef Test_RegionsOp : Test_Op<"regions"> { 1325762bd60SAlex Rice let regions = (region AnyRegion:$any_region, 1335762bd60SAlex Rice SizedRegion<1>:$single_block_region); 1345762bd60SAlex Rice} 1355762bd60SAlex Rice// CHECK-LABEL: irdl.operation @regions { 1365762bd60SAlex Rice// CHECK-NEXT: %[[v0:[^ ]*]] = irdl.region 1375762bd60SAlex Rice// CHECK-NEXT: %[[v1:[^ ]*]] = irdl.region with size 1 138*69d3ba3dSThéo Degioanni// CHECK-NEXT: irdl.regions(any_region: %[[v0]], single_block_region: %[[v1]]) 1395762bd60SAlex Rice// CHECK-NEXT: } 1405762bd60SAlex Rice 141135bd319SAlex Rice// Check that various types are converted correctly. 142135bd319SAlex Ricedef Test_TypesOp : Test_Op<"types"> { 143135bd319SAlex Rice let arguments = (ins I32:$a, 144135bd319SAlex Rice SI64:$b, 145135bd319SAlex Rice UI8:$c, 146135bd319SAlex Rice Index:$d, 147135bd319SAlex Rice F32:$e, 148135bd319SAlex Rice NoneType:$f, 149135bd319SAlex Rice Complex<F8E4M3FN>); 150135bd319SAlex Rice} 151135bd319SAlex Rice// CHECK-LABEL: irdl.operation @types { 152135bd319SAlex Rice// CHECK-NEXT: %{{.*}} = irdl.is i32 153135bd319SAlex Rice// CHECK-NEXT: %{{.*}} = irdl.is si64 154135bd319SAlex Rice// CHECK-NEXT: %{{.*}} = irdl.is ui8 155135bd319SAlex Rice// CHECK-NEXT: %{{.*}} = irdl.is index 156135bd319SAlex Rice// CHECK-NEXT: %{{.*}} = irdl.is f32 157135bd319SAlex Rice// CHECK-NEXT: %{{.*}} = irdl.is none 158135bd319SAlex Rice// CHECK-NEXT: %{{.*}} = irdl.is complex<f8E4M3FN> 159135bd319SAlex Rice// CHECK-NEXT: irdl.operands({{.*}}) 160135bd319SAlex Rice// CHECK-NEXT: } 161a64975f9SFehr Mathieu 162a64975f9SFehr Mathieu// Check that variadics and optionals are converted correctly. 163a64975f9SFehr Mathieudef Test_VariadicityOp : Test_Op<"variadicity"> { 164a64975f9SFehr Mathieu let arguments = (ins Variadic<Test_SingletonAType>:$variadic, 165a64975f9SFehr Mathieu Optional<Test_SingletonBType>:$optional, 166a64975f9SFehr Mathieu Test_SingletonCType:$required); 167a64975f9SFehr Mathieu} 168a64975f9SFehr Mathieu// CHECK-LABEL: irdl.operation @variadicity { 16904575dceSAlex Rice// CHECK-NEXT: %[[v0:[^ ]*]] = irdl.base @test::@"!singleton_a" 17004575dceSAlex Rice// CHECK-NEXT: %[[v1:[^ ]*]] = irdl.base @test::@"!singleton_b" 17104575dceSAlex Rice// CHECK-NEXT: %[[v2:[^ ]*]] = irdl.base @test::@"!singleton_c" 172*69d3ba3dSThéo Degioanni// CHECK-NEXT: irdl.operands(variadic: variadic %[[v0]], optional: optional %[[v1]], required: %[[v2]]) 173a64975f9SFehr Mathieu// CHECK-NEXT: } 174