diff --git a/mlir/python/mlir/dialects/_arith_ops_ext.py b/mlir/python/mlir/dialects/_arith_ops_ext.py --- a/mlir/python/mlir/dialects/_arith_ops_ext.py +++ b/mlir/python/mlir/dialects/_arith_ops_ext.py @@ -60,6 +60,10 @@ def type(self): return self.results[0].type + @property + def value(self): + return Attribute(self.operation.attributes["value"]) + @property def literal_value(self) -> Union[int, float]: if _is_integer_like_type(self.type): diff --git a/mlir/test/python/dialects/arith_dialect.py b/mlir/test/python/dialects/arith_dialect.py new file mode 100644 --- /dev/null +++ b/mlir/test/python/dialects/arith_dialect.py @@ -0,0 +1,19 @@ +# RUN: %PYTHON %s | FileCheck %s + +from mlir.ir import * +import mlir.dialects.func as func +import mlir.dialects.arith as arith + +def run(f): + print("\nTEST:", f.__name__) + f() + +# CHECK-LABEL: TEST: testConstantOp +@run +def testConstantOps(): + with Context() as ctx, Location.unknown(): + module = Module.create() + with InsertionPoint(module.body): + arith.ConstantOp(value=42.42, result=F32Type.get()) + # CHECK: %cst = arith.constant 4.242000e+01 : f32 + print(module)