236 lines · python
1# RUN: %PYTHON %s | FileCheck %s2 3from mlir.ir import *4from mlir.dialects import index, arith5 6 7def run(f):8 print("\nTEST:", f.__name__)9 with Context() as ctx, Location.unknown():10 module = Module.create()11 with InsertionPoint(module.body):12 f(ctx)13 print(module)14 15 16# CHECK-LABEL: TEST: testConstantOp17@run18def testConstantOp(ctx):19 a = index.ConstantOp(value=42)20 # CHECK: %{{.*}} = index.constant 4221 22 23# CHECK-LABEL: TEST: testBoolConstantOp24@run25def testBoolConstantOp(ctx):26 a = index.BoolConstantOp(value=True)27 # CHECK: %{{.*}} = index.bool.constant true28 29 30# CHECK-LABEL: TEST: testAndOp31@run32def testAndOp(ctx):33 a = index.ConstantOp(value=42)34 r = index.AndOp(a, a)35 # CHECK: %{{.*}} = index.and %{{.*}}, %{{.*}}36 37 38# CHECK-LABEL: TEST: testOrOp39@run40def testOrOp(ctx):41 a = index.ConstantOp(value=42)42 r = index.OrOp(a, a)43 # CHECK: %{{.*}} = index.or %{{.*}}, %{{.*}}44 45 46# CHECK-LABEL: TEST: testXOrOp47@run48def testXOrOp(ctx):49 a = index.ConstantOp(value=42)50 r = index.XOrOp(a, a)51 # CHECK: %{{.*}} = index.xor %{{.*}}, %{{.*}}52 53 54# CHECK-LABEL: TEST: testCastSOp55@run56def testCastSOp(ctx):57 a = index.ConstantOp(value=42)58 b = arith.ConstantOp(value=23, result=IntegerType.get_signless(64))59 c = index.CastSOp(input=a, output=IntegerType.get_signless(32))60 d = index.CastSOp(input=b, output=IndexType.get())61 # CHECK: %{{.*}} = index.casts %{{.*}} : index to i3262 # CHECK: %{{.*}} = index.casts %{{.*}} : i64 to index63 64 65# CHECK-LABEL: TEST: testCastUOp66@run67def testCastUOp(ctx):68 a = index.ConstantOp(value=42)69 b = arith.ConstantOp(value=23, result=IntegerType.get_signless(64))70 c = index.CastUOp(input=a, output=IntegerType.get_signless(32))71 d = index.CastUOp(input=b, output=IndexType.get())72 # CHECK: %{{.*}} = index.castu %{{.*}} : index to i3273 # CHECK: %{{.*}} = index.castu %{{.*}} : i64 to index74 75 76# CHECK-LABEL: TEST: testCeilDivSOp77@run78def testCeilDivSOp(ctx):79 a = index.ConstantOp(value=42)80 r = index.CeilDivSOp(a, a)81 # CHECK: %{{.*}} = index.ceildivs %{{.*}}, %{{.*}}82 83 84# CHECK-LABEL: TEST: testCeilDivUOp85@run86def testCeilDivUOp(ctx):87 a = index.ConstantOp(value=42)88 r = index.CeilDivUOp(a, a)89 # CHECK: %{{.*}} = index.ceildivu %{{.*}}, %{{.*}}90 91 92# CHECK-LABEL: TEST: testCmpOp93@run94def testCmpOp(ctx):95 a = index.ConstantOp(value=42)96 b = index.ConstantOp(value=23)97 pred = AttrBuilder.get("IndexCmpPredicateAttr")("slt", context=ctx)98 r = index.CmpOp(pred, lhs=a, rhs=b)99 # CHECK: %{{.*}} = index.cmp slt(%{{.*}}, %{{.*}})100 101 102# CHECK-LABEL: TEST: testAddOp103@run104def testAddOp(ctx):105 a = index.ConstantOp(value=42)106 r = index.AddOp(a, a)107 # CHECK: %{{.*}} = index.add %{{.*}}, %{{.*}}108 109 110# CHECK-LABEL: TEST: testSubOp111@run112def testSubOp(ctx):113 a = index.ConstantOp(value=42)114 r = index.SubOp(a, a)115 # CHECK: %{{.*}} = index.sub %{{.*}}, %{{.*}}116 117 118# CHECK-LABEL: TEST: testMulOp119@run120def testMulOp(ctx):121 a = index.ConstantOp(value=42)122 r = index.MulOp(a, a)123 # CHECK: %{{.*}} = index.mul %{{.*}}, %{{.*}}124 125 126# CHECK-LABEL: TEST: testDivSOp127@run128def testDivSOp(ctx):129 a = index.ConstantOp(value=42)130 r = index.DivSOp(a, a)131 # CHECK: %{{.*}} = index.divs %{{.*}}, %{{.*}}132 133 134# CHECK-LABEL: TEST: testDivUOp135@run136def testDivUOp(ctx):137 a = index.ConstantOp(value=42)138 r = index.DivUOp(a, a)139 # CHECK: %{{.*}} = index.divu %{{.*}}, %{{.*}}140 141 142# CHECK-LABEL: TEST: testFloorDivSOp143@run144def testFloorDivSOp(ctx):145 a = index.ConstantOp(value=42)146 r = index.FloorDivSOp(a, a)147 # CHECK: %{{.*}} = index.floordivs %{{.*}}, %{{.*}}148 149 150# CHECK-LABEL: TEST: testMaxSOp151@run152def testMaxSOp(ctx):153 a = index.ConstantOp(value=42)154 b = index.ConstantOp(value=23)155 r = index.MaxSOp(a, b)156 # CHECK: %{{.*}} = index.maxs %{{.*}}, %{{.*}}157 158 159# CHECK-LABEL: TEST: testMaxUOp160@run161def testMaxUOp(ctx):162 a = index.ConstantOp(value=42)163 b = index.ConstantOp(value=23)164 r = index.MaxUOp(a, b)165 # CHECK: %{{.*}} = index.maxu %{{.*}}, %{{.*}}166 167 168# CHECK-LABEL: TEST: testMinSOp169@run170def testMinSOp(ctx):171 a = index.ConstantOp(value=42)172 b = index.ConstantOp(value=23)173 r = index.MinSOp(a, b)174 # CHECK: %{{.*}} = index.mins %{{.*}}, %{{.*}}175 176 177# CHECK-LABEL: TEST: testMinUOp178@run179def testMinUOp(ctx):180 a = index.ConstantOp(value=42)181 b = index.ConstantOp(value=23)182 r = index.MinUOp(a, b)183 # CHECK: %{{.*}} = index.minu %{{.*}}, %{{.*}}184 185 186# CHECK-LABEL: TEST: testRemSOp187@run188def testRemSOp(ctx):189 a = index.ConstantOp(value=42)190 b = index.ConstantOp(value=23)191 r = index.RemSOp(a, b)192 # CHECK: %{{.*}} = index.rems %{{.*}}, %{{.*}}193 194 195# CHECK-LABEL: TEST: testRemUOp196@run197def testRemUOp(ctx):198 a = index.ConstantOp(value=42)199 b = index.ConstantOp(value=23)200 r = index.RemUOp(a, b)201 # CHECK: %{{.*}} = index.remu %{{.*}}, %{{.*}}202 203 204# CHECK-LABEL: TEST: testShlOp205@run206def testShlOp(ctx):207 a = index.ConstantOp(value=42)208 b = index.ConstantOp(value=3)209 r = index.ShlOp(a, b)210 # CHECK: %{{.*}} = index.shl %{{.*}}, %{{.*}}211 212 213# CHECK-LABEL: TEST: testShrSOp214@run215def testShrSOp(ctx):216 a = index.ConstantOp(value=42)217 b = index.ConstantOp(value=3)218 r = index.ShrSOp(a, b)219 # CHECK: %{{.*}} = index.shrs %{{.*}}, %{{.*}}220 221 222# CHECK-LABEL: TEST: testShrUOp223@run224def testShrUOp(ctx):225 a = index.ConstantOp(value=42)226 b = index.ConstantOp(value=3)227 r = index.ShrUOp(a, b)228 # CHECK: %{{.*}} = index.shru %{{.*}}, %{{.*}}229 230 231# CHECK-LABEL: TEST: testSizeOfOp232@run233def testSizeOfOp(ctx):234 r = index.SizeOfOp()235 # CHECK: %{{.*}} = index.sizeof236