[flang] use mlir::LoopLikeOpInterface::blockIsInLoop
authorTom Eccles <tom.eccles@arm.com>
Thu, 9 Feb 2023 15:25:40 +0000 (15:25 +0000)
committerTom Eccles <tom.eccles@arm.com>
Mon, 13 Feb 2023 10:29:36 +0000 (10:29 +0000)
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

flang/lib/Optimizer/Transforms/StackArrays.cpp

index 876760c..a0cd6de 100644 (file)
@@ -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) {