diff --git a/flang/lib/Optimizer/Transforms/StackArrays.cpp b/flang/lib/Optimizer/Transforms/StackArrays.cpp --- a/flang/lib/Optimizer/Transforms/StackArrays.cpp +++ b/flang/lib/Optimizer/Transforms/StackArrays.cpp @@ -496,41 +496,8 @@ 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(parent) || - parent->getParentOfType()) - return true; - - // This block might be nested inside another block, which is in a loop - if (!mlir::isa(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 visited; - llvm::SmallVector 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) {