diff options
author | Devang Patel <dpatel@apple.com> | 2006-12-08 22:30:11 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2006-12-08 22:30:11 +0000 |
commit | 69867b511c732a7fac7301977bd6e880e46439f1 (patch) | |
tree | 56878df0837fdb18a5e8cc52b0bcb8711f73edee /lib/VMCore/PassManager.cpp | |
parent | 0ec729ef2d0bf7a9563ac2f2666cff37afe8c257 (diff) |
Implement PMTopLevel::findAnalysisPass() and
PMDataManager::findAnalysisPass()
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32377 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/PassManager.cpp')
-rw-r--r-- | lib/VMCore/PassManager.cpp | 77 |
1 files changed, 71 insertions, 6 deletions
diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp index be9bff4d3d..d7684f07e7 100644 --- a/lib/VMCore/PassManager.cpp +++ b/lib/VMCore/PassManager.cpp @@ -118,6 +118,11 @@ public: /// Collect passes whose last user is P void collectLastUses(std::vector<Pass *> &LastUses, Pass *P); + /// Find the pass that implements Analysis AID. Search immutable + /// passes and all pass managers. If desired pass is not found + /// then return NULL. + Pass *findAnalysisPass(AnalysisID AID); + virtual ~PMTopLevelManager() { PassManagers.clear(); } @@ -187,7 +192,7 @@ void PMTopLevelManager::schedulePass(Pass *P, Pass *PM) { for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(), E = RequiredSet.end(); I != E; ++I) { - Pass *AnalysisPass = NULL; // FIXME PM->getAnalysisPass(*I, true); + Pass *AnalysisPass = findAnalysisPass(*I); if (!AnalysisPass) { // Schedule this analysis run first. AnalysisPass = (*I)->createPass(); @@ -199,6 +204,40 @@ void PMTopLevelManager::schedulePass(Pass *P, Pass *PM) { addTopLevelPass(P); } +/// Find the pass that implements Analysis AID. Search immutable +/// passes and all pass managers. If desired pass is not found +/// then return NULL. +Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) { + + Pass *P = NULL; + for (std::vector<ImmutablePass *>::iterator I = ImmutablePasses.begin(), + E = ImmutablePasses.end(); P == NULL && I != E; ++I) { + const PassInfo *PI = (*I)->getPassInfo(); + if (PI == AID) + P = *I; + + // If Pass not found then check the interfaces implemented by Immutable Pass + if (!P) { + const std::vector<const PassInfo*> &ImmPI = + PI->getInterfacesImplemented(); + for (unsigned Index = 0, End = ImmPI.size(); + P == NULL && Index != End; ++Index) + if (ImmPI[Index] == AID) + P = *I; + } + } + + if (P) + return P; + + // Check pass managers; + for (std::vector<Pass *>::iterator I = PassManagers.begin(), + E = PassManagers.end(); P == NULL && I != E; ++I) + P = NULL; // FIXME: (*I)->findAnalysisPass(AID, false /* Search downward */); + + return P; +} + //===----------------------------------------------------------------------===// // PMDataManager @@ -263,6 +302,10 @@ public: /// implementations it needs. void initializeAnalysisImpl(Pass *P); + /// Find the pass that implements Analysis AID. If desired pass is not found + /// then return NULL. + Pass *findAnalysisPass(AnalysisID AID, bool Direction); + inline std::vector<Pass *>::iterator passVectorBegin() { return PassVector.begin(); } @@ -596,7 +639,7 @@ void PMDataManager::collectRequiredAnalysisPasses(std::vector<Pass *> &RP, for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(), E = RequiredSet.end(); I != E; ++I) { - Pass *AnalysisPass = NULL; //FIXME findAnalysisPass(*I,true); + Pass *AnalysisPass = findAnalysisPass(*I, true); assert (AnalysisPass && "Analysis pass is not available"); RP.push_back(AnalysisPass); } @@ -614,13 +657,37 @@ void PMDataManager::initializeAnalysisImpl(Pass *P) { for (std::vector<const PassInfo *>::const_iterator I = AnUsage.getRequiredSet().begin(), E = AnUsage.getRequiredSet().end(); I != E; ++I) { - Pass *Impl = getAnalysisPass(*I); + Pass *Impl = findAnalysisPass(*I, true); if (Impl == 0) assert(0 && "Analysis used but not available!"); // TODO: P->AnalysisImpls.push_back(std::make_pair(*I, Impl)); } } +/// Find the pass that implements Analysis AID. If desired pass is not found +/// then return NULL. +Pass *PMDataManager::findAnalysisPass(AnalysisID AID, bool SearchParent) { + + // Check if AvailableAnalysis map has one entry. + std::map<AnalysisID, Pass*>::const_iterator I = AvailableAnalysis.find(AID); + + if (I != AvailableAnalysis.end()) + return I->second; + + // Search Parents through TopLevelManager + if (SearchParent) + return TPM->findAnalysisPass(AID); + + // FIXME : This is expensive and requires. Need to check only managers not all passes. + // One solution is to collect managers in advance at TPM level. + Pass *P = NULL; + for(std::vector<Pass *>::iterator I = passVectorBegin(), + E = passVectorEnd(); P == NULL && I!= E; ++I ) + P = NULL; // FIXME : P = (*I)->getResolver()->getAnalysisToUpdate(AID, false /* Do not search parents again */); + + return P; +} + //===----------------------------------------------------------------------===// // BasicBlockPassManager_New implementation @@ -912,7 +979,6 @@ inline bool FunctionPassManagerImpl_New::doFinalization(Module &M) { Changed |= FP->doFinalization(M); } - return Changed; } @@ -928,8 +994,7 @@ ModulePassManager_New::addPass(Pass *P) { // If P is FunctionPass then use function pass maanager. if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P)) { - if (!activeFunctionPassManager - || !activeFunctionPassManager->addPass(P)) { + if (!activeFunctionPassManager || !activeFunctionPassManager->addPass(P)) { // If active manager exists then clear its analysis info. if (activeFunctionPassManager) |