diff --git a/llvm/include/llvm/Analysis/LoopPass.h b/llvm/include/llvm/Analysis/LoopPass.h index b3d4c6e89721..2fd14f2dad4a 100644 --- a/llvm/include/llvm/Analysis/LoopPass.h +++ b/llvm/include/llvm/Analysis/LoopPass.h @@ -37,6 +37,10 @@ class LoopPass : public Pass { return false; } + /// Assign pass manager to manager this pass + virtual void assignPassManager(PMStack &PMS, + PassManagerType PMT = PMT_LoopPassManager); + }; class LPPassManager : public FunctionPass, public PMDataManager { diff --git a/llvm/lib/Analysis/LoopPass.cpp b/llvm/lib/Analysis/LoopPass.cpp index dc5c5683fb21..425e46e6e0b7 100644 --- a/llvm/lib/Analysis/LoopPass.cpp +++ b/llvm/lib/Analysis/LoopPass.cpp @@ -143,3 +143,44 @@ bool LPPassManager::runOnFunction(Function &F) { } +//===----------------------------------------------------------------------===// +// LoopPass + +/// Assign pass manager to manage this pass. +void LoopPass::assignPassManager(PMStack &PMS, + PassManagerType PreferredType) { + // Find LPPassManager + while (!PMS.empty()) { + if (PMS.top()->getPassManagerType() > PMT_LoopPassManager) + PMS.pop(); + else; + break; + } + + LPPassManager *LPPM = dynamic_cast(PMS.top()); + + // Create new Loop Pass Manager if it does not exist. + if (!LPPM) { + + assert (!PMS.empty() && "Unable to create Loop Pass Manager"); + PMDataManager *PMD = PMS.top(); + + // [1] Create new Call Graph Pass Manager + LPPM = new LPPassManager(PMD->getDepth() + 1); + + // [2] Set up new manager's top level manager + PMTopLevelManager *TPM = PMD->getTopLevelManager(); + TPM->addIndirectPassManager(LPPM); + + // [3] Assign manager to manage this new manager. This may create + // and push new managers into PMS + Pass *P = dynamic_cast(LPPM); + P->assignPassManager(PMS); + + // [4] Push new manager into PMS + PMS.push(LPPM); + } + + LPPM->add(this); +} +