diff --git a/llvm/include/llvm/PassManagers.h b/llvm/include/llvm/PassManagers.h index a97f4f3e1a6b..ff06024ed47e 100644 --- a/llvm/include/llvm/PassManagers.h +++ b/llvm/include/llvm/PassManagers.h @@ -13,6 +13,7 @@ #include "llvm/PassManager.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/DenseMap.h" #include #include @@ -221,7 +222,12 @@ private: // Map to keep track of last user of the analysis pass. // LastUser->second is the last user of Lastuser->first. - std::map LastUser; + DenseMap LastUser; + + // Map to keep track of passes that are last used by a pass. + // This inverse map is initialized at PM->run() based on + // LastUser map. + DenseMap > InversedLastUser; /// Immutable passes are managed by top level manager. std::vector ImmutablePasses; diff --git a/llvm/lib/VMCore/PassManager.cpp b/llvm/lib/VMCore/PassManager.cpp index d6d89f55c3f2..ed0dde03a187 100644 --- a/llvm/lib/VMCore/PassManager.cpp +++ b/llvm/lib/VMCore/PassManager.cpp @@ -404,9 +404,11 @@ void PMTopLevelManager::setLastUser(SmallVector &AnalysisPasses, // If AP is the last user of other passes then make P last user of // such passes. - for (std::map::iterator LUI = LastUser.begin(), + for (DenseMap::iterator LUI = LastUser.begin(), LUE = LastUser.end(); LUI != LUE; ++LUI) { if (LUI->second == AP) + // DenseMap iterator is not invalidated here because + // this is just updating exisitng entry. LastUser[LUI->first] = P; } } @@ -414,11 +416,18 @@ void PMTopLevelManager::setLastUser(SmallVector &AnalysisPasses, /// Collect passes whose last user is P void PMTopLevelManager::collectLastUses(SmallVector &LastUses, - Pass *P) { - for (std::map::iterator LUI = LastUser.begin(), - LUE = LastUser.end(); LUI != LUE; ++LUI) - if (LUI->second == P) - LastUses.push_back(LUI->first); + Pass *P) { + DenseMap >::iterator DMI = + InversedLastUser.find(P); + if (DMI == InversedLastUser.end()) + return; + + SmallPtrSet &LU = DMI->second; + for (SmallPtrSet::iterator I = LU.begin(), + E = LU.end(); I != E; ++I) { + LastUses.push_back(*I); + } + } AnalysisUsage *PMTopLevelManager::findAnalysisUsage(Pass *P) { @@ -557,6 +566,19 @@ void PMTopLevelManager::initializeAllAnalysisInfo() { for (std::vector::iterator I = IndirectPassManagers.begin(), E = IndirectPassManagers.end(); I != E; ++I) (*I)->initializeAnalysisInfo(); + + for(DenseMap::iterator DMI = LastUser.begin(), + DME = LastUser.end(); DMI != DME; ++DMI) { + DenseMap >::iterator InvDMI = + InversedLastUser.find(DMI->second); + if (InvDMI != InversedLastUser.end()) { + SmallPtrSet &L = InvDMI->second; + L.insert(DMI->first); + } else { + SmallPtrSet L; L.insert(DMI->first); + InversedLastUser[DMI->second] = L; + } + } } /// Destructor