@@ -117,7 +117,8 @@ def AffineApplyOp : Affine_Op<"apply", [Pure]> {
117
117
}
118
118
119
119
def AffineForOp : Affine_Op<"for",
120
- [AutomaticAllocationScope, ImplicitAffineTerminator, ConditionallySpeculatable,
120
+ [AttrSizedOperandSegments, AutomaticAllocationScope,
121
+ ImplicitAffineTerminator, ConditionallySpeculatable,
121
122
RecursiveMemoryEffects, DeclareOpInterfaceMethods<LoopLikeOpInterface,
122
123
["getSingleInductionVar", "getSingleLowerBound", "getSingleStep",
123
124
"getSingleUpperBound", "replaceWithAdditionalYields"]>,
@@ -147,7 +148,7 @@ def AffineForOp : Affine_Op<"for",
147
148
from a lower bound to an upper bound by a stride. The stride, represented by
148
149
`step`, is a positive constant integer which defaults to "1" if not present.
149
150
The lower and upper bounds specify a half-open range: the range includes the
150
- lower bound but does not include the upper bound.
151
+ lower bound but does not include the upper bound.
151
152
152
153
The lower and upper bounds of a `affine.for` operation are represented as an
153
154
application of an affine mapping to a list of SSA values passed to the map.
@@ -229,7 +230,12 @@ def AffineForOp : Affine_Op<"for",
229
230
explicitly present. The number and types of the "affine.for" results must
230
231
match the initial values in the `iter_args` binding and the yield operands.
231
232
}];
232
- let arguments = (ins Variadic<AnyType>);
233
+ let arguments = (ins Variadic<Index>:$lowerBoundOperands,
234
+ Variadic<Index>:$upperBoundOperands,
235
+ Variadic<AnyType>:$inits,
236
+ AffineMapAttr:$lowerBoundMap,
237
+ AffineMapAttr:$upperBoundMap,
238
+ IndexAttr:$step);
233
239
let results = (outs Variadic<AnyType>:$results);
234
240
let regions = (region SizedRegion<1>:$region);
235
241
@@ -251,26 +257,10 @@ def AffineForOp : Affine_Op<"for",
251
257
using BodyBuilderFn =
252
258
function_ref<void(OpBuilder &, Location, Value, ValueRange)>;
253
259
254
- static StringRef getStepAttrStrName() { return "step"; }
255
- static StringRef getLowerBoundAttrStrName() { return "lower_bound"; }
256
- static StringRef getUpperBoundAttrStrName() { return "upper_bound"; }
257
-
258
260
BlockArgument getInductionVar() { return getBody()->getArgument(0); }
259
261
Block::BlockArgListType getRegionIterArgs() {
260
262
return getBody()->getArguments().drop_front();
261
263
}
262
- Operation::operand_range getInits() {
263
- return getOperands().drop_front(getNumControlOperands());
264
- }
265
-
266
- // TODO: provide iterators for the lower and upper bound operands
267
- // if the current access via getLowerBound(), getUpperBound() is too slow.
268
-
269
- /// Returns operands for the lower bound map.
270
- operand_range getLowerBoundOperands();
271
-
272
- /// Returns operands for the upper bound map.
273
- operand_range getUpperBoundOperands();
274
264
275
265
/// Returns operands for the lower and upper bound maps with the operands
276
266
/// for the lower bound map in front of those for the upper bound map.
@@ -283,20 +273,7 @@ def AffineForOp : Affine_Op<"for",
283
273
AffineBound getUpperBound();
284
274
285
275
/// Returns loop step.
286
- int64_t getStep() {
287
- return ::llvm::cast<IntegerAttr>(*(*this)->getInherentAttr(getStepAttrStrName())).getInt();
288
- }
289
-
290
- /// Returns affine map for the lower bound.
291
- AffineMap getLowerBoundMap() { return getLowerBoundMapAttr().getValue(); }
292
- AffineMapAttr getLowerBoundMapAttr() {
293
- return ::llvm::cast<AffineMapAttr>(*(*this)->getInherentAttr(getLowerBoundAttrStrName()));
294
- }
295
- /// Returns affine map for the upper bound. The upper bound is exclusive.
296
- AffineMap getUpperBoundMap() { return getUpperBoundMapAttr().getValue(); }
297
- AffineMapAttr getUpperBoundMapAttr() {
298
- return ::llvm::cast<AffineMapAttr>(*(*this)->getInherentAttr(getUpperBoundAttrStrName()));
299
- }
276
+ int64_t getStepAsInt() { return getStep().getSExtValue(); }
300
277
301
278
/// Set lower bound. The new bound must have the same number of operands as
302
279
/// the current bound map. Otherwise, 'replaceForLowerBound' should be used.
@@ -305,18 +282,10 @@ def AffineForOp : Affine_Op<"for",
305
282
/// current bound map. Otherwise, 'replaceForUpperBound' should be used.
306
283
void setUpperBound(ValueRange operands, AffineMap map);
307
284
308
- /// Set the lower bound map without changing operands.
309
- void setLowerBoundMap(AffineMap map);
310
-
311
- /// Set the upper bound map without changing operands.
312
- void setUpperBoundMap(AffineMap map);
313
-
314
285
/// Set loop step.
315
286
void setStep(int64_t step) {
316
287
assert(step > 0 && "step has to be a positive integer constant");
317
- auto *context = getLowerBoundMap().getContext();
318
- (*this)->setAttr(StringAttr::get(context, getStepAttrStrName()),
319
- IntegerAttr::get(IndexType::get(context), step));
288
+ setStep(APInt(/*numBits=*/64, step, /*isSigned=*/true));
320
289
}
321
290
322
291
/// Returns number of region arguments for loop-carried values.
@@ -325,7 +294,9 @@ def AffineForOp : Affine_Op<"for",
325
294
}
326
295
327
296
/// Number of operands controlling the loop: lb and ub.
328
- unsigned getNumControlOperands() { return getOperation()->getNumOperands() - getNumIterOperands(); }
297
+ unsigned getNumControlOperands() {
298
+ return getOperation()->getNumOperands() - getNumIterOperands();
299
+ }
329
300
330
301
/// Get the number of loop-carried values.
331
302
unsigned getNumIterOperands();
0 commit comments