Skip to content

Commit ec5def5

Browse files
committed
Fix MLIR Python binding for arith.constant after argument has been changed to an interface
e179532 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
1 parent 6e1ba62 commit ec5def5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

mlir/python/mlir/dialects/_arith_ops_ext.py

+4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ def create_index(cls, value: int, *, loc=None, ip=None):
6060
def type(self):
6161
return self.results[0].type
6262

63+
@property
64+
def value(self):
65+
return Attribute(self.operation.attributes["value"])
66+
6367
@property
6468
def literal_value(self) -> Union[int, float]:
6569
if _is_integer_like_type(self.type):
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# RUN: %PYTHON %s | FileCheck %s
2+
3+
from mlir.ir import *
4+
import mlir.dialects.func as func
5+
import mlir.dialects.arith as arith
6+
7+
def run(f):
8+
print("\nTEST:", f.__name__)
9+
f()
10+
11+
# CHECK-LABEL: TEST: testConstantOp
12+
@run
13+
def testConstantOps():
14+
with Context() as ctx, Location.unknown():
15+
module = Module.create()
16+
with InsertionPoint(module.body):
17+
arith.ConstantOp(value=42.42, result=F32Type.get())
18+
# CHECK: %cst = arith.constant 4.242000e+01 : f32
19+
print(module)

0 commit comments

Comments
 (0)