From 3f5d2b58b84cb12a9520dd33921ca556d539eb4d Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Thu, 7 Dec 2006 19:21:29 +0000 Subject: [PATCH] Add PMTopLevelManager. It is not used yet. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32314 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/PassManager.cpp | 76 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp index f46f4456b21..d4db1d14537 100644 --- a/lib/VMCore/PassManager.cpp +++ b/lib/VMCore/PassManager.cpp @@ -86,6 +86,82 @@ using namespace llvm; namespace llvm { +//===----------------------------------------------------------------------===// +// PMTopLevelManager +// +/// PMTopLevelManager manages LastUser info and collects common APIs used by +/// top level pass managers. +class PMTopLevelManager { + +public: + + inline std::vector::iterator passManagersBegin() { + return PassManagers.begin(); + } + + inline std::vector::iterator passManagersEnd() { + return PassManagers.end(); + } + + /// Schedule pass P for execution. Make sure that passes required by + /// P are run before P is run. Update analysis info maintained by + /// the manager. Remove dead passes. This is a recursive function. + void schedulePass(Pass *P, Pass *PM); + + /// This is implemented by top level pass manager and used by + /// schedulePass() to add analysis info passes that are not available. + virtual void addTopLevelPass(Pass *P) = 0; + + /// Set pass P as the last user of the given analysis passes. + void setLastUser(std::vector &AnalysisPasses, Pass *P); + + /// Collect passes whose last user is P + void collectLastUses(std::vector &LastUses, Pass *P); + + virtual ~PMTopLevelManager() { + PassManagers.clear(); + } + +private: + + /// Collection of pass managers + std::vector PassManagers; + + // Map to keep track of last user of the analysis pass. + // LastUser->second is the last user of Lastuser->first. + std::map LastUser; +}; + +/// Set pass P as the last user of the given analysis passes. +void PMTopLevelManager::setLastUser(std::vector &AnalysisPasses, + Pass *P) { + + for (std::vector::iterator I = AnalysisPasses.begin(), + E = AnalysisPasses.end(); I != E; ++I) { + Pass *AP = *I; + LastUser[AP] = P; + // If AP is the last user of other passes then make P last user of + // such passes. + for (std::map::iterator LUI = LastUser.begin(), + LUE = LastUser.end(); LUI != LUE; ++LUI) { + if (LUI->second == AP) + LastUser[LUI->first] = P; + } + } + +} + +/// Collect passes whose last user is P +void PMTopLevelManager::collectLastUses(std::vector &LastUses, + Pass *P) { + for (std::map::iterator LUI = LastUser.begin(), + LUE = LastUser.end(); LUI != LUE; ++LUI) + if (LUI->second == P) + LastUses.push_back(LUI->first); +} + + + /// PMDataManager provides the common place to manage the analysis data /// used by pass managers. class PMDataManager {