From 7c34730fb96808d7116d83b8831164042a98a4b1 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 11 Oct 2010 23:19:01 +0000 Subject: [PATCH] Fix the pass manager's search order for immutable passes, and make it stop searching when it has found a match. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116262 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/PassManager.cpp | 41 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp index ab4d4e55c75..57d6b8c0deb 100644 --- a/lib/VMCore/PassManager.cpp +++ b/lib/VMCore/PassManager.cpp @@ -612,41 +612,40 @@ void PMTopLevelManager::schedulePass(Pass *P) { /// then return NULL. Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) { - Pass *P = NULL; // Check pass managers for (SmallVector::iterator I = PassManagers.begin(), - E = PassManagers.end(); P == NULL && I != E; ++I) { - PMDataManager *PMD = *I; - P = PMD->findAnalysisPass(AID, false); - } + E = PassManagers.end(); I != E; ++I) + if (Pass *P = (*I)->findAnalysisPass(AID, false)) + return P; // Check other pass managers for (SmallVector::iterator I = IndirectPassManagers.begin(), - E = IndirectPassManagers.end(); P == NULL && I != E; ++I) - P = (*I)->findAnalysisPass(AID, false); + E = IndirectPassManagers.end(); I != E; ++I) + if (Pass *P = (*I)->findAnalysisPass(AID, false)) + return P; - for (SmallVector::iterator I = ImmutablePasses.begin(), - E = ImmutablePasses.end(); P == NULL && I != E; ++I) { + // Check the immutable passes. Iterate in reverse order so that we find + // the most recently registered passes first. + for (SmallVector::reverse_iterator I = + ImmutablePasses.rbegin(), E = ImmutablePasses.rend(); I != E; ++I) { AnalysisID PI = (*I)->getPassID(); if (PI == AID) - P = *I; + return *I; // If Pass not found then check the interfaces implemented by Immutable Pass - if (!P) { - const PassInfo *PassInf = - PassRegistry::getPassRegistry()->getPassInfo(PI); - const std::vector &ImmPI = - PassInf->getInterfacesImplemented(); - for (std::vector::const_iterator II = ImmPI.begin(), - EE = ImmPI.end(); II != EE; ++II) { - if ((*II)->getTypeInfo() == AID) - P = *I; - } + const PassInfo *PassInf = + PassRegistry::getPassRegistry()->getPassInfo(PI); + const std::vector &ImmPI = + PassInf->getInterfacesImplemented(); + for (std::vector::const_iterator II = ImmPI.begin(), + EE = ImmPI.end(); II != EE; ++II) { + if ((*II)->getTypeInfo() == AID) + return *I; } } - return P; + return 0; } // Print passes managed by this top level manager.