Verify function attributes.
[oota-llvm.git] / lib / VMCore / PassManager.cpp
index 68a856a4d519ca976a351b045ee117b80dc6d0ad..29a6df0d6a7124cb51fbdccc9de36c99fd3a6f7d 100644 (file)
@@ -73,7 +73,7 @@ class VISIBILITY_HIDDEN BBPassManager : public PMDataManager,
 public:
   static char ID;
   explicit BBPassManager(int Depth) 
-    : PMDataManager(Depth), FunctionPass((intptr_t)&ID) {}
+    : PMDataManager(Depth), FunctionPass(&ID) {}
 
   /// Execute all of the passes scheduled for execution.  Keep track of
   /// whether any of the passes modifies the function, and if so, return true.
@@ -129,7 +129,7 @@ class FunctionPassManagerImpl : public Pass,
 public:
   static char ID;
   explicit FunctionPassManagerImpl(int Depth) : 
-    Pass((intptr_t)&ID), PMDataManager(Depth), 
+    Pass(&ID), PMDataManager(Depth), 
     PMTopLevelManager(TLM_Function) { }
 
   /// add - Add a pass to the queue of passes to run.  This passes ownership of
@@ -193,7 +193,7 @@ class MPPassManager : public Pass, public PMDataManager {
 public:
   static char ID;
   explicit MPPassManager(int Depth) :
-    Pass((intptr_t)&ID), PMDataManager(Depth) { }
+    Pass(&ID), PMDataManager(Depth) { }
 
   // Delete on the fly managers.
   virtual ~MPPassManager() {
@@ -269,8 +269,7 @@ class PassManagerImpl : public Pass,
 public:
   static char ID;
   explicit PassManagerImpl(int Depth) :
-    Pass((intptr_t)&ID), PMDataManager(Depth),
-    PMTopLevelManager(TLM_Pass) { }
+    Pass(&ID), PMDataManager(Depth), PMTopLevelManager(TLM_Pass) { }
 
   /// add - Add a pass to the queue of passes to run.  This passes ownership of
   /// the Pass to the PassManager.  When the PassManager is destroyed, the pass
@@ -463,20 +462,34 @@ void PMTopLevelManager::schedulePass(Pass *P) {
 
   AnalysisUsage *AnUsage = findAnalysisUsage(P);
 
-  const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet();
-  for (AnalysisUsage::VectorType::const_iterator I = RequiredSet.begin(),
-         E = RequiredSet.end(); I != E; ++I) {
-
-    Pass *AnalysisPass = findAnalysisPass(*I);
-    if (!AnalysisPass) {
-      AnalysisPass = (*I)->createPass();
-      // Schedule this analysis run first only if it is not a lower level
-      // analysis pass. Lower level analsyis passes are run on the fly.
-      if (P->getPotentialPassManagerType () >=
-          AnalysisPass->getPotentialPassManagerType())
-        schedulePass(AnalysisPass);
-      else
-        delete AnalysisPass;
+  bool checkAnalysis = true;
+  while (checkAnalysis) {
+    checkAnalysis = false;
+  
+    const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet();
+    for (AnalysisUsage::VectorType::const_iterator I = RequiredSet.begin(),
+           E = RequiredSet.end(); I != E; ++I) {
+      
+      Pass *AnalysisPass = findAnalysisPass(*I);
+      if (!AnalysisPass) {
+        AnalysisPass = (*I)->createPass();
+        if (P->getPotentialPassManagerType () ==
+            AnalysisPass->getPotentialPassManagerType())
+          // Schedule analysis pass that is managed by the same pass manager.
+          schedulePass(AnalysisPass);
+        else if (P->getPotentialPassManagerType () >
+                 AnalysisPass->getPotentialPassManagerType()) {
+          // Schedule analysis pass that is managed by a new manager.
+          schedulePass(AnalysisPass);
+          // Recheck analysis passes to ensure that required analysises that
+          // are already checked are still available.
+          checkAnalysis = true;
+        }
+        else
+          // Do not schedule this analysis. Lower level analsyis 
+          // passes are run on the fly.
+          delete AnalysisPass;
+      }
     }
   }
 
@@ -1568,7 +1581,7 @@ void ModulePass::assignPassManager(PMStack &PMS,
     else
       break;
   }
-
+  assert(!PMS.empty() && "Unable to find appropriate Pass Manager");
   PMS.top()->add(this);
 }
 
@@ -1577,7 +1590,7 @@ void ModulePass::assignPassManager(PMStack &PMS,
 void FunctionPass::assignPassManager(PMStack &PMS,
                                      PassManagerType PreferredType) {
 
-  // Find Module Pass Manager (TODO : Or Call Graph Pass Manager)
+  // Find Module Pass Manager
   while(!PMS.empty()) {
     if (PMS.top()->getPassManagerType() > PMT_FunctionPassManager)
       PMS.pop();
@@ -1601,13 +1614,7 @@ void FunctionPass::assignPassManager(PMStack &PMS,
 
     // [3] Assign manager to manage this new manager. This may create
     // and push new managers into PMS
-
-    // If Call Graph Pass Manager is active then use it to manage
-    // this new Function Pass manager.
-    if (PMD->getPassManagerType() == PMT_CallGraphPassManager)
-      FPP->assignPassManager(PMS, PMT_CallGraphPassManager);
-    else
-      FPP->assignPassManager(PMS);
+    FPP->assignPassManager(PMS, PMD->getPassManagerType());
 
     // [4] Push new manager into PMS
     PMS.push(FPP);