From 1f8200b404eafff5d9bf498be8143deebbfe39ec Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Tue, 23 Jan 2007 21:52:35 +0000 Subject: [PATCH] Add CallGraphSCCPass::assignPassManager(). This enables CalLGraphPassManager. llvm-svn: 33466 --- llvm/include/llvm/CallGraphSCCPass.h | 4 +++ llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp | 38 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/llvm/include/llvm/CallGraphSCCPass.h b/llvm/include/llvm/CallGraphSCCPass.h index c3307385b079..f64ece41b6d7 100644 --- a/llvm/include/llvm/CallGraphSCCPass.h +++ b/llvm/include/llvm/CallGraphSCCPass.h @@ -27,6 +27,7 @@ namespace llvm { class CallGraphNode; class CallGraph; +class PMStack; struct CallGraphSCCPass : public ModulePass { @@ -54,6 +55,9 @@ struct CallGraphSCCPass : public ModulePass { /// virtual bool runOnModule(Module &M); + /// Assign pass manager to manager this pass + virtual void assignPassManager(PMStack &PMS, + PassManagerType PMT = PMT_CallGraphPassManager); /// getAnalysisUsage - For this class, we declare that we require and preserve /// the call graph. If the derived class implements this method, it should diff --git a/llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp b/llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp index 7ec7a87d2ca5..4de2e56fc7a3 100644 --- a/llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp +++ b/llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp @@ -144,6 +144,44 @@ bool CGPassManager::doFinalization(CallGraph &CG) { return Changed; } +/// Assign pass manager to manager this pass +void CallGraphSCCPass::assignPassManager(PMStack &PMS, + PassManagerType PreferredType) { + // Find CGPassManager + while (!PMS.empty()) { + if (PMS.top()->getPassManagerType() > PMT_CallGraphPassManager) + PMS.pop(); + else; + break; + } + + CGPassManager *CGP = dynamic_cast(PMS.top()); + + // Create new Call Graph SCC Pass Manager if it does not exist. + if (!CGP) { + + assert (!PMS.empty() && "Unable to create Call Graph Pass Manager"); + PMDataManager *PMD = PMS.top(); + + // [1] Create new Call Graph Pass Manager + CGP = new CGPassManager(PMD->getDepth() + 1); + + // [2] Set up new manager's top level manager + PMTopLevelManager *TPM = PMD->getTopLevelManager(); + TPM->addIndirectPassManager(CGP); + + // [3] Assign manager to manage this new manager. This may create + // and push new managers into PMS + Pass *P = dynamic_cast(CGP); + P->assignPassManager(PMS); + + // [4] Push new manager into PMS + PMS.push(CGP); + } + + CGP->add(this); +} + /// getAnalysisUsage - For this class, we declare that we require and preserve /// the call graph. If the derived class implements this method, it should /// always explicitly call the implementation here.