Skip to content

Commit 96fc548

Browse files
authored
Revert "[mlir][py] better support for arith.constant construction" (llvm#84103)
Reverts llvm#83259 This broke an integration test on Windows
1 parent 85388a0 commit 96fc548

File tree

2 files changed

+2
-59
lines changed

2 files changed

+2
-59
lines changed

mlir/python/mlir/dialects/arith.py

+2-21
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from ._arith_ops_gen import *
66
from ._arith_ops_gen import _Dialect
77
from ._arith_enum_gen import *
8-
from array import array as _array
9-
from typing import overload
108

119
try:
1210
from ..ir import *
@@ -45,30 +43,13 @@ def _is_float_type(type: Type):
4543
class ConstantOp(ConstantOp):
4644
"""Specialization for the constant op class."""
4745

48-
@overload
49-
def __init__(self, value: Attribute, *, loc=None, ip=None):
50-
...
51-
52-
@overload
5346
def __init__(
54-
self, result: Type, value: Union[int, float, _array], *, loc=None, ip=None
47+
self, result: Type, value: Union[int, float, Attribute], *, loc=None, ip=None
5548
):
56-
...
57-
58-
def __init__(self, result, value, *, loc=None, ip=None):
59-
if value is None:
60-
assert isinstance(result, Attribute)
61-
super().__init__(result, loc=loc, ip=ip)
62-
return
63-
6449
if isinstance(value, int):
6550
super().__init__(IntegerAttr.get(result, value), loc=loc, ip=ip)
6651
elif isinstance(value, float):
6752
super().__init__(FloatAttr.get(result, value), loc=loc, ip=ip)
68-
elif isinstance(value, _array) and value.typecode in ["i", "l"]:
69-
super().__init__(DenseIntElementsAttr.get(value, type=result))
70-
elif isinstance(value, _array) and value.typecode in ["f", "d"]:
71-
super().__init__(DenseFPElementsAttr.get(value, type=result))
7253
else:
7354
super().__init__(value, loc=loc, ip=ip)
7455

@@ -98,6 +79,6 @@ def literal_value(self) -> Union[int, float]:
9879

9980

10081
def constant(
101-
result: Type, value: Union[int, float, Attribute, _array], *, loc=None, ip=None
82+
result: Type, value: Union[int, float, Attribute], *, loc=None, ip=None
10283
) -> Value:
10384
return _get_op_result_or_op_results(ConstantOp(result, value, loc=loc, ip=ip))

mlir/test/python/dialects/arith_dialect.py

-38
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from mlir.ir import *
55
import mlir.dialects.arith as arith
66
import mlir.dialects.func as func
7-
from array import array
87

98

109
def run(f):
@@ -93,40 +92,3 @@ def __str__(self):
9392
b = a * a
9493
# CHECK: ArithValue(%2 = arith.mulf %cst_1, %cst_1 : f64)
9594
print(b)
96-
97-
98-
# CHECK-LABEL: TEST: testArrayConstantConstruction
99-
@run
100-
def testArrayConstantConstruction():
101-
with Context(), Location.unknown():
102-
module = Module.create()
103-
with InsertionPoint(module.body):
104-
i32_array = array("i", [1, 2, 3, 4])
105-
i32 = IntegerType.get_signless(32)
106-
vec_i32 = VectorType.get([2, 2], i32)
107-
arith.constant(vec_i32, i32_array)
108-
arith.ConstantOp(vec_i32, DenseIntElementsAttr.get(i32_array, type=vec_i32))
109-
110-
i64_array = array("l", [5, 6, 7, 8])
111-
i64 = IntegerType.get_signless(64)
112-
vec_i64 = VectorType.get([1, 4], i64)
113-
arith.constant(vec_i64, i64_array)
114-
arith.ConstantOp(vec_i64, DenseIntElementsAttr.get(i64_array, type=vec_i64))
115-
116-
f32_array = array("f", [1.0, 2.0, 3.0, 4.0])
117-
f32 = F32Type.get()
118-
vec_f32 = VectorType.get([4, 1], f32)
119-
arith.constant(vec_f32, f32_array)
120-
arith.ConstantOp(vec_f32, DenseFPElementsAttr.get(f32_array, type=vec_f32))
121-
122-
f64_array = array("d", [1.0, 2.0, 3.0, 4.0])
123-
f64 = F64Type.get()
124-
vec_f64 = VectorType.get([2, 1, 2], f64)
125-
arith.constant(vec_f64, f64_array)
126-
arith.ConstantOp(vec_f64, DenseFPElementsAttr.get(f64_array, type=vec_f64))
127-
128-
# CHECK-COUNT-2: arith.constant dense<[{{\[}}1, 2], [3, 4]]> : vector<2x2xi32>
129-
# CHECK-COUNT-2: arith.constant dense<[{{\[}}5, 6, 7, 8]]> : vector<1x4xi64>
130-
# CHECK-COUNT-2: arith.constant dense<[{{\[}}1.000000e+00], [2.000000e+00], [3.000000e+00], [4.000000e+00]]> : vector<4x1xf32>
131-
# CHECK-COUNT-2: arith.constant dense<[{{\[}}[1.000000e+00, 2.000000e+00]], [{{\[}}3.000000e+00, 4.000000e+00]]]> : vector<2x1x2xf64>
132-
print(module)

0 commit comments

Comments
 (0)