47 lines · python
1# RUN: %PYTHON %s | FileCheck %s2# This is just a smoke test that the dialect is functional.3 4from mlir.ir import *5from mlir.dialects import ml_program, arith, builtin6 7 8def constructAndPrintInModule(f):9 print("\nTEST:", f.__name__)10 with Context(), Location.unknown():11 module = Module.create()12 with InsertionPoint(module.body):13 f()14 print(module)15 return f16 17 18# CHECK-LABEL: testFuncOp19@constructAndPrintInModule20def testFuncOp():21 # CHECK: ml_program.func @foobar(%arg0: si32) -> si3222 f = ml_program.FuncOp(23 name="foobar", type=([IntegerType.get_signed(32)], [IntegerType.get_signed(32)])24 )25 block = f.add_entry_block()26 with InsertionPoint(block):27 # CHECK: ml_program.return28 ml_program.ReturnOp([block.arguments[0]])29 30 31# CHECK-LABEL: testGlobalStoreOp32@constructAndPrintInModule33def testGlobalStoreOp():34 # CHECK: %cst = arith.constant 4.242000e+01 : f3235 cst = arith.ConstantOp(value=42.42, result=F32Type.get())36 37 m = builtin.ModuleOp()38 m.sym_name = StringAttr.get("symbol1")39 m.sym_visibility = StringAttr.get("public")40 # CHECK: module @symbol1 attributes {sym_visibility = "public"} {41 # CHECK: ml_program.global public mutable @symbol2 : f3242 # CHECK: }43 with InsertionPoint(m.body):44 ml_program.GlobalOp("symbol2", F32Type.get(), is_mutable=True)45 # CHECK: ml_program.global_store @symbol1::@symbol2 = %cst : f3246 ml_program.GlobalStoreOp(["symbol1", "symbol2"], cst)47