Skip to content

Commit

Permalink
[flang] use mlir::LoopLikeOpInterface::blockIsInLoop
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tblah committed Feb 13, 2023
1 parent e6ec76c commit d5ea1b2
Showing 1 changed file with 1 addition and 34 deletions.
35 changes: 1 addition & 34 deletions flang/lib/Optimizer/Transforms/StackArrays.cpp
Expand Up @@ -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) {
Expand Down

0 comments on commit d5ea1b2

Please sign in to comment.