@@ -108,10 +108,69 @@ def affine_for_op_test(buffer):
108
108
# CHECK: %[[TMP:.*]] = memref.load %[[BUFFER]][%[[INDVAR]]] : memref<1024xf32>
109
109
tmp = memref .LoadOp (buffer , [sum .induction_variable ])
110
110
sum_next = arith .AddFOp (sum .inner_iter_args [0 ], tmp )
111
-
112
111
affine .AffineYieldOp ([sum_next ])
113
112
114
- return
113
+
114
+ # CHECK-LABEL: TEST: testAffineForOpErrors
115
+ @constructAndPrintInModule
116
+ def testAffineForOpErrors ():
117
+ c1 = arith .ConstantOp (T .index (), 1 )
118
+ c2 = arith .ConstantOp (T .index (), 2 )
119
+ c3 = arith .ConstantOp (T .index (), 3 )
120
+ d0 = AffineDimExpr .get (0 )
121
+
122
+ try :
123
+ affine .AffineForOp (
124
+ c1 ,
125
+ c2 ,
126
+ 1 ,
127
+ lower_bound_operands = [c3 ],
128
+ upper_bound_operands = [],
129
+ )
130
+ except ValueError as e :
131
+ assert (
132
+ e .args [0 ]
133
+ == "Either a concrete lower bound or an AffineMap in combination with lower bound operands, but not both, is supported."
134
+ )
135
+
136
+ try :
137
+ affine .AffineForOp (
138
+ AffineMap .get_constant (1 ),
139
+ c2 ,
140
+ 1 ,
141
+ lower_bound_operands = [c3 , c3 ],
142
+ upper_bound_operands = [],
143
+ )
144
+ except ValueError as e :
145
+ assert (
146
+ e .args [0 ]
147
+ == "Wrong number of lower bound operands passed to AffineForOp; Expected 0, got 2."
148
+ )
149
+
150
+ try :
151
+ two_indices = affine .AffineDelinearizeIndexOp (
152
+ [T .index (), T .index ()], c1 , [c1 , c1 ]
153
+ )
154
+ affine .AffineForOp (
155
+ two_indices ,
156
+ c2 ,
157
+ 1 ,
158
+ lower_bound_operands = [],
159
+ upper_bound_operands = [],
160
+ )
161
+ except ValueError as e :
162
+ assert e .args [0 ] == "Only a single concrete value is supported for lower bound."
163
+
164
+ try :
165
+ affine .AffineForOp (
166
+ 1.0 ,
167
+ c2 ,
168
+ 1 ,
169
+ lower_bound_operands = [],
170
+ upper_bound_operands = [],
171
+ )
172
+ except ValueError as e :
173
+ assert e .args [0 ] == "lower bound must be int | ResultValueT | AffineMap."
115
174
116
175
117
176
@constructAndPrintInModule
@@ -182,51 +241,6 @@ def range_loop_4(lb, ub, memref_v):
182
241
memref .store (add , memref_v , [i ])
183
242
affine .yield_ ([])
184
243
185
- # CHECK-LABEL: func.func @range_loop_5(
186
- # CHECK-SAME: %[[VAL_0:.*]]: index, %[[VAL_1:.*]]: index, %[[VAL_2:.*]]: memref<10xindex>) {
187
- # CHECK: affine.for %[[VAL_3:.*]] = 0 to 10 {
188
- # CHECK: %[[VAL_4:.*]] = arith.addi %[[VAL_3]], %[[VAL_3]] : index
189
- # CHECK: memref.store %[[VAL_4]], %[[VAL_2]]{{\[}}%[[VAL_3]]] : memref<10xindex>
190
- # CHECK: }
191
- # CHECK: return
192
- # CHECK: }
193
- @func .FuncOp .from_py_func (T .index (), T .index (), memref_t )
194
- def range_loop_5 (lb , ub , memref_v ):
195
- for i in range (0 , 10 , step = 1 ):
196
- add = arith .addi (i , i )
197
- memref .store (add , memref_v , [i ])
198
- affine .yield_ ([])
199
-
200
- # CHECK-LABEL: func.func @range_loop_6(
201
- # CHECK-SAME: %[[VAL_0:.*]]: index, %[[VAL_1:.*]]: index, %[[VAL_2:.*]]: memref<10xindex>) {
202
- # CHECK: affine.for %[[VAL_3:.*]] = 0 to 10 {
203
- # CHECK: %[[VAL_4:.*]] = arith.addi %[[VAL_3]], %[[VAL_3]] : index
204
- # CHECK: memref.store %[[VAL_4]], %[[VAL_2]]{{\[}}%[[VAL_3]]] : memref<10xindex>
205
- # CHECK: }
206
- # CHECK: return
207
- # CHECK: }
208
- @func .FuncOp .from_py_func (T .index (), T .index (), memref_t )
209
- def range_loop_6 (lb , ub , memref_v ):
210
- for i in range (0 , 10 ):
211
- add = arith .addi (i , i )
212
- memref .store (add , memref_v , [i ])
213
- affine .yield_ ([])
214
-
215
- # CHECK-LABEL: func.func @range_loop_7(
216
- # CHECK-SAME: %[[VAL_0:.*]]: index, %[[VAL_1:.*]]: index, %[[VAL_2:.*]]: memref<10xindex>) {
217
- # CHECK: affine.for %[[VAL_3:.*]] = 0 to 10 {
218
- # CHECK: %[[VAL_4:.*]] = arith.addi %[[VAL_3]], %[[VAL_3]] : index
219
- # CHECK: memref.store %[[VAL_4]], %[[VAL_2]]{{\[}}%[[VAL_3]]] : memref<10xindex>
220
- # CHECK: }
221
- # CHECK: return
222
- # CHECK: }
223
- @func .FuncOp .from_py_func (T .index (), T .index (), memref_t )
224
- def range_loop_7 (lb , ub , memref_v ):
225
- for i in range (10 ):
226
- add = arith .addi (i , i )
227
- memref .store (add , memref_v , [i ])
228
- affine .yield_ ([])
229
-
230
244
# CHECK-LABEL: func.func @range_loop_8(
231
245
# CHECK-SAME: %[[VAL_0:.*]]: index, %[[VAL_1:.*]]: index, %[[VAL_2:.*]]: memref<10xindex>) {
232
246
# CHECK: %[[VAL_3:.*]] = affine.for %[[VAL_4:.*]] = 0 to 10 iter_args(%[[VAL_5:.*]] = %[[VAL_2]]) -> (memref<10xindex>) {
@@ -238,7 +252,7 @@ def range_loop_7(lb, ub, memref_v):
238
252
# CHECK: }
239
253
@func .FuncOp .from_py_func (T .index (), T .index (), memref_t )
240
254
def range_loop_8 (lb , ub , memref_v ):
241
- for i , it in range (10 , iter_args = [memref_v ]):
255
+ for i , it in range (0 , 10 , iter_args = [memref_v ]):
242
256
add = arith .addi (i , i )
243
257
memref .store (add , it , [i ])
244
258
affine .yield_ ([it ])
0 commit comments