From df1a10ece6a75f230d98c6fb001349eede90387a Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Tue, 14 Nov 2006 03:05:08 +0000 Subject: [PATCH] Implement removeDeadPasses(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31722 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/PassManager.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp index 2332fed5de5..0f52b2d674e 100644 --- a/lib/VMCore/PassManager.cpp +++ b/lib/VMCore/PassManager.cpp @@ -53,7 +53,7 @@ public: void removeNotPreservedAnalysis(Pass *P); /// Remove dead passes - void removeDeadPasses() { /* TODO : Implement */ } + void removeDeadPasses(Pass *P); /// Add pass P into the PassVector. Update RequiredAnalysis and /// AvailableAnalysis appropriately if ProcessAnalysis is true. @@ -292,6 +292,25 @@ void CommonPassManagerImpl::removeNotPreservedAnalysis(Pass *P) { } } +/// Remove analysis passes that are not used any longer +void CommonPassManagerImpl::removeDeadPasses(Pass *P) { + + for (std::map::iterator I = LastUser.begin(), + E = LastUser.end(); I !=E; ++I) { + if (I->second == P) { + Pass *deadPass = I->first; + deadPass->releaseMemory(); + + std::map::iterator Pos = + AvailableAnalysis.find(deadPass->getPassInfo()); + + assert (Pos != AvailableAnalysis.end() && + "Pass is not available"); + AvailableAnalysis.erase(Pos); + } + } +} + /// Add pass P into the PassVector. Update RequiredAnalysis and /// AvailableAnalysis appropriately if ProcessAnalysis is true. void CommonPassManagerImpl::addPassToManager (Pass *P, @@ -349,7 +368,7 @@ BasicBlockPassManager_New::runOnFunction(Function &F) { BasicBlockPass *BP = dynamic_cast(P); Changed |= BP->runOnBasicBlock(*I); removeNotPreservedAnalysis(P); - removeDeadPasses(); + removeDeadPasses(P); } return Changed; } @@ -439,7 +458,7 @@ FunctionPassManagerImpl_New::runOnModule(Module &M) { FunctionPass *FP = dynamic_cast(P); Changed |= FP->runOnFunction(*I); removeNotPreservedAnalysis(P); - removeDeadPasses(); + removeDeadPasses(P); } return Changed; } @@ -514,7 +533,7 @@ ModulePassManager_New::runOnModule(Module &M) { ModulePass *MP = dynamic_cast(P); Changed |= MP->runOnModule(M); removeNotPreservedAnalysis(P); - removeDeadPasses(); + removeDeadPasses(P); } return Changed; }