from mlir.ir import *
from mlir.dialects import index, arith
def run(f):
print("\nTEST:", f.__name__)
with Context() as ctx, Location.unknown():
module = Module.create()
with InsertionPoint(module.body):
f(ctx)
print(module)
@run
def testConstantOp(ctx):
a = index.ConstantOp(value=42)
@run
def testBoolConstantOp(ctx):
a = index.BoolConstantOp(value=True)
@run
def testAndOp(ctx):
a = index.ConstantOp(value=42)
r = index.AndOp(a, a)
@run
def testOrOp(ctx):
a = index.ConstantOp(value=42)
r = index.OrOp(a, a)
@run
def testXOrOp(ctx):
a = index.ConstantOp(value=42)
r = index.XOrOp(a, a)
@run
def testCastSOp(ctx):
a = index.ConstantOp(value=42)
b = arith.ConstantOp(value=23, result=IntegerType.get_signless(64))
c = index.CastSOp(input=a, output=IntegerType.get_signless(32))
d = index.CastSOp(input=b, output=IndexType.get())
@run
def testCastUOp(ctx):
a = index.ConstantOp(value=42)
b = arith.ConstantOp(value=23, result=IntegerType.get_signless(64))
c = index.CastUOp(input=a, output=IntegerType.get_signless(32))
d = index.CastUOp(input=b, output=IndexType.get())
@run
def testCeilDivSOp(ctx):
a = index.ConstantOp(value=42)
r = index.CeilDivSOp(a, a)
@run
def testCeilDivUOp(ctx):
a = index.ConstantOp(value=42)
r = index.CeilDivUOp(a, a)
@run
def testCmpOp(ctx):
a = index.ConstantOp(value=42)
b = index.ConstantOp(value=23)
pred = AttrBuilder.get("IndexCmpPredicateAttr")("slt", context=ctx)
r = index.CmpOp(pred, lhs=a, rhs=b)
@run
def testAddOp(ctx):
a = index.ConstantOp(value=42)
r = index.AddOp(a, a)
@run
def testSubOp(ctx):
a = index.ConstantOp(value=42)
r = index.SubOp(a, a)
@run
def testMulOp(ctx):
a = index.ConstantOp(value=42)
r = index.MulOp(a, a)
@run
def testDivSOp(ctx):
a = index.ConstantOp(value=42)
r = index.DivSOp(a, a)
@run
def testDivUOp(ctx):
a = index.ConstantOp(value=42)
r = index.DivUOp(a, a)
@run
def testFloorDivSOp(ctx):
a = index.ConstantOp(value=42)
r = index.FloorDivSOp(a, a)
@run
def testMaxSOp(ctx):
a = index.ConstantOp(value=42)
b = index.ConstantOp(value=23)
r = index.MaxSOp(a, b)
@run
def testMaxUOp(ctx):
a = index.ConstantOp(value=42)
b = index.ConstantOp(value=23)
r = index.MaxUOp(a, b)
@run
def testMinSOp(ctx):
a = index.ConstantOp(value=42)
b = index.ConstantOp(value=23)
r = index.MinSOp(a, b)
@run
def testMinUOp(ctx):
a = index.ConstantOp(value=42)
b = index.ConstantOp(value=23)
r = index.MinUOp(a, b)
@run
def testRemSOp(ctx):
a = index.ConstantOp(value=42)
b = index.ConstantOp(value=23)
r = index.RemSOp(a, b)
@run
def testRemUOp(ctx):
a = index.ConstantOp(value=42)
b = index.ConstantOp(value=23)
r = index.RemUOp(a, b)
@run
def testShlOp(ctx):
a = index.ConstantOp(value=42)
b = index.ConstantOp(value=3)
r = index.ShlOp(a, b)
@run
def testShrSOp(ctx):
a = index.ConstantOp(value=42)
b = index.ConstantOp(value=3)
r = index.ShrSOp(a, b)
@run
def testShrUOp(ctx):
a = index.ConstantOp(value=42)
b = index.ConstantOp(value=3)
r = index.ShrUOp(a, b)
@run
def testSizeOfOp(ctx):
r = index.SizeOfOp()