From b899eed1bc0a64f96fa7aff8d7c6f999cf85bdfe Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Tue, 14 Nov 2006 01:59:59 +0000 Subject: [PATCH] Use std::map to map AnalysisID and Pass. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31720 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/PassManager.cpp | 43 +++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp index 25742f1be1a..90f3e948a82 100644 --- a/lib/VMCore/PassManager.cpp +++ b/lib/VMCore/PassManager.cpp @@ -15,7 +15,7 @@ #include "llvm/PassManager.h" #include "llvm/Module.h" #include -#include +#include using namespace llvm; @@ -32,9 +32,15 @@ public: /// manager. bool manageablePass(Pass *P); - /// Return true IFF AnalysisID AID is currently available. - bool isAnalysisAvailable(AnalysisID AID) { - return (AvailableAnalysis.count(AID) != 0); + Pass *getAnalysisPass(AnalysisID AID) const { + + std::map::const_iterator I = + AvailableAnalysis.find(AID); + + if (I != AvailableAnalysis.end()) + return NULL; + else + return I->second; } /// Augment RequiredAnalysis by adding analysis required by pass P. @@ -60,6 +66,13 @@ public: AvailableAnalysis.clear(); } + // All Required analyses should be available to the pass as it runs! Here + // we fill in the AnalysisImpls member of the pass so that it can + // successfully use the getAnalysis() method to retrieve the + // implementations it needs. + // + inline void initializeAnalysisImpl(Pass *P) { /* TODO : Implement */ } + inline std::vector::iterator passVectorBegin() { return PassVector.begin(); } @@ -79,7 +92,7 @@ private: // pass. If a pass requires an analysis which is not not available then // equired analysis pass is scheduled to run before the pass itself is // scheduled to run. - std::set AvailableAnalysis; + std::map AvailableAnalysis; // Collection of pass that are managed by this manager std::vector PassVector; @@ -242,9 +255,9 @@ void CommonPassManagerImpl::noteDownRequiredAnalysis(Pass *P) { /// Augement AvailableAnalysis by adding analysis made available by pass P. void CommonPassManagerImpl::noteDownAvailableAnalysis(Pass *P) { - + if (const PassInfo *PI = P->getPassInfo()) { - AvailableAnalysis.insert(PI); + AvailableAnalysis[PI] = P; //TODO This pass is the current implementation of all of the interfaces it //TODO implements as well. @@ -261,12 +274,12 @@ void CommonPassManagerImpl::removeNotPreservedAnalysis(Pass *P) { P->getAnalysisUsage(AnUsage); const std::vector &PreservedSet = AnUsage.getPreservedSet(); - for (std::set::iterator I = AvailableAnalysis.begin(), + for (std::map::iterator I = AvailableAnalysis.begin(), E = AvailableAnalysis.end(); I != E; ++I ) { - if (std::find(PreservedSet.begin(), PreservedSet.end(), *I) == + if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) == PreservedSet.end()) { // Remove this analysis - std::set::iterator J = I++; + std::map::iterator J = I++; AvailableAnalysis.erase(J); } } @@ -336,7 +349,7 @@ BasicBlockPassManager_New::runOnFunction(Function &F) { /// Return true IFF AnalysisID AID is currently available. bool BasicBlockPassManager_New::analysisCurrentlyAvailable(AnalysisID AID) { - return isAnalysisAvailable(AID); + return (getAnalysisPass(AID) != 0); } // FunctionPassManager_New implementation @@ -427,11 +440,11 @@ FunctionPassManagerImpl_New::runOnModule(Module &M) { /// Return true IFF AnalysisID AID is currently available. bool FunctionPassManagerImpl_New::analysisCurrentlyAvailable(AnalysisID AID) { - if (isAnalysisAvailable(AID)) + if (getAnalysisPass(AID) != 0) return true; if (activeBBPassManager && - activeBBPassManager->isAnalysisAvailable(AID)) + activeBBPassManager->getAnalysisPass(AID) != 0) return true; // TODO : Check inactive managers @@ -501,11 +514,11 @@ ModulePassManager_New::runOnModule(Module &M) { /// Return true IFF AnalysisID AID is currently available. bool ModulePassManager_New::analysisCurrentlyAvailable(AnalysisID AID) { - if (isAnalysisAvailable(AID)) + if (getAnalysisPass(AID) != 0) return true; if (activeFunctionPassManager && - activeFunctionPassManager->isAnalysisAvailable(AID)) + activeFunctionPassManager->getAnalysisPass(AID) != 0) return true; // TODO : Check inactive managers