Use DenseMap to keep track of last users.

Use inversed map for faster queries.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54662 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel 2008-08-12 00:26:16 +00:00
parent 50dd1d0280
commit 721e59cfb2
2 changed files with 35 additions and 7 deletions

View File

@ -13,6 +13,7 @@
#include "llvm/PassManager.h" #include "llvm/PassManager.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include <deque> #include <deque>
#include <map> #include <map>
@ -221,7 +222,12 @@ private:
// Map to keep track of last user of the analysis pass. // Map to keep track of last user of the analysis pass.
// LastUser->second is the last user of Lastuser->first. // LastUser->second is the last user of Lastuser->first.
std::map<Pass *, Pass *> LastUser; DenseMap<Pass *, Pass *> 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<Pass *, SmallPtrSet<Pass *, 8> > InversedLastUser;
/// Immutable passes are managed by top level manager. /// Immutable passes are managed by top level manager.
std::vector<ImmutablePass *> ImmutablePasses; std::vector<ImmutablePass *> ImmutablePasses;

View File

@ -404,9 +404,11 @@ void PMTopLevelManager::setLastUser(SmallVector<Pass *, 12> &AnalysisPasses,
// If AP is the last user of other passes then make P last user of // If AP is the last user of other passes then make P last user of
// such passes. // such passes.
for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(), for (DenseMap<Pass *, Pass *>::iterator LUI = LastUser.begin(),
LUE = LastUser.end(); LUI != LUE; ++LUI) { LUE = LastUser.end(); LUI != LUE; ++LUI) {
if (LUI->second == AP) if (LUI->second == AP)
// DenseMap iterator is not invalidated here because
// this is just updating exisitng entry.
LastUser[LUI->first] = P; LastUser[LUI->first] = P;
} }
} }
@ -414,11 +416,18 @@ void PMTopLevelManager::setLastUser(SmallVector<Pass *, 12> &AnalysisPasses,
/// Collect passes whose last user is P /// Collect passes whose last user is P
void PMTopLevelManager::collectLastUses(SmallVector<Pass *, 12> &LastUses, void PMTopLevelManager::collectLastUses(SmallVector<Pass *, 12> &LastUses,
Pass *P) { Pass *P) {
for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(), DenseMap<Pass *, SmallPtrSet<Pass *, 8> >::iterator DMI =
LUE = LastUser.end(); LUI != LUE; ++LUI) InversedLastUser.find(P);
if (LUI->second == P) if (DMI == InversedLastUser.end())
LastUses.push_back(LUI->first); return;
SmallPtrSet<Pass *, 8> &LU = DMI->second;
for (SmallPtrSet<Pass *, 8>::iterator I = LU.begin(),
E = LU.end(); I != E; ++I) {
LastUses.push_back(*I);
}
} }
AnalysisUsage *PMTopLevelManager::findAnalysisUsage(Pass *P) { AnalysisUsage *PMTopLevelManager::findAnalysisUsage(Pass *P) {
@ -557,6 +566,19 @@ void PMTopLevelManager::initializeAllAnalysisInfo() {
for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(), for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
E = IndirectPassManagers.end(); I != E; ++I) E = IndirectPassManagers.end(); I != E; ++I)
(*I)->initializeAnalysisInfo(); (*I)->initializeAnalysisInfo();
for(DenseMap<Pass *, Pass *>::iterator DMI = LastUser.begin(),
DME = LastUser.end(); DMI != DME; ++DMI) {
DenseMap<Pass *, SmallPtrSet<Pass *, 8> >::iterator InvDMI =
InversedLastUser.find(DMI->second);
if (InvDMI != InversedLastUser.end()) {
SmallPtrSet<Pass *, 8> &L = InvDMI->second;
L.insert(DMI->first);
} else {
SmallPtrSet<Pass *, 8> L; L.insert(DMI->first);
InversedLastUser[DMI->second] = L;
}
}
} }
/// Destructor /// Destructor