From 8ed47b74300e524de45d4589609b490581e9db2f Mon Sep 17 00:00:00 2001 From: Alex Zinenko Date: Tue, 28 Jan 2020 11:53:00 +0100 Subject: [PATCH] [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. --- .../Conversion/AffineToStandard/AffineToStandard.h | 3 ++- .../AffineToStandard/AffineToStandard.cpp | 28 ++++++++++------------ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/mlir/include/mlir/Conversion/AffineToStandard/AffineToStandard.h b/mlir/include/mlir/Conversion/AffineToStandard/AffineToStandard.h index eee763e..8843e81 100644 --- a/mlir/include/mlir/Conversion/AffineToStandard/AffineToStandard.h +++ b/mlir/include/mlir/Conversion/AffineToStandard/AffineToStandard.h @@ -20,6 +20,7 @@ class MLIRContext; class OpBuilder; class RewritePattern; class Value; +class ValueRange; // Owning list of rewriting patterns. class OwningRewritePatternList; @@ -27,7 +28,7 @@ class OwningRewritePatternList; /// Emit code that computes the given affine expression using standard /// arithmetic operations applied to the provided dimension and symbol values. Value expandAffineExpr(OpBuilder &builder, Location loc, AffineExpr expr, - ArrayRef dimValues, ArrayRef symbolValues); + ValueRange dimValues, ValueRange symbolValues); /// Collect a set of patterns to convert from the Affine dialect to the Standard /// dialect, in particular convert structured affine control flow into CFG diff --git a/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp b/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp index ff4196f..601bfe7 100644 --- a/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp +++ b/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp @@ -37,8 +37,8 @@ class AffineApplyExpander public: /// This internal class expects arguments to be non-null, checks must be /// performed at the call site. - AffineApplyExpander(OpBuilder &builder, ArrayRef dimValues, - ArrayRef symbolValues, Location loc) + AffineApplyExpander(OpBuilder &builder, ValueRange dimValues, + ValueRange symbolValues, Location loc) : builder(builder), dimValues(dimValues), symbolValues(symbolValues), loc(loc) {} @@ -199,8 +199,8 @@ public: private: OpBuilder &builder; - ArrayRef dimValues; - ArrayRef symbolValues; + ValueRange dimValues; + ValueRange symbolValues; Location loc; }; @@ -209,16 +209,17 @@ private: /// Create a sequence of operations that implement the `expr` applied to the /// given dimension and symbol values. mlir::Value mlir::expandAffineExpr(OpBuilder &builder, Location loc, - AffineExpr expr, ArrayRef dimValues, - ArrayRef symbolValues) { + AffineExpr expr, ValueRange dimValues, + ValueRange symbolValues) { return AffineApplyExpander(builder, dimValues, symbolValues, loc).visit(expr); } /// Create a sequence of operations that implement the `affineMap` applied to /// the given `operands` (as it it were an AffineApplyOp). -Optional> static expandAffineMap( - OpBuilder &builder, Location loc, AffineMap affineMap, - ArrayRef operands) { +Optional> static expandAffineMap(OpBuilder &builder, + Location loc, + AffineMap affineMap, + ValueRange operands) { auto numDims = affineMap.getNumDims(); auto expanded = functional::map( [numDims, &builder, loc, operands](AffineExpr expr) { @@ -244,8 +245,7 @@ Optional> static expandAffineMap( /// dependences that wouldn't exist in a tree reduction, but is easier to /// recognize as a reduction by the subsequent passes. static Value buildMinMaxReductionSeq(Location loc, CmpIPredicate predicate, - ArrayRef values, - OpBuilder &builder) { + ValueRange values, OpBuilder &builder) { assert(!llvm::empty(values) && "empty min/max chain"); auto valueIt = values.begin(); @@ -262,9 +262,8 @@ static Value buildMinMaxReductionSeq(Location loc, CmpIPredicate predicate, /// applied to the respective operands, and compute the maximum value across /// the results. Value mlir::lowerAffineLowerBound(AffineForOp op, OpBuilder &builder) { - SmallVector boundOperands(op.getLowerBoundOperands()); auto lbValues = expandAffineMap(builder, op.getLoc(), op.getLowerBoundMap(), - boundOperands); + op.getLowerBoundOperands()); if (!lbValues) return nullptr; return buildMinMaxReductionSeq(op.getLoc(), CmpIPredicate::sgt, *lbValues, @@ -275,8 +274,7 @@ Value mlir::lowerAffineLowerBound(AffineForOp op, OpBuilder &builder) { /// values of a (potentially) multi-output affine map applied to `operands`. static Value lowerAffineMapMin(OpBuilder &builder, Location loc, AffineMap map, ValueRange operands) { - if (auto values = - expandAffineMap(builder, loc, map, llvm::to_vector<4>(operands))) + if (auto values = expandAffineMap(builder, loc, map, operands)) return buildMinMaxReductionSeq(loc, CmpIPredicate::slt, *values, builder); return nullptr; } -- 2.7.4