[Mlir-commits] [mlir] 0b83a35 - [MLIR][NFC] Drop unnecessary use of OpBuilder in build trip count map

Uday Bondhugula llvmlistbot at llvm.org
Sat Oct 2 20:55:39 PDT 2021


Author: Uday Bondhugula
Date: 2021-10-03T09:25:18+05:30
New Revision: 0b83a35caf2205e7d38a6ca164ee123fdbcff920

URL: https://github.com/llvm/llvm-project/commit/0b83a35caf2205e7d38a6ca164ee123fdbcff920
DIFF: https://github.com/llvm/llvm-project/commit/0b83a35caf2205e7d38a6ca164ee123fdbcff920.diff

LOG: [MLIR][NFC] Drop unnecessary use of OpBuilder in build trip count map

NFC. Drop unnecessary use of OpBuilder in buildTripCountMapAndOperands.
Rename this to getTripCountMapAndOperands and remove stale comments.

Differential Revision: https://reviews.llvm.org/D110993

Added: 
    

Modified: 
    mlir/include/mlir/Analysis/LoopAnalysis.h
    mlir/lib/Analysis/LoopAnalysis.cpp
    mlir/lib/Transforms/Utils/LoopUtils.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Analysis/LoopAnalysis.h b/mlir/include/mlir/Analysis/LoopAnalysis.h
index 145019f61a893..41c0e7c82255d 100644
--- a/mlir/include/mlir/Analysis/LoopAnalysis.h
+++ b/mlir/include/mlir/Analysis/LoopAnalysis.h
@@ -34,10 +34,8 @@ class Value;
 /// multi-result map. The trip count expression is simplified before returning.
 /// This method only utilizes map composition to construct lower and upper
 /// bounds before computing the trip count expressions
-// TODO: this should be moved into 'Transforms/' and be replaced by a pure
-// analysis method relying on FlatAffineConstraints
-void buildTripCountMapAndOperands(AffineForOp forOp, AffineMap *map,
-                                  SmallVectorImpl<Value> *operands);
+void getTripCountMapAndOperands(AffineForOp forOp, AffineMap *map,
+                                SmallVectorImpl<Value> *operands);
 
 /// Returns the trip count of the loop if it's a constant, None otherwise. This
 /// uses affine expression analysis and is able to determine constant trip count

diff  --git a/mlir/lib/Analysis/LoopAnalysis.cpp b/mlir/lib/Analysis/LoopAnalysis.cpp
index f26875bd04f3b..d40958e877771 100644
--- a/mlir/lib/Analysis/LoopAnalysis.cpp
+++ b/mlir/lib/Analysis/LoopAnalysis.cpp
@@ -32,21 +32,19 @@ using namespace mlir;
 /// expression is simplified before returning. This method only utilizes map
 /// composition to construct lower and upper bounds before computing the trip
 /// count expressions.
-void mlir::buildTripCountMapAndOperands(
+void mlir::getTripCountMapAndOperands(
     AffineForOp forOp, AffineMap *tripCountMap,
     SmallVectorImpl<Value> *tripCountOperands) {
-  int64_t loopSpan;
-
+  MLIRContext *context = forOp.getContext();
   int64_t step = forOp.getStep();
-  OpBuilder b(forOp.getOperation());
-
+  int64_t loopSpan;
   if (forOp.hasConstantBounds()) {
     int64_t lb = forOp.getConstantLowerBound();
     int64_t ub = forOp.getConstantUpperBound();
     loopSpan = ub - lb;
     if (loopSpan < 0)
       loopSpan = 0;
-    *tripCountMap = b.getConstantAffineMap(ceilDiv(loopSpan, step));
+    *tripCountMap = AffineMap::getConstantMap(ceilDiv(loopSpan, step), context);
     tripCountOperands->clear();
     return;
   }
@@ -65,7 +63,7 @@ void mlir::buildTripCountMapAndOperands(
   SmallVector<AffineExpr, 4> lbSplatExpr(ubValueMap.getNumResults(),
                                          lbMap.getResult(0));
   auto lbMapSplat = AffineMap::get(lbMap.getNumDims(), lbMap.getNumSymbols(),
-                                   lbSplatExpr, b.getContext());
+                                   lbSplatExpr, context);
   AffineValueMap lbSplatValueMap(lbMapSplat, forOp.getLowerBoundOperands());
 
   AffineValueMap tripCountValueMap;
@@ -82,14 +80,10 @@ void mlir::buildTripCountMapAndOperands(
 /// Returns the trip count of the loop if it's a constant, None otherwise. This
 /// method uses affine expression analysis (in turn using getTripCount) and is
 /// able to determine constant trip count in non-trivial cases.
-// FIXME(mlir-team): this is really relying on buildTripCountMapAndOperands;
-// being an analysis utility, it shouldn't. Replace with a version that just
-// works with analysis structures (FlatAffineConstraints) and thus doesn't
-// update the IR.
 Optional<uint64_t> mlir::getConstantTripCount(AffineForOp forOp) {
   SmallVector<Value, 4> operands;
   AffineMap map;
-  buildTripCountMapAndOperands(forOp, &map, &operands);
+  getTripCountMapAndOperands(forOp, &map, &operands);
 
   if (!map)
     return None;
@@ -115,7 +109,7 @@ Optional<uint64_t> mlir::getConstantTripCount(AffineForOp forOp) {
 uint64_t mlir::getLargestDivisorOfTripCount(AffineForOp forOp) {
   SmallVector<Value, 4> operands;
   AffineMap map;
-  buildTripCountMapAndOperands(forOp, &map, &operands);
+  getTripCountMapAndOperands(forOp, &map, &operands);
 
   if (!map)
     return 1;

diff  --git a/mlir/lib/Transforms/Utils/LoopUtils.cpp b/mlir/lib/Transforms/Utils/LoopUtils.cpp
index bf472ad46d4b2..7a59d505e8a51 100644
--- a/mlir/lib/Transforms/Utils/LoopUtils.cpp
+++ b/mlir/lib/Transforms/Utils/LoopUtils.cpp
@@ -68,7 +68,7 @@ static void getCleanupLoopLowerBound(AffineForOp forOp, unsigned unrollFactor,
 
   AffineMap tripCountMap;
   SmallVector<Value, 4> tripCountOperands;
-  buildTripCountMapAndOperands(forOp, &tripCountMap, &tripCountOperands);
+  getTripCountMapAndOperands(forOp, &tripCountMap, &tripCountOperands);
 
   // Sometimes the trip count cannot be expressed as an affine expression.
   if (!tripCountMap) {


        


More information about the Mlir-commits mailing list