- Add a "getOrInsertGlobal" method to the Module class. This acts similarly to
[oota-llvm.git] / lib / VMCore / PassManager.cpp
index d7b3cc7e638baf28be9716070be18189099cf630..ef90aace3dab03d3e07f5ff6bf435934f9c28fa3 100644 (file)
@@ -22,6 +22,7 @@
 #include "llvm/Analysis/Dominators.h"
 #include "llvm-c/Core.h"
 #include <algorithm>
+#include <cstdio>
 #include <vector>
 #include <map>
 using namespace llvm;
@@ -73,7 +74,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 +130,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 +194,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 +270,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
@@ -780,13 +780,23 @@ void PMDataManager::removeDeadPasses(Pass *P, const char *Msg,
     if (TheTimeInfo) TheTimeInfo->passStarted(*I);
     (*I)->releaseMemory();
     if (TheTimeInfo) TheTimeInfo->passEnded(*I);
-
-    std::map<AnalysisID, Pass*>::iterator Pos = 
-      AvailableAnalysis.find((*I)->getPassInfo());
-    
-    // It is possible that pass is already removed from the AvailableAnalysis
-    if (Pos != AvailableAnalysis.end())
-      AvailableAnalysis.erase(Pos);
+    if (const PassInfo *PI = (*I)->getPassInfo()) {
+      std::map<AnalysisID, Pass*>::iterator Pos =
+        AvailableAnalysis.find(PI);
+
+      // It is possible that pass is already removed from the AvailableAnalysis
+      if (Pos != AvailableAnalysis.end())
+        AvailableAnalysis.erase(Pos);
+
+      // Remove all interfaces this pass implements, for which it is also
+      // listed as the available implementation.
+      const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
+      for (unsigned i = 0, e = II.size(); i != e; ++i) {
+        Pos = AvailableAnalysis.find(II[i]);
+        if (Pos != AvailableAnalysis.end() && Pos->second == *I)
+          AvailableAnalysis.erase(Pos);
+      }
+    }
   }
 }
 
@@ -1582,7 +1592,7 @@ void ModulePass::assignPassManager(PMStack &PMS,
     else
       break;
   }
-
+  assert(!PMS.empty() && "Unable to find appropriate Pass Manager");
   PMS.top()->add(this);
 }
 
@@ -1591,7 +1601,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();
@@ -1615,13 +1625,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);