[Mlir-commits] [mlir] f2ff8a8 - [MLIR] Add result status for normalizeAffineFor

Uday Bondhugula llvmlistbot at llvm.org
Thu Feb 10 22:22:22 PST 2022


Author: Uday Bondhugula
Date: 2022-02-11T11:29:52+05:30
New Revision: f2ff8a8e833cfe5067e73a7b5db1d2c6fd9126ef

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

LOG: [MLIR] Add result status for normalizeAffineFor

Add result status for normalizeAffineFor utility.

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

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Affine/Utils.h
    mlir/lib/Dialect/Affine/Transforms/AffineLoopNormalize.cpp
    mlir/lib/Dialect/Affine/Utils/Utils.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Affine/Utils.h b/mlir/include/mlir/Dialect/Affine/Utils.h
index ad91fbdeca503..47adf63377dac 100644
--- a/mlir/include/mlir/Dialect/Affine/Utils.h
+++ b/mlir/include/mlir/Dialect/Affine/Utils.h
@@ -158,10 +158,11 @@ void normalizeAffineParallel(AffineParallelOp op);
 /// Normalize an affine.for op. If the affine.for op has only a single iteration
 /// only then it is simply promoted, else it is normalized in the traditional
 /// way, by converting the lower bound to zero and loop step to one. The upper
-/// bound is set to the trip count of the loop. For now, original loops must
-/// have lower bound with a single result only. There is no such restriction on
-/// upper bounds.
-void normalizeAffineFor(AffineForOp op);
+/// bound is set to the trip count of the loop. Original loops must have a
+/// lower bound with only a single result. There is no such restriction on upper
+/// bounds. Returns success if the loop has been normalized (or is already in
+/// the normal form).
+LogicalResult normalizeAffineFor(AffineForOp op);
 
 /// Traverse `e` and return an AffineExpr where all occurrences of `dim` have
 /// been replaced by either:

diff  --git a/mlir/lib/Dialect/Affine/Transforms/AffineLoopNormalize.cpp b/mlir/lib/Dialect/Affine/Transforms/AffineLoopNormalize.cpp
index fe645576b7980..536f342e805b3 100644
--- a/mlir/lib/Dialect/Affine/Transforms/AffineLoopNormalize.cpp
+++ b/mlir/lib/Dialect/Affine/Transforms/AffineLoopNormalize.cpp
@@ -30,7 +30,7 @@ struct AffineLoopNormalizePass
       if (auto affineParallel = dyn_cast<AffineParallelOp>(op))
         normalizeAffineParallel(affineParallel);
       else if (auto affineFor = dyn_cast<AffineForOp>(op))
-        normalizeAffineFor(affineFor);
+        (void)normalizeAffineFor(affineFor);
     });
   }
 };

diff  --git a/mlir/lib/Dialect/Affine/Utils/Utils.cpp b/mlir/lib/Dialect/Affine/Utils/Utils.cpp
index f63dbf9fdc6d4..04371104540be 100644
--- a/mlir/lib/Dialect/Affine/Utils/Utils.cpp
+++ b/mlir/lib/Dialect/Affine/Utils/Utils.cpp
@@ -551,21 +551,21 @@ void mlir::normalizeAffineParallel(AffineParallelOp op) {
 /// bound is set to the trip count of the loop. For now, original loops must
 /// have lower bound with a single result only. There is no such restriction on
 /// upper bounds.
-void mlir::normalizeAffineFor(AffineForOp op) {
+LogicalResult mlir::normalizeAffineFor(AffineForOp op) {
   if (succeeded(promoteIfSingleIteration(op)))
-    return;
+    return success();
 
   // Check if the forop is already normalized.
   if (op.hasConstantLowerBound() && (op.getConstantLowerBound() == 0) &&
       (op.getStep() == 1))
-    return;
+    return success();
 
   // Check if the lower bound has a single result only. Loops with a max lower
   // bound can't be normalized without additional support like
   // affine.execute_region's. If the lower bound does not have a single result
   // then skip this op.
   if (op.getLowerBoundMap().getNumResults() != 1)
-    return;
+    return failure();
 
   Location loc = op.getLoc();
   OpBuilder opBuilder(op);
@@ -642,6 +642,7 @@ void mlir::normalizeAffineFor(AffineForOp op) {
                                    origLbMap.getNumSymbols(), newIVExpr);
   Operation *newIV = opBuilder.create<AffineApplyOp>(loc, ivMap, lbOperands);
   op.getInductionVar().replaceAllUsesExcept(newIV->getResult(0), newIV);
+  return success();
 }
 
 /// Ensure that all operations that could be executed after `start`


        


More information about the Mlir-commits mailing list