[Mlir-commits] [mlir] ec5def5 - Fix MLIR Python binding for arith.constant after argument has been changed to an interface
Mehdi Amini
llvmlistbot at llvm.org
Mon Aug 1 02:07:25 PDT 2022
Author: Mehdi Amini
Date: 2022-08-01T09:06:55Z
New Revision: ec5def5e20f6ae9fe8cc30e5ee152d4b239e1e95
URL: https://github.com/llvm/llvm-project/commit/ec5def5e20f6ae9fe8cc30e5ee152d4b239e1e95
DIFF: https://github.com/llvm/llvm-project/commit/ec5def5e20f6ae9fe8cc30e5ee152d4b239e1e95.diff
LOG: Fix MLIR Python binding for arith.constant after argument has been changed to an interface
e1795322844c removed the Type field from attributes and
arith::ConstantOp argument is now a TypedAttrInterface which isn't
supported by the python generator.
This patch temporarily restore the functionality for arith.constant but
won't generalize: we need to work on the generator instead.
Differential Revision: https://reviews.llvm.org/D130878
Added:
mlir/test/python/dialects/arith_dialect.py
Modified:
mlir/python/mlir/dialects/_arith_ops_ext.py
Removed:
################################################################################
diff --git a/mlir/python/mlir/dialects/_arith_ops_ext.py b/mlir/python/mlir/dialects/_arith_ops_ext.py
index c755df255c1e7..240859352ce21 100644
--- a/mlir/python/mlir/dialects/_arith_ops_ext.py
+++ b/mlir/python/mlir/dialects/_arith_ops_ext.py
@@ -60,6 +60,10 @@ def create_index(cls, value: int, *, loc=None, ip=None):
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
index 0000000000000..acae9b6474083
--- /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
+ at 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)
More information about the Mlir-commits
mailing list