[llvm] [Analysis] Visit orphan Functions in GCGPassManager catch-up loop (PR #194219)

Christudasan Devadasan via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 29 20:57:57 PDT 2026


================
@@ -541,10 +555,51 @@ bool CGPassManager::runOnModule(Module &M) {
 
     MaxSCCIterations.updateMax(Iteration);
   }
+
+  Changed |= RunAllPassesOnOrphanNodes(CG, CurSCC, VisitedNodes);
   Changed |= doFinalization(CG);
   return Changed;
 }
 
+bool CGPassManager::RunAllPassesOnOrphanNodes(
+    CallGraph &CG, CallGraphSCC &CurSCC,
+    std::vector<const CallGraphNode *> &VisitedNodes) {
+  bool Changed = false;
+
+  // Collect orphan roots up front so Module iteration cannot be disturbed
+  // by IR-level mutation a pass may perform on an orphan.
+  std::vector<CallGraphNode *> OrphanRoots;
+  for (Function &F : CG.getModule()) {
+    if (!F.isDeclaration()) {
+      CallGraphNode *Node = CG[&F];
+      if (!is_contained(VisitedNodes, Node))
+        OrphanRoots.push_back(Node);
+    }
+  }
+
+  for (CallGraphNode *Root : OrphanRoots) {
+    if (!is_contained(VisitedNodes, Root)) {
----------------
cdevadas wrote:

Is this check necessary as you are already adding the nodes to `OrphanRoots` when they aren't present in `VisitedNodes` in the earlier loop at Line 575?

https://github.com/llvm/llvm-project/pull/194219


More information about the llvm-commits mailing list