================
@@ -69,6 +73,30 @@ class UseAfterMoveFinder {
   llvm::SmallPtrSet<const CFGBlock *, 8> Visited;
 };
 
+/// Returns whether the `Before` block can reach the `After` block.
+bool reaches(const CFGBlock *Before, const CFGBlock *After) {
+  llvm::SmallVector<const CFGBlock *> Stack;
+  llvm::SmallPtrSet<const CFGBlock *, 1> Visited;
+
+  Stack.push_back(Before);
+  while (!Stack.empty()) {
+    const CFGBlock *Current = Stack.back();
+    Stack.pop_back();
+
+    if (Current == After)
+      return true;
+
+    Visited.insert(Current);
+
+    for (const CFGBlock *Succ : Current->succs()) {
+      if (Succ && !Visited.contains(Succ))
+        Stack.push_back(Succ);
+    }
+  }
+
+  return false;
+}
+
----------------
5chmidti wrote:

What do you think about using 
https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Analysis/Analyses/CFGReachabilityAnalysis.h?

We are rebuilding the CFG a lot of times and don't cache anything, so the 
caching in `CFGReverseBlockReachabilityAnalysis` won't have any worth until we 
do, but it is an existing implementation of what you are doing here, so we 
should at least consider it.

https://github.com/llvm/llvm-project/pull/93623
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to