Skip to content

Commit 8ed47b7

Browse files
committed
[mlir] NFC: use ValueRange in AffineToStandard conversion
ValueRange is a more flexible way of passing around ranges of Values that avoids Value vector materialization in affine expression expansion.
1 parent 4a331be commit 8ed47b7

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

mlir/include/mlir/Conversion/AffineToStandard/AffineToStandard.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ class MLIRContext;
2020
class OpBuilder;
2121
class RewritePattern;
2222
class Value;
23+
class ValueRange;
2324

2425
// Owning list of rewriting patterns.
2526
class OwningRewritePatternList;
2627

2728
/// Emit code that computes the given affine expression using standard
2829
/// arithmetic operations applied to the provided dimension and symbol values.
2930
Value expandAffineExpr(OpBuilder &builder, Location loc, AffineExpr expr,
30-
ArrayRef<Value> dimValues, ArrayRef<Value> symbolValues);
31+
ValueRange dimValues, ValueRange symbolValues);
3132

3233
/// Collect a set of patterns to convert from the Affine dialect to the Standard
3334
/// dialect, in particular convert structured affine control flow into CFG

mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class AffineApplyExpander
3737
public:
3838
/// This internal class expects arguments to be non-null, checks must be
3939
/// performed at the call site.
40-
AffineApplyExpander(OpBuilder &builder, ArrayRef<Value> dimValues,
41-
ArrayRef<Value> symbolValues, Location loc)
40+
AffineApplyExpander(OpBuilder &builder, ValueRange dimValues,
41+
ValueRange symbolValues, Location loc)
4242
: builder(builder), dimValues(dimValues), symbolValues(symbolValues),
4343
loc(loc) {}
4444

@@ -199,8 +199,8 @@ class AffineApplyExpander
199199

200200
private:
201201
OpBuilder &builder;
202-
ArrayRef<Value> dimValues;
203-
ArrayRef<Value> symbolValues;
202+
ValueRange dimValues;
203+
ValueRange symbolValues;
204204

205205
Location loc;
206206
};
@@ -209,16 +209,17 @@ class AffineApplyExpander
209209
/// Create a sequence of operations that implement the `expr` applied to the
210210
/// given dimension and symbol values.
211211
mlir::Value mlir::expandAffineExpr(OpBuilder &builder, Location loc,
212-
AffineExpr expr, ArrayRef<Value> dimValues,
213-
ArrayRef<Value> symbolValues) {
212+
AffineExpr expr, ValueRange dimValues,
213+
ValueRange symbolValues) {
214214
return AffineApplyExpander(builder, dimValues, symbolValues, loc).visit(expr);
215215
}
216216

217217
/// Create a sequence of operations that implement the `affineMap` applied to
218218
/// the given `operands` (as it it were an AffineApplyOp).
219-
Optional<SmallVector<Value, 8>> static expandAffineMap(
220-
OpBuilder &builder, Location loc, AffineMap affineMap,
221-
ArrayRef<Value> operands) {
219+
Optional<SmallVector<Value, 8>> static expandAffineMap(OpBuilder &builder,
220+
Location loc,
221+
AffineMap affineMap,
222+
ValueRange operands) {
222223
auto numDims = affineMap.getNumDims();
223224
auto expanded = functional::map(
224225
[numDims, &builder, loc, operands](AffineExpr expr) {
@@ -244,8 +245,7 @@ Optional<SmallVector<Value, 8>> static expandAffineMap(
244245
/// dependences that wouldn't exist in a tree reduction, but is easier to
245246
/// recognize as a reduction by the subsequent passes.
246247
static Value buildMinMaxReductionSeq(Location loc, CmpIPredicate predicate,
247-
ArrayRef<Value> values,
248-
OpBuilder &builder) {
248+
ValueRange values, OpBuilder &builder) {
249249
assert(!llvm::empty(values) && "empty min/max chain");
250250

251251
auto valueIt = values.begin();
@@ -262,9 +262,8 @@ static Value buildMinMaxReductionSeq(Location loc, CmpIPredicate predicate,
262262
/// applied to the respective operands, and compute the maximum value across
263263
/// the results.
264264
Value mlir::lowerAffineLowerBound(AffineForOp op, OpBuilder &builder) {
265-
SmallVector<Value, 8> boundOperands(op.getLowerBoundOperands());
266265
auto lbValues = expandAffineMap(builder, op.getLoc(), op.getLowerBoundMap(),
267-
boundOperands);
266+
op.getLowerBoundOperands());
268267
if (!lbValues)
269268
return nullptr;
270269
return buildMinMaxReductionSeq(op.getLoc(), CmpIPredicate::sgt, *lbValues,
@@ -275,8 +274,7 @@ Value mlir::lowerAffineLowerBound(AffineForOp op, OpBuilder &builder) {
275274
/// values of a (potentially) multi-output affine map applied to `operands`.
276275
static Value lowerAffineMapMin(OpBuilder &builder, Location loc, AffineMap map,
277276
ValueRange operands) {
278-
if (auto values =
279-
expandAffineMap(builder, loc, map, llvm::to_vector<4>(operands)))
277+
if (auto values = expandAffineMap(builder, loc, map, operands))
280278
return buildMinMaxReductionSeq(loc, CmpIPredicate::slt, *values, builder);
281279
return nullptr;
282280
}

0 commit comments

Comments
 (0)