[Mlir-commits] [mlir] f043677 - [MLIR] Make isPerfectlyNested check more efficient
Uday Bondhugula
llvmlistbot at llvm.org
Sat Apr 18 11:24:27 PDT 2020
Author: Uday Bondhugula
Date: 2020-04-18T23:34:49+05:30
New Revision: f043677f6dd6e5392509b59139999918b421699d
URL: https://github.com/llvm/llvm-project/commit/f043677f6dd6e5392509b59139999918b421699d
DIFF: https://github.com/llvm/llvm-project/commit/f043677f6dd6e5392509b59139999918b421699d.diff
LOG: [MLIR] Make isPerfectlyNested check more efficient
Make mlir::isPerfectlyNested more efficient; use O(1) check instead of
O(N) size() method.
Differential Revision: https://reviews.llvm.org/D78428
Added:
Modified:
mlir/lib/Transforms/Utils/LoopUtils.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Transforms/Utils/LoopUtils.cpp b/mlir/lib/Transforms/Utils/LoopUtils.cpp
index c03cf6cfc282..2175e6709f65 100644
--- a/mlir/lib/Transforms/Utils/LoopUtils.cpp
+++ b/mlir/lib/Transforms/Utils/LoopUtils.cpp
@@ -705,17 +705,25 @@ bool mlir::isValidLoopInterchangePermutation(ArrayRef<AffineForOp> loops,
return checkLoopInterchangeDependences(depCompsVec, loops, loopPermMap);
}
-/// Return true if `loops` is a perfect nest.
+/// Returns true if `loops` is a perfectly nested loop nest, where loops appear
+/// in it from outermost to innermost.
static bool LLVM_ATTRIBUTE_UNUSED
isPerfectlyNested(ArrayRef<AffineForOp> loops) {
- auto outerLoop = loops.front();
+ assert(!loops.empty() && "no loops provided");
+
+ // We already know that the block can't be empty.
+ auto hasTwoElements = [](Block *block) {
+ auto secondOpIt = std::next(block->begin());
+ return secondOpIt != block->end() && &*secondOpIt == &block->back();
+ };
+
+ auto enclosingLoop = loops.front();
for (auto loop : loops.drop_front()) {
auto parentForOp = dyn_cast<AffineForOp>(loop.getParentOp());
// parentForOp's body should be just this loop and the terminator.
- if (parentForOp != outerLoop ||
- parentForOp.getBody()->getOperations().size() != 2)
+ if (parentForOp != enclosingLoop || !hasTwoElements(parentForOp.getBody()))
return false;
- outerLoop = loop;
+ enclosingLoop = loop;
}
return true;
}
More information about the Mlir-commits
mailing list