19f3f6d7bSStella Laurenzo# RUN: %PYTHON %s | FileCheck %s 29f3f6d7bSStella Laurenzo 39f3f6d7bSStella Laurenzoimport gc 49f3f6d7bSStella Laurenzofrom mlir.ir import * 59f3f6d7bSStella Laurenzo 69f3f6d7bSStella Laurenzo 79f3f6d7bSStella Laurenzodef run(f): 89f3f6d7bSStella Laurenzo print("\nTEST:", f.__name__) 99f3f6d7bSStella Laurenzo f() 109f3f6d7bSStella Laurenzo gc.collect() 119f3f6d7bSStella Laurenzo assert Context._get_live_count() == 0 1278f2dae0SAlex Zinenko return f 139f3f6d7bSStella Laurenzo 149f3f6d7bSStella Laurenzo 159f3f6d7bSStella Laurenzo# CHECK-LABEL: TEST: testCapsuleConversions 1678f2dae0SAlex Zinenko@run 179f3f6d7bSStella Laurenzodef testCapsuleConversions(): 189f3f6d7bSStella Laurenzo ctx = Context() 199f3f6d7bSStella Laurenzo ctx.allow_unregistered_dialects = True 209f3f6d7bSStella Laurenzo with Location.unknown(ctx): 219f3f6d7bSStella Laurenzo i32 = IntegerType.get_signless(32) 229f3f6d7bSStella Laurenzo value = Operation.create("custom.op1", results=[i32]).result 239f3f6d7bSStella Laurenzo value_capsule = value._CAPIPtr 249f3f6d7bSStella Laurenzo assert '"mlir.ir.Value._CAPIPtr"' in repr(value_capsule) 259f3f6d7bSStella Laurenzo value2 = Value._CAPICreate(value_capsule) 269f3f6d7bSStella Laurenzo assert value2 == value 279f3f6d7bSStella Laurenzo 289f3f6d7bSStella Laurenzo 299f3f6d7bSStella Laurenzo# CHECK-LABEL: TEST: testOpResultOwner 3078f2dae0SAlex Zinenko@run 319f3f6d7bSStella Laurenzodef testOpResultOwner(): 329f3f6d7bSStella Laurenzo ctx = Context() 339f3f6d7bSStella Laurenzo ctx.allow_unregistered_dialects = True 349f3f6d7bSStella Laurenzo with Location.unknown(ctx): 359f3f6d7bSStella Laurenzo i32 = IntegerType.get_signless(32) 369f3f6d7bSStella Laurenzo op = Operation.create("custom.op1", results=[i32]) 379f3f6d7bSStella Laurenzo assert op.result.owner == op 389f3f6d7bSStella Laurenzo 399f3f6d7bSStella Laurenzo 4078f2dae0SAlex Zinenko# CHECK-LABEL: TEST: testValueIsInstance 4178f2dae0SAlex Zinenko@run 4278f2dae0SAlex Zinenkodef testValueIsInstance(): 4378f2dae0SAlex Zinenko ctx = Context() 4478f2dae0SAlex Zinenko ctx.allow_unregistered_dialects = True 4578f2dae0SAlex Zinenko module = Module.parse( 4678f2dae0SAlex Zinenko r""" 47*2310ced8SRiver Riddle func.func @foo(%arg0: f32) { 4878f2dae0SAlex Zinenko %0 = "some_dialect.some_op"() : () -> f64 4978f2dae0SAlex Zinenko return 5078f2dae0SAlex Zinenko }""", ctx) 5178f2dae0SAlex Zinenko func = module.body.operations[0] 5278f2dae0SAlex Zinenko assert BlockArgument.isinstance(func.regions[0].blocks[0].arguments[0]) 5378f2dae0SAlex Zinenko assert not OpResult.isinstance(func.regions[0].blocks[0].arguments[0]) 5478f2dae0SAlex Zinenko 5578f2dae0SAlex Zinenko op = func.regions[0].blocks[0].operations[0] 5678f2dae0SAlex Zinenko assert not BlockArgument.isinstance(op.results[0]) 5778f2dae0SAlex Zinenko assert OpResult.isinstance(op.results[0]) 58f78fe0b7Srkayaith 59f78fe0b7Srkayaith 60f78fe0b7Srkayaith# CHECK-LABEL: TEST: testValueHash 61f78fe0b7Srkayaith@run 62f78fe0b7Srkayaithdef testValueHash(): 63f78fe0b7Srkayaith ctx = Context() 64f78fe0b7Srkayaith ctx.allow_unregistered_dialects = True 65f78fe0b7Srkayaith module = Module.parse( 66f78fe0b7Srkayaith r""" 67*2310ced8SRiver Riddle func.func @foo(%arg0: f32) -> f32 { 68f78fe0b7Srkayaith %0 = "some_dialect.some_op"(%arg0) : (f32) -> f32 69f78fe0b7Srkayaith return %0 : f32 70f78fe0b7Srkayaith }""", ctx) 71f78fe0b7Srkayaith 72f78fe0b7Srkayaith [func] = module.body.operations 73f78fe0b7Srkayaith block = func.entry_block 74f78fe0b7Srkayaith op, ret = block.operations 75f78fe0b7Srkayaith assert hash(block.arguments[0]) == hash(op.operands[0]) 76f78fe0b7Srkayaith assert hash(op.result) == hash(ret.operands[0]) 77