Skip to content

Commit 829df04

Browse files
committed
Update affine.py
1 parent c333f86 commit 829df04

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

mlir/python/mlir/dialects/affine.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,28 @@ def __init__(
6161

6262
if isinstance(lower_bound, int):
6363
lower_bound = AffineMap.get_constant(lower_bound)
64-
elif isinstance(lower_bound, _ResultValueT):
64+
elif isinstance(lower_bound, (Operation, OpView, Value)):
65+
if len(lower_bound_operands):
66+
raise ValueError(
67+
f"Either a concrete lower bound or an AffineMap in combination "
68+
f"with lower bound operands, but not both, is supported."
69+
)
6570
lower_bound_operands.append(lower_bound)
66-
lower_bound = AffineMap.get_constant(1)
71+
lower_bound = AffineMap.get_identity(1)
6772

6873
if not isinstance(lower_bound, AffineMap):
6974
raise ValueError(f"{lower_bound=} must be int | ResultValueT | AffineMap")
7075

7176
if isinstance(upper_bound, int):
7277
upper_bound = AffineMap.get_constant(upper_bound)
73-
elif isinstance(upper_bound, _ResultValueT):
78+
elif isinstance(upper_bound, (Operation, OpView, Value)):
79+
if len(upper_bound_operands):
80+
raise ValueError(
81+
f"Either a concrete upper bound or an AffineMap in combination "
82+
f"with upper bound operands, but not both, is supported."
83+
)
7484
upper_bound_operands.append(upper_bound)
75-
upper_bound = AffineMap.get_constant(1)
85+
upper_bound = AffineMap.get_identity(1)
7686

7787
if not isinstance(upper_bound, AffineMap):
7888
raise ValueError(f"{upper_bound=} must be int | ResultValueT | AffineMap")

mlir/test/python/dialects/affine.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,13 @@ def testForSugar():
119119
memref_t = T.memref(10, T.index())
120120
range = affine.for_
121121

122+
# CHECK: #[[$ATTR_2:.+]] = affine_map<(d0) -> (d0)>
123+
122124
# CHECK-LABEL: func.func @range_loop_1(
123125
# CHECK-SAME: %[[VAL_0:.*]]: index, %[[VAL_1:.*]]: index, %[[VAL_2:.*]]: memref<10xindex>) {
124-
# CHECK: affine.for %[[VAL_3:.*]] = 1 to 1 iter_args() -> () {
126+
# CHECK: affine.for %[[VAL_3:.*]] = #[[$ATTR_2]](%[[VAL_0]]) to #[[$ATTR_2]](%[[VAL_1]]) {
125127
# CHECK: %[[VAL_4:.*]] = arith.addi %[[VAL_3]], %[[VAL_3]] : index
126128
# CHECK: memref.store %[[VAL_4]], %[[VAL_2]]{{\[}}%[[VAL_3]]] : memref<10xindex>
127-
# CHECK: affine.yield
128129
# CHECK: }
129130
# CHECK: return
130131
# CHECK: }
@@ -138,10 +139,9 @@ def range_loop_1(lb, ub, memref_v):
138139

139140
# CHECK-LABEL: func.func @range_loop_2(
140141
# CHECK-SAME: %[[VAL_0:.*]]: index, %[[VAL_1:.*]]: index, %[[VAL_2:.*]]: memref<10xindex>) {
141-
# CHECK: affine.for %[[VAL_3:.*]] = 1 to 10 iter_args() -> () {
142+
# CHECK: affine.for %[[VAL_3:.*]] = #[[$ATTR_2]](%[[VAL_0]]) to 10 {
142143
# CHECK: %[[VAL_4:.*]] = arith.addi %[[VAL_3]], %[[VAL_3]] : index
143144
# CHECK: memref.store %[[VAL_4]], %[[VAL_2]]{{\[}}%[[VAL_3]]] : memref<10xindex>
144-
# CHECK: affine.yield
145145
# CHECK: }
146146
# CHECK: return
147147
# CHECK: }
@@ -154,10 +154,9 @@ def range_loop_2(lb, ub, memref_v):
154154

155155
# CHECK-LABEL: func.func @range_loop_3(
156156
# CHECK-SAME: %[[VAL_0:.*]]: index, %[[VAL_1:.*]]: index, %[[VAL_2:.*]]: memref<10xindex>) {
157-
# CHECK: affine.for %[[VAL_3:.*]] = 0 to 1 iter_args() -> () {
157+
# CHECK: affine.for %[[VAL_3:.*]] = 0 to #[[$ATTR_2]](%[[VAL_1]]) {
158158
# CHECK: %[[VAL_4:.*]] = arith.addi %[[VAL_3]], %[[VAL_3]] : index
159159
# CHECK: memref.store %[[VAL_4]], %[[VAL_2]]{{\[}}%[[VAL_3]]] : memref<10xindex>
160-
# CHECK: affine.yield
161160
# CHECK: }
162161
# CHECK: return
163162
# CHECK: }

0 commit comments

Comments
 (0)