From 531f01f878915fc51ccf5e1194a2dc8d73c207cd Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Tue, 16 Jan 2007 19:46:09 +0000 Subject: [PATCH] Setup pass manager before scheduling required analysis. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33262 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Pass.h | 11 +++- lib/VMCore/PassManager.cpp | 112 ++++++++++++++++++++----------------- 2 files changed, 71 insertions(+), 52 deletions(-) diff --git a/include/llvm/Pass.h b/include/llvm/Pass.h index 9951a988bf0..fcdc66fcbad 100644 --- a/include/llvm/Pass.h +++ b/include/llvm/Pass.h @@ -108,6 +108,8 @@ public: void dump() const; // dump - call print(std::cerr, 0); virtual void assignPassManager(PMStack &PMS) {} + virtual void setupPassManager(PMStack &PMS) {} + // Access AnalysisResolver inline void setResolver(AnalysisResolver *AR) { Resolver = AR; } inline AnalysisResolver *getResolver() { return Resolver; } @@ -201,6 +203,7 @@ public: virtual bool runPass(BasicBlock&) { return false; } virtual void assignPassManager(PMStack &PMS); + // Force out-of-line virtual method. virtual ~ModulePass(); }; @@ -267,6 +270,7 @@ public: bool run(Function &F); virtual void assignPassManager(PMStack &PMS); + virtual void setupPassManager(PMStack &PMS); }; @@ -321,6 +325,7 @@ public: virtual bool runPass(BasicBlock &BB); virtual void assignPassManager(PMStack &PMS); + virtual void setupPassManager(PMStack &PMS); }; /// Different types of internal pass managers. External pass managers @@ -337,8 +342,10 @@ enum PassManagerType { /// PMStack /// Top level pass manager (see PasManager.cpp) maintains active Pass Managers -/// using PMStack. Each Pass implements assignPassManager() to connect itself -/// with appropriate manager. assignPassManager() walks PMStack to find +/// using PMStack. Each Pass implements setupPassManager() and +/// assignPassManager() to connect itself with appropriate manager. +/// setupPassManager() creates new pass manager if required before adding +/// required analysis passes. assignPassManager() walks PMStack to find /// suitable manager. /// /// PMStack is just a wrapper around standard deque that overrides pop() and diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp index 1e3b48ee686..50364e9c71d 100644 --- a/lib/VMCore/PassManager.cpp +++ b/lib/VMCore/PassManager.cpp @@ -366,8 +366,7 @@ void PMTopLevelManager::collectLastUses(std::vector &LastUses, /// the manager. Remove dead passes. This is a recursive function. void PMTopLevelManager::schedulePass(Pass *P) { - // TODO : Allocate function manager for this pass, other wise required set - // may be inserted into previous function manager + P->setupPassManager(activeStack); AnalysisUsage AnUsage; P->getAnalysisUsage(AnUsage); @@ -1218,47 +1217,55 @@ void ModulePass::assignPassManager(PMStack &PMS) { MPP->add(this); } -/// Find appropriate Function Pass Manager or Call Graph Pass Manager -/// in the PM Stack and add self into that manager. -void FunctionPass::assignPassManager(PMStack &PMS) { +/// Setup Pass Manager in advance before checking availability of +/// required analysis passes. +void FunctionPass::setupPassManager(PMStack &PMS) { // Find Module Pass Manager (TODO : Or Call Graph Pass Manager) while(!PMS.empty()) { if (PMS.top()->getPassManagerType() > PMT_FunctionPassManager) PMS.pop(); else - break; + break; } - FPPassManager *FPP = dynamic_cast(PMS.top()); - - // Create new Function Pass Manager - if (!FPP) { - assert(!PMS.empty() && "Unable to create Function Pass Manager"); - PMDataManager *PMD = PMS.top(); - // [1] Create new Function Pass Manager - FPP = new FPPassManager(PMD->getDepth() + 1); + assert(!PMS.empty() && "Unable to create Function Pass Manager"); - // [2] Set up new manager's top level manager - PMTopLevelManager *TPM = PMD->getTopLevelManager(); - TPM->addIndirectPassManager(FPP); + if (PMS.top()->getPassManagerType() == PMT_FunctionPassManager + || PMS.top()->getPassManagerType() == PMT_CallGraphPassManager) + return; + + PMDataManager *PMD = PMS.top(); + + // [1] Create new Function Pass Manager + FPPassManager *FPP = new FPPassManager(PMD->getDepth() + 1); + + // [2] Set up new manager's top level manager + PMTopLevelManager *TPM = PMD->getTopLevelManager(); + TPM->addIndirectPassManager(FPP); + + // [3] Assign manager to manage this new manager. This may create + // and push new managers into PMS + Pass *P = dynamic_cast(FPP); + P->assignPassManager(PMS); + + // [4] Push new manager into PMS + PMS.push(FPP); +} - // [3] Assign manager to manage this new manager. This may create - // and push new managers into PMS - Pass *P = dynamic_cast(FPP); - P->assignPassManager(PMS); +/// Find appropriate Function Pass Manager or Call Graph Pass Manager +/// in the PM Stack and add self into that manager. +void FunctionPass::assignPassManager(PMStack &PMS) { - // [4] Push new manager into PMS - PMS.push(FPP); - } + PMDataManager *PMD = dynamic_cast(PMS.top()); + assert(PMD && "Unable to assign Pass Manager"); - // Assign FPP as the manager of this pass. - FPP->add(this); + PMD->add(this); } -/// Find appropriate Basic Pass Manager or Call Graph Pass Manager -/// in the PM Stack and add self into that manager. -void BasicBlockPass::assignPassManager(PMStack &PMS) { +/// Setup Pass Manager in advance before checking availability of +/// required analysis passes. +void BasicBlockPass::setupPassManager(PMStack &PMS) { BBPassManager *BBP = NULL; @@ -1268,32 +1275,37 @@ void BasicBlockPass::assignPassManager(PMStack &PMS) { BBP = dynamic_cast(PMS.top()); } - // If leaf manager is not Basic Block Pass manager then create new - // basic Block Pass manager. - - if (!BBP) { - assert(!PMS.empty() && "Unable to create BasicBlock Pass Manager"); - PMDataManager *PMD = PMS.top(); - - // [1] Create new Basic Block Manager - BBP = new BBPassManager(PMD->getDepth() + 1); - - // [2] Set up new manager's top level manager - // Basic Block Pass Manager does not live by itself - PMTopLevelManager *TPM = PMD->getTopLevelManager(); - TPM->addIndirectPassManager(BBP); + if (BBP) + return; + assert(!PMS.empty() && "Unable to create BasicBlock Pass Manager"); + PMDataManager *PMD = PMS.top(); + + // [1] Create new Basic Block Manager + BBP = new BBPassManager(PMD->getDepth() + 1); + + // [2] Set up new manager's top level manager + // Basic Block Pass Manager does not live by itself + PMTopLevelManager *TPM = PMD->getTopLevelManager(); + TPM->addIndirectPassManager(BBP); + // [3] Assign manager to manage this new manager. This may create // and push new managers into PMS - Pass *P = dynamic_cast(BBP); - P->assignPassManager(PMS); + Pass *P = dynamic_cast(BBP); + P->assignPassManager(PMS); + + // [4] Push new manager into PMS + PMS.push(BBP); +} - // [4] Push new manager into PMS - PMS.push(BBP); - } +/// Find appropriate Basic Pass Manager or Call Graph Pass Manager +/// in the PM Stack and add self into that manager. +void BasicBlockPass::assignPassManager(PMStack &PMS) { + + PMDataManager *PMD = dynamic_cast(PMS.top()); + assert(PMD && "Unable to assign Pass Manager"); - // Assign BBP as the manager of this pass. - BBP->add(this); + PMD->add(this); } -- 2.34.1