From d9d681d128902f0c0e555b9dc3763902af5eb686 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 12 Jan 2006 16:48:23 +0000 Subject: [PATCH] Patch #10 from Saem: "Extracts a few more methods, reduces some redundancy in the code at the same time." git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25248 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/PassManagerT.h | 84 +++++++++++++++------------------------ 1 file changed, 32 insertions(+), 52 deletions(-) diff --git a/lib/VMCore/PassManagerT.h b/lib/VMCore/PassManagerT.h index 1f96d63a2c0..de0fc46f7e4 100644 --- a/lib/VMCore/PassManagerT.h +++ b/lib/VMCore/PassManagerT.h @@ -472,33 +472,10 @@ private: E = RequiredSet.end(); I != E; ++I) markPassUsed(*I, P); // Mark *I as used by P - // Erase all analyses not in the preserved set... - if (!AnUsage.getPreservesAll()) { - const std::vector &PreservedSet = AnUsage.getPreservedSet(); - for (std::map::iterator I = CurrentAnalyses.begin(), - E = CurrentAnalyses.end(); I != E; ) { - if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) == - PreservedSet.end()) { // Analysis not preserved! - CurrentAnalyses.erase(I); // Remove from available analyses - I = CurrentAnalyses.begin(); - } else { - ++I; - } - } - } - - // Add this pass to the currently available set... - if (const PassInfo *PI = P->getPassInfo()) { - CurrentAnalyses[PI] = P; - - // This pass is the current implementation of all of the interfaces it - // implements as well. - // - const std::vector &II = PI->getInterfacesImplemented(); - for (unsigned i = 0, e = II.size(); i != e; ++i) - CurrentAnalyses[II[i]] = P; - } - + removeNonPreservedAnalyses(AnUsage); + + makeCurrentlyAvailable(P); + // For now assume that our results are never used... LastUseOf[P] = P; } @@ -632,30 +609,10 @@ private: // Erase all analyses not in the preserved set removeNonPreservedAnalyses(AnUsage); - // Add the current pass to the set of passes that have been run, and are - // thus available to users. - // - if (const PassInfo *PI = P->getPassInfo()) { - CurrentAnalyses[PI] = P; - - // This pass is the current implementation of all of the interfaces it - // implements as well. - // - const std::vector &II = PI->getInterfacesImplemented(); - for (unsigned i = 0, e = II.size(); i != e; ++i) - CurrentAnalyses[II[i]] = P; - } - - // Free memory for any passes that we are the last use of... - std::vector &DeadPass = LastUserOf[P]; - for (std::vector::iterator I = DeadPass.begin(),E = DeadPass.end(); - I != E; ++I) { - PMDebug::PrintPassInformation(getDepth()+1, "Freeing Pass", *I, M); - (*I)->releaseMemory(); - } + makeCurrentlyAvailable(P); - // remove dead passes from the CurrentAnalyses list... - removeDeadPasses(DeadPass); + // free memory and remove dead passes from the CurrentAnalyses list... + removeDeadPasses(P, M, LastUserOf); } return MadeChanges; @@ -707,7 +664,15 @@ private: } } - inline void removeDeadPasses(std::vector &DeadPass) { + inline void removeDeadPasses(Pass* P, UnitType *M, + std::map > &LastUserOf) { + std::vector &DeadPass = LastUserOf[P]; + for (std::vector::iterator I = DeadPass.begin(),E = DeadPass.end(); + I != E; ++I) { + PMDebug::PrintPassInformation(getDepth()+1, "Freeing Pass", *I, M); + (*I)->releaseMemory(); + } + for (std::map::iterator I = CurrentAnalyses.begin(); I != CurrentAnalyses.end(); ) { std::vector::iterator DPI = std::find(DeadPass.begin(), @@ -720,8 +685,23 @@ private: } } } + + inline void makeCurrentlyAvailable(Pass* P) { + if (const PassInfo *PI = P->getPassInfo()) { + CurrentAnalyses[PI] = P; + + // This pass is the current implementation of all of the interfaces it + // implements as well. + // + const std::vector &II = PI->getInterfacesImplemented(); + for (unsigned i = 0, e = II.size(); i != e; ++i) + CurrentAnalyses[II[i]] = P; + } + } }; + + //===----------------------------------------------------------------------===// // BasicBlockPassManager // @@ -859,7 +839,7 @@ public: }; //===----------------------------------------------------------------------===// -// PassManagerTraits Method Implementations +// PassManager Method Implementations // // BasicBlockPassManager Implementations -- 2.34.1