[llvm-commits] [llvm] r54662 - in /llvm/trunk: include/llvm/PassManagers.h lib/VMCore/PassManager.cpp
Devang Patel
dpatel at apple.com
Mon Aug 11 17:26:16 PDT 2008
Author: dpatel
Date: Mon Aug 11 19:26:16 2008
New Revision: 54662
URL: http://llvm.org/viewvc/llvm-project?rev=54662&view=rev
Log:
Use DenseMap to keep track of last users.
Use inversed map for faster queries.
Modified:
llvm/trunk/include/llvm/PassManagers.h
llvm/trunk/lib/VMCore/PassManager.cpp
Modified: llvm/trunk/include/llvm/PassManagers.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/PassManagers.h?rev=54662&r1=54661&r2=54662&view=diff
==============================================================================
--- llvm/trunk/include/llvm/PassManagers.h (original)
+++ llvm/trunk/include/llvm/PassManagers.h Mon Aug 11 19:26:16 2008
@@ -13,6 +13,7 @@
#include "llvm/PassManager.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/DenseMap.h"
#include <deque>
#include <map>
@@ -221,7 +222,12 @@
// 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;
+ 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.
std::vector<ImmutablePass *> ImmutablePasses;
Modified: llvm/trunk/lib/VMCore/PassManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/PassManager.cpp?rev=54662&r1=54661&r2=54662&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/PassManager.cpp (original)
+++ llvm/trunk/lib/VMCore/PassManager.cpp Mon Aug 11 19:26:16 2008
@@ -404,9 +404,11 @@
// If AP is the last user of other passes then make P last user of
// 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) {
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 @@
/// Collect passes whose last user is P
void PMTopLevelManager::collectLastUses(SmallVector<Pass *, 12> &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);
+ Pass *P) {
+ DenseMap<Pass *, SmallPtrSet<Pass *, 8> >::iterator DMI =
+ InversedLastUser.find(P);
+ if (DMI == InversedLastUser.end())
+ 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) {
@@ -557,6 +566,19 @@
for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
E = IndirectPassManagers.end(); I != E; ++I)
(*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
More information about the llvm-commits
mailing list