Update module pass manager to support module passes that require
authorDevang Patel <dpatel@apple.com>
Mon, 16 Apr 2007 20:27:05 +0000 (20:27 +0000)
committerDevang Patel <dpatel@apple.com>
Mon, 16 Apr 2007 20:27:05 +0000 (20:27 +0000)
function passes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36154 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/PassManager.cpp

index 02a27c252732a7de8355e1227600fc49e2cd4dda..1b2349006af9b6c9875f5e8a5b8de66a2c2af33d 100644 (file)
@@ -195,6 +195,11 @@ public:
   /// through getAnalysis interface.
   virtual void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass);
 
+  /// Return function pass corresponding to PassInfo PI, that is 
+  /// required by module pass MP. Instantiate analysis pass, by using
+  /// its runOnFunction() for function F.
+  virtual Pass* getOnTheFlyPass(Pass *MP, const PassInfo *PI, Function &F);
+
   virtual const char *getPassName() const {
     return "Module Pass Manager";
   }
@@ -218,6 +223,11 @@ public:
   virtual PassManagerType getPassManagerType() const { 
     return PMT_ModulePassManager; 
   }
+
+ private:
+  /// Collection of on the fly FPPassManagers. These managers manage
+  /// function passes that are required by module passes.
+  std::map<Pass *, FPPassManager *> OnTheFlyManagers;
 };
 
 //===----------------------------------------------------------------------===//
@@ -614,6 +624,10 @@ void PMDataManager::removeDeadPasses(Pass *P, std::string Msg,
                                      enum PassDebuggingString DBG_STR) {
 
   std::vector<Pass *> DeadPasses;
+
+  if (!TPM)
+    return;
+
   TPM->collectLastUses(DeadPasses, P);
 
   for (std::vector<Pass *>::iterator I = DeadPasses.begin(),
@@ -678,14 +692,6 @@ void PMDataManager::add(Pass *P,
         assert (0 && "Unable to accomodate Required Pass");
     }
 
-    // Now, take care of required analysises that are not available.
-    for (SmallVector<AnalysisID, 8>::iterator 
-           I = ReqAnalysisNotAvailable.begin(), 
-           E = ReqAnalysisNotAvailable.end() ;I != E; ++I) {
-      Pass *AnalysisPass = (*I)->createPass();
-      this->addLowerLevelRequiredPass(P, AnalysisPass);
-    }
-
     // Set P as P's last user until someone starts using P.
     // However, if P is a Pass Manager then it does not need
     // to record its last user.
@@ -699,6 +705,14 @@ void PMDataManager::add(Pass *P,
       TransferLastUses.clear();
     }
 
+    // Now, take care of required analysises that are not available.
+    for (SmallVector<AnalysisID, 8>::iterator 
+           I = ReqAnalysisNotAvailable.begin(), 
+           E = ReqAnalysisNotAvailable.end() ;I != E; ++I) {
+      Pass *AnalysisPass = (*I)->createPass();
+      this->addLowerLevelRequiredPass(P, AnalysisPass);
+    }
+
     // Take a note of analysis required and made available by this pass.
     // Remove the analysis not preserved by this pass
     removeNotPreservedAnalysis(P);
@@ -1190,10 +1204,29 @@ void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
            RequiredPass->getPotentialPassManagerType())
           && "Unable to handle Pass that requires lower level Analysis pass");
 
-  assert (0 && 
-          "Unable to handle Pass that requires lower level Analysis pass");
+  FPPassManager *FPP = OnTheFlyManagers[P];
+  if (!FPP) {
+    FPP = new FPPassManager(getDepth() + 1);
+    OnTheFlyManagers[P] = FPP;
+  }
+
+  FPP->add(RequiredPass, false);
 }
+
+/// Return function pass corresponding to PassInfo PI, that is 
+/// required by module pass MP. Instantiate analysis pass, by using
+/// its runOnFunction() for function F.
+Pass* MPPassManager::getOnTheFlyPass(Pass *MP, const PassInfo *PI, 
+                                     Function &F) {
+   AnalysisID AID = PI;
+  FPPassManager *FPP =OnTheFlyManagers[MP];
+  assert (FPP && "Unable to find on the fly pass");
+  
+  FPP->runOnFunction(F);
+  return FPP->findAnalysisPass(AID, false);
+}
+
+
 //===----------------------------------------------------------------------===//
 // PassManagerImpl implementation
 //