Use inverted map to speedup collectLastUses().
authorDevang Patel <dpatel@apple.com>
Sat, 17 Feb 2007 03:53:44 +0000 (03:53 +0000)
committerDevang Patel <dpatel@apple.com>
Sat, 17 Feb 2007 03:53:44 +0000 (03:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34364 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/PassManagers.h
lib/VMCore/PassManager.cpp

index bd3672f944ac22d396ef410ec18c66fe2b9c5cec..4b82c98985319a636939c57e5b314c11eaeb8bf2 100644 (file)
@@ -120,6 +120,10 @@ public:
   /// Collect passes whose last user is P
   void collectLastUses(std::vector<Pass *> &LastUses, Pass *P);
 
+  // Walk LastUser map and create inverted map. This should be done
+  // after all passes are added and before running first pass.
+  void collectInvertedLU();
+
   /// Find the pass that implements Analysis AID. Search immutable
   /// passes and all pass managers. If desired pass is not found
   /// then return NULL.
@@ -171,6 +175,7 @@ private:
   // Map to keep track of last user of the analysis pass.
   // LastUser->second is the last user of Lastuser->first.
   std::map<Pass *, Pass *> LastUser;
+  std::map<Pass *, std::vector <Pass *> > InvertedLU;
 
   /// Immutable passes are managed by top level manager.
   std::vector<ImmutablePass *> ImmutablePasses;
index bc85967ee1c0fd62218667cc64e70085c18f3156..6c1f2360d83845ade99ea4fa883758b6a4090916 100644 (file)
@@ -362,13 +362,19 @@ void PMTopLevelManager::setLastUser(std::vector<Pass *> &AnalysisPasses,
   }
 }
 
+// Walk LastUser map and create inverted map. This should be done
+// after all passes are added and before running first pass.
+void PMTopLevelManager::collectInvertedLU() {
+   for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
+          LUE = LastUser.end(); LUI != LUE; ++LUI)
+     InvertedLU[LUI->second].push_back(LUI->first);
+}
+
 /// Collect passes whose last user is P
 void PMTopLevelManager::collectLastUses(std::vector<Pass *> &LastUses,
                                             Pass *P) {
-   for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
-          LUE = LastUser.end(); LUI != LUE; ++LUI)
-      if (LUI->second == P)
-        LastUses.push_back(LUI->first);
+   std::vector<Pass *>&LU = InvertedLU[P]; 
+   LastUses.insert(LastUses.end(), LU.begin(), LU.end());
 }
 
 /// Schedule pass P for execution. Make sure that passes required by
@@ -938,6 +944,9 @@ bool FunctionPassManagerImpl::run(Function &F) {
   dumpArguments();
   dumpPasses();
 
+  // Collect inverted map of LastUsers. This improves speed of
+  // collectLastUses().
+  TPM->collectInvertedLU();
   initializeAllAnalysisInfo();
   for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {  
     FPPassManager *FP = getContainedManager(Index);
@@ -1086,6 +1095,9 @@ bool PassManagerImpl::run(Module &M) {
   dumpArguments();
   dumpPasses();
 
+  // Collect inverted map of LastUsers. This improves speed of
+  // collectLastUses().
+  TPM->collectInvertedLU();
   initializeAllAnalysisInfo();
   for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {  
     MPPassManager *MP = getContainedManager(Index);