[cfe-dev] Patch for fixing infinite rec. within PMTopLevelManager::schedulePass

philipp.legrum at daimler.com philipp.legrum at daimler.com
Thu Feb 25 08:24:39 PST 2010


Hello Developers,

I figured, that trying to load two passes that require each other results 
in an infinite recursion of PMTopLevelManager::schedulePass
So I added tracing if schedulePass processes a pass that an outer 
invocation of schedulePass is already processing.
If so, it aborts with an error message and outputs the cycle.

Would be nice if someone could review the patch and apply if suitable 
and/or give me feedback.

Thank you.
Philipp



Index: include/llvm/PassManagers.h
===================================================================
--- include/llvm/PassManagers.h (revision 97141)
+++ include/llvm/PassManagers.h (working copy)
@@ -256,6 +256,10 @@
   SmallVector<ImmutablePass *, 8> ImmutablePasses;
 
   DenseMap<Pass *, AnalysisUsage *> AnUsageMap;
+
+  // Stack to keep track of circular module dependencies
+  // during pass scheduling.
+  SmallVector<const PassInfo *, 12> schedulingTrace;
 };
 
 
Index: lib/VMCore/PassManager.cpp
===================================================================
--- lib/VMCore/PassManager.cpp  (revision 97141)
+++ lib/VMCore/PassManager.cpp  (working copy)
@@ -495,6 +495,26 @@
   // TODO : Allocate function manager for this pass, other wise required 
set
   // may be inserted into previous function manager
 
+  // Monitor circular dependencies of passes
+  SmallVector<const PassInfo *, 12>::iterator result =
+  std::find(schedulingTrace.begin(), schedulingTrace.end(),
+            P->getPassInfo());
+ 
+  // If we are about to schedule a pass we are already scheduling
+  // we have detected a cyclic requirement.
+  if (result != schedulingTrace.end()){
+    errs() << "Error: Pass scheduler detected cyclic requirement in 
passes:\n";
+    for (SmallVector<const PassInfo *, 12>::iterator I = result,
+         E = schedulingTrace.end(); I != E; ++I){
+      errs() << "  " << (*I)->getPassName() << "\n";
+    }
+    errs() << "  " << (*result)->getPassName() << "\n";
+    exit(-1);
+  }
+ 
+  // Track the recursive pass scheduling
+  schedulingTrace.push_back(P->getPassInfo());
+
   // Give pass a chance to prepare the stage.
   P->preparePassManager(activeStack);
 
@@ -539,6 +559,7 @@
       }
     }
   }
+  schedulingTrace.pop_back();
 
   // Now all required passes are available.
   addTopLevelPass(P);

If you are not the intended addressee, please inform us immediately that you have received this e-mail in error, and delete it. We thank you for your cooperation.  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100225/99961a0b/attachment.html>


More information about the cfe-dev mailing list