From 3b8a90686adb3d0adaa4389e7b7900570a235e03 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Mon, 11 Aug 2008 21:13:39 +0000 Subject: [PATCH] Keep track of analysis usage information for passes. Avoid invoking getAnalysisUsage() repeatedly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54650 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/PassManagers.h | 6 ++++ lib/VMCore/PassManager.cpp | 61 +++++++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/include/llvm/PassManagers.h b/include/llvm/PassManagers.h index 5d90a229202..a97f4f3e1a6 100644 --- a/include/llvm/PassManagers.h +++ b/include/llvm/PassManagers.h @@ -13,6 +13,7 @@ #include "llvm/PassManager.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/DenseMap.h" #include #include @@ -172,6 +173,9 @@ public: /// 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 @@ private: /// Immutable passes are managed by top level manager. std::vector ImmutablePasses; + + DenseMap AnUsageMap; }; diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp index fc3621a7345..d6d89f55c3f 100644 --- a/lib/VMCore/PassManager.cpp +++ b/lib/VMCore/PassManager.cpp @@ -421,6 +421,19 @@ void PMTopLevelManager::collectLastUses(SmallVector &LastUses, LastUses.push_back(LUI->first); } +AnalysisUsage *PMTopLevelManager::findAnalysisUsage(Pass *P) { + AnalysisUsage *AnUsage = NULL; + DenseMap::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 @@ void PMTopLevelManager::schedulePass(Pass *P) { 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 @@ PMTopLevelManager::~PMTopLevelManager() { for (std::vector::iterator I = ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I) delete *I; + + for (DenseMap::iterator DMI = AnUsageMap.begin(), + DME = AnUsageMap.end(); DMI != DME; ++DMI) { + AnalysisUsage *AU = DMI->second; + delete AU; + } + } //===----------------------------------------------------------------------===// @@ -578,13 +598,12 @@ void PMDataManager::recordAvailableAnalysis(Pass *P) { // 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::iterator I = HigherLevelAnalysis.begin(), E = HigherLevelAnalysis.end(); I != E; ++I) { Pass *P1 = *I; @@ -604,9 +623,8 @@ void PMDataManager::verifyPreservedAnalysis(Pass *P) { #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 @@ void PMDataManager::verifyDomInfo(Pass &P, Function &F) { /// 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::iterator I = AvailableAnalysis.begin(), E = AvailableAnalysis.end(); I != E; ) { std::map::iterator Info = I++; @@ -820,9 +837,8 @@ void PMDataManager::add(Pass *P, void PMDataManager::collectRequiredAnalysis(SmallVector&RP, SmallVector &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 @@ void PMDataManager::collectRequiredAnalysis(SmallVector&RP, 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 @@ void PMDataManager::collectRequiredAnalysis(SmallVector&RP, // 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.