[flang-commits] [flang] d5ea1b2 - [flang] use mlir::LoopLikeOpInterface::blockIsInLoop
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Mon Feb 13 02:32:18 PST 2023
Author: Tom Eccles
Date: 2023-02-13T10:29:36Z
New Revision: d5ea1b22cba345e4fc0d42085a8c366407c7265b
URL: https://github.com/llvm/llvm-project/commit/d5ea1b22cba345e4fc0d42085a8c366407c7265b
DIFF: https://github.com/llvm/llvm-project/commit/d5ea1b22cba345e4fc0d42085a8c366407c7265b.diff
LOG: [flang] use mlir::LoopLikeOpInterface::blockIsInLoop
The inlined version of this function can now go away because
https://reviews.llvm.org/D141401 has been merged.
Differential Revision: https://reviews.llvm.org/D143659
Added:
Modified:
flang/lib/Optimizer/Transforms/StackArrays.cpp
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/Transforms/StackArrays.cpp b/flang/lib/Optimizer/Transforms/StackArrays.cpp
index 876760c45f551..a0cd6def7a38d 100644
--- a/flang/lib/Optimizer/Transforms/StackArrays.cpp
+++ b/flang/lib/Optimizer/Transforms/StackArrays.cpp
@@ -496,41 +496,8 @@ AllocMemConversion::matchAndRewrite(fir::AllocMemOp allocmem,
return mlir::success();
}
-// TODO: use mlir::blockIsInLoop once D141401 is merged
static bool isInLoop(mlir::Block *block) {
- mlir::Operation *parent = block->getParentOp();
-
- // The block could be inside a loop-like operation
- if (mlir::isa<mlir::LoopLikeOpInterface>(parent) ||
- parent->getParentOfType<mlir::LoopLikeOpInterface>())
- return true;
-
- // This block might be nested inside another block, which is in a loop
- if (!mlir::isa<mlir::FunctionOpInterface>(parent))
- if (isInLoop(parent->getBlock()))
- return true;
-
- // Or the block could be inside a control flow graph loop:
- // A block is in a control flow graph loop if it can reach itself in a graph
- // traversal
- llvm::DenseSet<mlir::Block *> visited;
- llvm::SmallVector<mlir::Block *> stack;
- stack.push_back(block);
- while (!stack.empty()) {
- mlir::Block *current = stack.pop_back_val();
- auto [it, inserted] = visited.insert(current);
- if (!inserted) {
- // loop detected
- if (current == block)
- return true;
- continue;
- }
-
- stack.reserve(stack.size() + current->getNumSuccessors());
- for (mlir::Block *successor : current->getSuccessors())
- stack.push_back(successor);
- }
- return false;
+ return mlir::LoopLikeOpInterface::blockIsInLoop(block);
}
static bool isInLoop(mlir::Operation *op) {
More information about the flang-commits
mailing list