brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · ed62db9 Raw
67 lines · python
1# RUN: %PYTHON %s 2>&1 | FileCheck %s2 3from mlir.ir import *4from mlir.dialects.irdl import *5import sys6 7 8def run(f):9    print("\nTEST:", f.__name__, file=sys.stderr)10    f()11 12 13# CHECK: TEST: testIRDL14@run15def testIRDL():16    with Context() as ctx, Location.unknown():17        module = Module.create()18        with InsertionPoint(module.body):19            irdl_test = dialect("irdl_test")20            with InsertionPoint(irdl_test.body):21                op = operation_("test_op")22                with InsertionPoint(op.body):23                    f32 = is_(TypeAttr.get(F32Type.get()))24                    operands_([f32], ["input"], [Variadicity.single])25                type1 = type_("type1")26                with InsertionPoint(type1.body):27                    f32 = is_(TypeAttr.get(F32Type.get()))28                    parameters([f32], ["val"])29                attr1 = attribute("attr1")30                with InsertionPoint(attr1.body):31                    test = is_(StringAttr.get("test"))32                    parameters([test], ["val"])33 34        # CHECK: module {35        # CHECK:   irdl.dialect @irdl_test {36        # CHECK:     irdl.operation @test_op {37        # CHECK:       %0 = irdl.is f3238        # CHECK:       irdl.operands(input: %0)39        # CHECK:     }40        # CHECK:     irdl.type @type1 {41        # CHECK:       %0 = irdl.is f3242        # CHECK:       irdl.parameters(val: %0)43        # CHECK:     }44        # CHECK:     irdl.attribute @attr1 {45        # CHECK:       %0 = irdl.is "test"46        # CHECK:       irdl.parameters(val: %0)47        # CHECK:     }48        # CHECK:   }49        # CHECK: }50        module.operation.verify()51        module.dump()52 53        load_dialects(module)54 55        m = Module.parse(56            """57          module {58            %a = arith.constant 1.0 : f3259            "irdl_test.test_op"(%a) : (f32) -> ()60          }61        """62        )63        # CHECK: module {64        # CHECK:   "irdl_test.test_op"(%cst) : (f32) -> ()65        # CHECK: }66        m.dump()67