We need to propagate the debug location information even when dealing with the
[oota-llvm.git] / lib / VMCore / PassManager.cpp
index 29a6df0d6a7124cb51fbdccc9de36c99fd3a6f7d..4335757a5093ca7f81c83fae037ba51b064161d2 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;
@@ -457,8 +458,10 @@ void PMTopLevelManager::schedulePass(Pass *P) {
   // generate the analysis again. Stale analysis info should not be
   // available at this point.
   if (P->getPassInfo() &&
-      P->getPassInfo()->isAnalysis() && findAnalysisPass(P->getPassInfo()))
+      P->getPassInfo()->isAnalysis() && findAnalysisPass(P->getPassInfo())) {
+    delete P;
     return;
+  }
 
   AnalysisUsage *AnUsage = findAnalysisUsage(P);
 
@@ -676,7 +679,7 @@ void PMDataManager::verifyDomInfo(Pass &P, Function &F) {
   if (!VerifyDomInfo || !P.getResolver())
     return;
 
-  DominatorTree *DT = P.getAnalysisToUpdate<DominatorTree>();
+  DominatorTree *DT = P.getAnalysisIfAvailable<DominatorTree>();
   if (!DT)
     return;
 
@@ -692,7 +695,7 @@ void PMDataManager::verifyDomInfo(Pass &P, Function &F) {
     assert (0 && "Invalid dominator info");
   }
 
-  DominanceFrontier *DF = P.getAnalysisToUpdate<DominanceFrontier>();
+  DominanceFrontier *DF = P.getAnalysisIfAvailable<DominanceFrontier>();
   if (!DF) 
     return;
 
@@ -724,12 +727,12 @@ void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
         && std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) == 
         PreservedSet.end()) {
       // Remove this analysis
-      AvailableAnalysis.erase(Info);
       if (PassDebugging >= Details) {
         Pass *S = Info->second;
         cerr << " -- '" <<  P->getPassName() << "' is not preserving '";
         cerr << S->getPassName() << "'\n";
       }
+      AvailableAnalysis.erase(Info);
     }
   }
 
@@ -779,13 +782,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);
+      }
+    }
   }
 }
 
@@ -1075,8 +1088,8 @@ PMDataManager::~PMDataManager() {
 
 //===----------------------------------------------------------------------===//
 // NOTE: Is this the right place to define this method ?
-// getAnalysisToUpdate - Return an analysis result or null if it doesn't exist
-Pass *AnalysisResolver::getAnalysisToUpdate(AnalysisID ID, bool dir) const {
+// getAnalysisIfAvailable - Return analysis result or null if it doesn't exist.
+Pass *AnalysisResolver::getAnalysisIfAvailable(AnalysisID ID, bool dir) const {
   return PM.findAnalysisPass(ID, dir);
 }
 
@@ -1127,7 +1140,7 @@ BBPassManager::runOnFunction(Function &F) {
 }
 
 // Implement doInitialization and doFinalization
-inline bool BBPassManager::doInitialization(Module &M) {
+bool BBPassManager::doInitialization(Module &M) {
   bool Changed = false;
 
   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
@@ -1138,7 +1151,7 @@ inline bool BBPassManager::doInitialization(Module &M) {
   return Changed;
 }
 
-inline bool BBPassManager::doFinalization(Module &M) {
+bool BBPassManager::doFinalization(Module &M) {
   bool Changed = false;
 
   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
@@ -1149,7 +1162,7 @@ inline bool BBPassManager::doFinalization(Module &M) {
   return Changed;
 }
 
-inline bool BBPassManager::doInitialization(Function &F) {
+bool BBPassManager::doInitialization(Function &F) {
   bool Changed = false;
 
   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
@@ -1160,7 +1173,7 @@ inline bool BBPassManager::doInitialization(Function &F) {
   return Changed;
 }
 
-inline bool BBPassManager::doFinalization(Function &F) {
+bool BBPassManager::doFinalization(Function &F) {
   bool Changed = false;
 
   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
@@ -1229,7 +1242,7 @@ bool FunctionPassManager::doFinalization() {
 //===----------------------------------------------------------------------===//
 // FunctionPassManagerImpl implementation
 //
-inline bool FunctionPassManagerImpl::doInitialization(Module &M) {
+bool FunctionPassManagerImpl::doInitialization(Module &M) {
   bool Changed = false;
 
   for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {  
@@ -1240,7 +1253,7 @@ inline bool FunctionPassManagerImpl::doInitialization(Module &M) {
   return Changed;
 }
 
-inline bool FunctionPassManagerImpl::doFinalization(Module &M) {
+bool FunctionPassManagerImpl::doFinalization(Module &M) {
   bool Changed = false;
 
   for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {  
@@ -1335,7 +1348,7 @@ bool FPPassManager::runOnModule(Module &M) {
   return Changed |= doFinalization(M);
 }
 
-inline bool FPPassManager::doInitialization(Module &M) {
+bool FPPassManager::doInitialization(Module &M) {
   bool Changed = false;
 
   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {  
@@ -1346,7 +1359,7 @@ inline bool FPPassManager::doInitialization(Module &M) {
   return Changed;
 }
 
-inline bool FPPassManager::doFinalization(Module &M) {
+bool FPPassManager::doFinalization(Module &M) {
   bool Changed = false;
 
   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {