[PATCH] D78428: [MLIR] Make isPerfectlyNested check more efficient
Uday Bondhugula via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 18 11:50:14 PDT 2020
This revision was automatically updated to reflect the committed changes.
bondhugula marked an inline comment as done.
Closed by commit rGf043677f6dd6: [MLIR] Make isPerfectlyNested check more efficient (authored by bondhugula).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D78428/new/
https://reviews.llvm.org/D78428
Files:
mlir/lib/Transforms/Utils/LoopUtils.cpp
Index: mlir/lib/Transforms/Utils/LoopUtils.cpp
===================================================================
--- mlir/lib/Transforms/Utils/LoopUtils.cpp
+++ mlir/lib/Transforms/Utils/LoopUtils.cpp
@@ -705,17 +705,25 @@
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78428.258537.patch
Type: text/x-patch
Size: 1369 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200418/91a67cc9/attachment.bin>
More information about the llvm-commits
mailing list