From a9dcbcfe9feff14364b9ea6f5c8d48df41890f8b Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sat, 12 Feb 2022 14:19:35 +0100 Subject: [PATCH] Use AffineMap::getSliceMap where applicable. NFCI. --- mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp | 24 +++++++++++------------- mlir/lib/IR/AffineMap.cpp | 5 ++--- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp index 7604d14..86ef121 100644 --- a/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp @@ -15,7 +15,7 @@ #include "mlir/IR/AffineExprVisitor.h" #include "mlir/IR/AffineMap.h" #include "mlir/IR/TypeUtilities.h" -#include "llvm/ADT/SmallSet.h" +#include "llvm/ADT/SmallBitVector.h" using namespace mlir; using namespace mlir::linalg; @@ -484,15 +484,15 @@ SmallVector LinalgOp::computeStaticLoopSizes() { /// are used within an AffineExpr. struct HasAffineDimExprVisitor : public AffineExprVisitor { - HasAffineDimExprVisitor(llvm::SmallSet &positions) - : positions(positions) {} + HasAffineDimExprVisitor(llvm::SmallBitVector positions) + : positions(std::move(positions)) {} bool visitAffineBinaryOpExpr(AffineBinaryOpExpr binaryOpExpr) { return visit(binaryOpExpr.getLHS()) || visit(binaryOpExpr.getRHS()); } bool visitDimExpr(AffineDimExpr dimExpr) { - return positions.count(dimExpr.getPosition()); + return positions.test(dimExpr.getPosition()); } bool visitConstantExpr(AffineConstantExpr constExpr) { return false; } @@ -500,7 +500,7 @@ struct HasAffineDimExprVisitor bool visitSymbolExpr(AffineSymbolExpr symbolExpr) { return false; } private: - llvm::SmallSet positions; + llvm::SmallBitVector positions; }; LogicalResult @@ -523,19 +523,17 @@ LinalgOp::reifyResultShapes(OpBuilder &b, /// From loopsToShapesMap extract the submap that represents the shape of the /// (resultIdx, dim) needed. - SmallVector resultPosRange = - llvm::to_vector<4>(llvm::seq(resultShapesSubMapPos.first, - resultShapesSubMapPos.second)); - AffineMap loopToResultsShapeMap = loopsToShapesMap.getSubMap(resultPosRange); + AffineMap loopToResultsShapeMap = loopsToShapesMap.getSliceMap( + resultShapesSubMapPos.first, + resultShapesSubMapPos.second - resultShapesSubMapPos.first); AffineMap resultShapesFromInputShapesMap = loopToResultsShapeMap.compose(getShapesToLoopsMap()); // Check that the result dim map does not contain the positions corresponding // to the outputs. - llvm::SmallSet outputDims; - llvm::for_each(resultPosRange, - [&outputDims](unsigned dim) { outputDims.insert(dim); }); - HasAffineDimExprVisitor checkDimExpr(outputDims); + llvm::SmallBitVector outputDims(resultShapesFromInputShapesMap.getNumDims()); + outputDims.set(resultShapesSubMapPos.first, resultShapesSubMapPos.second); + HasAffineDimExprVisitor checkDimExpr(std::move(outputDims)); Location loc = getOperation()->getLoc(); auto allResultDimValues = applyMapToValues(b, loc, resultShapesFromInputShapesMap, diff --git a/mlir/lib/IR/AffineMap.cpp b/mlir/lib/IR/AffineMap.cpp index 7fbe748..73cbd3b 100644 --- a/mlir/lib/IR/AffineMap.cpp +++ b/mlir/lib/IR/AffineMap.cpp @@ -534,7 +534,7 @@ AffineMap AffineMap::getMajorSubMap(unsigned numResults) const { return AffineMap(); if (numResults > getNumResults()) return *this; - return getSubMap(llvm::to_vector<4>(llvm::seq(0, numResults))); + return getSliceMap(0, numResults); } AffineMap AffineMap::getMinorSubMap(unsigned numResults) const { @@ -542,8 +542,7 @@ AffineMap AffineMap::getMinorSubMap(unsigned numResults) const { return AffineMap(); if (numResults > getNumResults()) return *this; - return getSubMap(llvm::to_vector<4>( - llvm::seq(getNumResults() - numResults, getNumResults()))); + return getSliceMap(getNumResults() - numResults, numResults); } AffineMap mlir::compressDims(AffineMap map, -- 2.7.4