[llvm-commits] [llvm] r54650 - in /llvm/trunk: include/llvm/PassManagers.h lib/VMCore/PassManager.cpp
Devang Patel
dpatel at apple.com
Mon Aug 11 14:13:41 PDT 2008
Author: dpatel
Date: Mon Aug 11 16:13:39 2008
New Revision: 54650
URL: http://llvm.org/viewvc/llvm-project?rev=54650&view=rev
Log:
Keep track of analysis usage information for passes. Avoid invoking
getAnalysisUsage() repeatedly.
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=54650&r1=54649&r2=54650&view=diff
==============================================================================
--- llvm/trunk/include/llvm/PassManagers.h (original)
+++ llvm/trunk/include/llvm/PassManagers.h Mon Aug 11 16:13:39 2008
@@ -13,6 +13,7 @@
#include "llvm/PassManager.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/DenseMap.h"
#include <deque>
#include <map>
@@ -172,6 +173,9 @@
/// then return NULL.
Pass *findAnalysisPass(AnalysisID AID);
+ /// Find analysis usage information for the pass P.
+ AnalysisUsage *findAnalysisUsage(Pass *P);
+
explicit PMTopLevelManager(enum TopLevelManagerType t);
virtual ~PMTopLevelManager();
@@ -221,6 +225,8 @@
/// Immutable passes are managed by top level manager.
std::vector<ImmutablePass *> ImmutablePasses;
+
+ DenseMap<Pass *, AnalysisUsage *> AnUsageMap;
};
Modified: llvm/trunk/lib/VMCore/PassManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/PassManager.cpp?rev=54650&r1=54649&r2=54650&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/PassManager.cpp (original)
+++ llvm/trunk/lib/VMCore/PassManager.cpp Mon Aug 11 16:13:39 2008
@@ -421,6 +421,19 @@
LastUses.push_back(LUI->first);
}
+AnalysisUsage *PMTopLevelManager::findAnalysisUsage(Pass *P) {
+ AnalysisUsage *AnUsage = NULL;
+ DenseMap<Pass *, AnalysisUsage *>::iterator DMI = AnUsageMap.find(P);
+ if (DMI != AnUsageMap.end())
+ AnUsage = DMI->second;
+ else {
+ AnUsage = new AnalysisUsage();
+ P->getAnalysisUsage(*AnUsage);
+ AnUsageMap[P] = AnUsage;
+ }
+ return AnUsage;
+}
+
/// Schedule pass P for execution. Make sure that passes required by
/// P are run before P is run. Update analysis info maintained by
/// the manager. Remove dead passes. This is a recursive function.
@@ -439,9 +452,9 @@
P->getPassInfo()->isAnalysis() && findAnalysisPass(P->getPassInfo()))
return;
- AnalysisUsage AnUsage;
- P->getAnalysisUsage(AnUsage);
- const AnalysisUsage::VectorType &RequiredSet = AnUsage.getRequiredSet();
+ AnalysisUsage *AnUsage = findAnalysisUsage(P);
+
+ const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet();
for (AnalysisUsage::VectorType::const_iterator I = RequiredSet.begin(),
E = RequiredSet.end(); I != E; ++I) {
@@ -555,6 +568,13 @@
for (std::vector<ImmutablePass *>::iterator
I = ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I)
delete *I;
+
+ for (DenseMap<Pass *, AnalysisUsage *>::iterator DMI = AnUsageMap.begin(),
+ DME = AnUsageMap.end(); DMI != DME; ++DMI) {
+ AnalysisUsage *AU = DMI->second;
+ delete AU;
+ }
+
}
//===----------------------------------------------------------------------===//
@@ -578,13 +598,12 @@
// passes managed by this manager
bool PMDataManager::preserveHigherLevelAnalysis(Pass *P) {
- AnalysisUsage AnUsage;
- P->getAnalysisUsage(AnUsage);
+ AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
- if (AnUsage.getPreservesAll())
+ if (AnUsage->getPreservesAll())
return true;
- const AnalysisUsage::VectorType &PreservedSet = AnUsage.getPreservedSet();
+ const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
for (std::vector<Pass *>::iterator I = HigherLevelAnalysis.begin(),
E = HigherLevelAnalysis.end(); I != E; ++I) {
Pass *P1 = *I;
@@ -604,9 +623,8 @@
#ifdef NDEBUG
return;
#endif
- AnalysisUsage AnUsage;
- P->getAnalysisUsage(AnUsage);
- const AnalysisUsage::VectorType &PreservedSet = AnUsage.getPreservedSet();
+ AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
+ const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
// Verify preserved analysis
for (AnalysisUsage::VectorType::const_iterator I = PreservedSet.begin(),
@@ -659,12 +677,11 @@
/// Remove Analysis not preserved by Pass P
void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
- AnalysisUsage AnUsage;
- P->getAnalysisUsage(AnUsage);
- if (AnUsage.getPreservesAll())
+ AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
+ if (AnUsage->getPreservesAll())
return;
- const AnalysisUsage::VectorType &PreservedSet = AnUsage.getPreservedSet();
+ const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
E = AvailableAnalysis.end(); I != E; ) {
std::map<AnalysisID, Pass*>::iterator Info = I++;
@@ -820,9 +837,8 @@
void PMDataManager::collectRequiredAnalysis(SmallVector<Pass *, 8>&RP,
SmallVector<AnalysisID, 8> &RP_NotAvail,
Pass *P) {
- AnalysisUsage AnUsage;
- P->getAnalysisUsage(AnUsage);
- const AnalysisUsage::VectorType &RequiredSet = AnUsage.getRequiredSet();
+ AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
+ const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet();
for (AnalysisUsage::VectorType::const_iterator
I = RequiredSet.begin(), E = RequiredSet.end();
I != E; ++I) {
@@ -833,7 +849,7 @@
RP_NotAvail.push_back(AID);
}
- const AnalysisUsage::VectorType &IDs = AnUsage.getRequiredTransitiveSet();
+ const AnalysisUsage::VectorType &IDs = AnUsage->getRequiredTransitiveSet();
for (AnalysisUsage::VectorType::const_iterator I = IDs.begin(),
E = IDs.end(); I != E; ++I) {
AnalysisID AID = *I;
@@ -850,12 +866,11 @@
// implementations it needs.
//
void PMDataManager::initializeAnalysisImpl(Pass *P) {
- AnalysisUsage AnUsage;
- P->getAnalysisUsage(AnUsage);
-
+ AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
+
for (AnalysisUsage::VectorType::const_iterator
- I = AnUsage.getRequiredSet().begin(),
- E = AnUsage.getRequiredSet().end(); I != E; ++I) {
+ I = AnUsage->getRequiredSet().begin(),
+ E = AnUsage->getRequiredSet().end(); I != E; ++I) {
Pass *Impl = findAnalysisPass(*I, true);
if (Impl == 0)
// This may be analysis pass that is initialized on the fly.
More information about the llvm-commits
mailing list