Add #ifdef switch toggle between old and new pass manager. However,

continue to use old pass manager at the moment. To use new manager
remove #define USE_OLD_PASSMANAGER 1 from Pass.h


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32525 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel 2006-12-13 02:36:01 +00:00
parent 21c362d324
commit 3162691f69
5 changed files with 118 additions and 50 deletions

View File

@ -36,6 +36,8 @@
#include <typeinfo> #include <typeinfo>
#include <cassert> #include <cassert>
#define USE_OLD_PASSMANAGER 1
namespace llvm { namespace llvm {
class Value; class Value;
@ -203,7 +205,9 @@ public:
virtual bool runPass(Module &M) { return runOnModule(M); } virtual bool runPass(Module &M) { return runOnModule(M); }
virtual bool runPass(BasicBlock&) { return false; } virtual bool runPass(BasicBlock&) { return false; }
#ifdef USE_OLD_PASSMANAGER
virtual void addToPassManager(ModulePassManager *PM, AnalysisUsage &AU); virtual void addToPassManager(ModulePassManager *PM, AnalysisUsage &AU);
#endif
}; };
@ -226,10 +230,12 @@ public:
/// ///
virtual bool runOnModule(Module &M) { return false; } virtual bool runOnModule(Module &M) { return false; }
#ifdef USE_OLD_PASSMANAGER
private: private:
template<typename Trait> friend class PassManagerT; template<typename Trait> friend class PassManagerT;
friend class ModulePassManager; friend class ModulePassManager;
virtual void addToPassManager(ModulePassManager *PM, AnalysisUsage &AU); virtual void addToPassManager(ModulePassManager *PM, AnalysisUsage &AU);
#endif
}; };
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -269,6 +275,7 @@ public:
/// ///
bool run(Function &F); bool run(Function &F);
#ifdef USE_OLD_PASSMANAGER
protected: protected:
template<typename Trait> friend class PassManagerT; template<typename Trait> friend class PassManagerT;
friend class ModulePassManager; friend class ModulePassManager;
@ -276,6 +283,7 @@ protected:
friend class BasicBlockPassManager; friend class BasicBlockPassManager;
virtual void addToPassManager(ModulePassManager *PM, AnalysisUsage &AU); virtual void addToPassManager(ModulePassManager *PM, AnalysisUsage &AU);
virtual void addToPassManager(FunctionPassManagerT *PM, AnalysisUsage &AU); virtual void addToPassManager(FunctionPassManagerT *PM, AnalysisUsage &AU);
#endif
}; };
@ -329,6 +337,7 @@ public:
virtual bool runPass(Module &M) { return false; } virtual bool runPass(Module &M) { return false; }
virtual bool runPass(BasicBlock &BB); virtual bool runPass(BasicBlock &BB);
#ifdef USE_OLD_PASSMANAGER
private: private:
template<typename Trait> friend class PassManagerT; template<typename Trait> friend class PassManagerT;
friend class FunctionPassManagerT; friend class FunctionPassManagerT;
@ -338,6 +347,7 @@ private:
} }
virtual void addToPassManager(FunctionPassManagerT *PM, AnalysisUsage &AU); virtual void addToPassManager(FunctionPassManagerT *PM, AnalysisUsage &AU);
virtual void addToPassManager(BasicBlockPassManager *PM,AnalysisUsage &AU); virtual void addToPassManager(BasicBlockPassManager *PM,AnalysisUsage &AU);
#endif
}; };
/// If the user specifies the -time-passes argument on an LLVM tool command line /// If the user specifies the -time-passes argument on an LLVM tool command line

View File

@ -189,10 +189,19 @@ protected:
/// ///
template<typename AnalysisType> template<typename AnalysisType>
AnalysisType *Pass::getAnalysisToUpdate() const { AnalysisType *Pass::getAnalysisToUpdate() const {
#ifdef USE_OLD_PASSMANAGER
assert(Resolver && "Pass not resident in a PassManager object!"); assert(Resolver && "Pass not resident in a PassManager object!");
#else
assert(Resolver_New && "Pass not resident in a PassManager object!");
#endif
const PassInfo *PI = getClassPassInfo<AnalysisType>(); const PassInfo *PI = getClassPassInfo<AnalysisType>();
if (PI == 0) return 0; if (PI == 0) return 0;
#ifdef USE_OLD_PASSMANAGER
return dynamic_cast<AnalysisType*>(Resolver->getAnalysisToUpdate(PI)); return dynamic_cast<AnalysisType*>(Resolver->getAnalysisToUpdate(PI));
#else
return dynamic_cast<AnalysisType*>
(Resolver_New->getAnalysisToUpdate(PI, true));
#endif
} }
/// getAnalysis<AnalysisType>() - This function is used by subclasses to get /// getAnalysis<AnalysisType>() - This function is used by subclasses to get
@ -201,15 +210,20 @@ AnalysisType *Pass::getAnalysisToUpdate() const {
/// ///
template<typename AnalysisType> template<typename AnalysisType>
AnalysisType &Pass::getAnalysis() const { AnalysisType &Pass::getAnalysis() const {
#ifdef USE_OLD_PASSMANAGER
assert(Resolver && "Pass has not been inserted into a PassManager object!"); assert(Resolver && "Pass has not been inserted into a PassManager object!");
#else
assert(Resolver_New && "Pass has not been inserted into a PassManager object!");
#endif
const PassInfo *PI = getClassPassInfo<AnalysisType>(); const PassInfo *PI = getClassPassInfo<AnalysisType>();
return getAnalysisID<AnalysisType>(PI); return getAnalysisID<AnalysisType>(PI);
} }
template<typename AnalysisType> template<typename AnalysisType>
AnalysisType &Pass::getAnalysisID(const PassInfo *PI) const { AnalysisType &Pass::getAnalysisID(const PassInfo *PI) const {
assert(Resolver && "Pass has not been inserted into a PassManager object!");
assert(PI && "getAnalysis for unregistered pass!"); assert(PI && "getAnalysis for unregistered pass!");
#ifdef USE_OLD_PASSMANAGER
assert(Resolver && "Pass has not been inserted into a PassManager object!");
// PI *must* appear in AnalysisImpls. Because the number of passes used // PI *must* appear in AnalysisImpls. Because the number of passes used
// should be a small number, we just do a linear search over a (dense) // should be a small number, we just do a linear search over a (dense)
@ -224,7 +238,17 @@ AnalysisType &Pass::getAnalysisID(const PassInfo *PI) const {
break; break;
} }
} }
#else
assert(Resolver_New && "Pass has not been inserted into a PassManager object!");
// PI *must* appear in AnalysisImpls. Because the number of passes used
// should be a small number, we just do a linear search over a (dense)
// vector.
Pass *ResultPass = Resolver_New->findImplPass(PI);
assert (ResultPass &&
"getAnalysis*() called on an analysis that was not "
"'required' by pass!");
#endif
// Because the AnalysisType may not be a subclass of pass (for // Because the AnalysisType may not be a subclass of pass (for
// AnalysisGroups), we must use dynamic_cast here to potentially adjust the // AnalysisGroups), we must use dynamic_cast here to potentially adjust the
// return pointer (because the class may multiply inherit, once from pass, // return pointer (because the class may multiply inherit, once from pass,

View File

@ -25,6 +25,9 @@ class Pass;
class ModulePass; class ModulePass;
class Module; class Module;
class ModuleProvider; class ModuleProvider;
#ifdef USE_OLD_PASSMANAGER
class ModulePassManager; class ModulePassManager;
class FunctionPassManagerT; class FunctionPassManagerT;
class BasicBlockPassManager; class BasicBlockPassManager;
@ -87,17 +90,19 @@ public:
bool doFinalization(); bool doFinalization();
}; };
class ModulePassManager_New; #else
class ModulePassManager;
class PassManagerImpl_New; class PassManagerImpl_New;
class FunctionPassManagerImpl_New; class FunctionPassManagerImpl_New;
/// PassManager_New manages ModulePassManagers /// PassManager manages ModulePassManagers
class PassManager_New { class PassManager {
public: public:
PassManager_New(); PassManager();
~PassManager_New(); ~PassManager();
/// add - Add a pass to the queue of passes to run. This passes ownership of /// add - Add a pass to the queue of passes to run. This passes ownership of
/// the Pass to the PassManager. When the PassManager is destroyed, the pass /// the Pass to the PassManager. When the PassManager is destroyed, the pass
@ -111,18 +116,18 @@ public:
private: private:
/// PassManagerImpl_New is the actual class. PassManager_New is just the /// PassManagerImpl_New is the actual class. PassManager is just the
/// wraper to publish simple pass manager interface /// wraper to publish simple pass manager interface
PassManagerImpl_New *PM; PassManagerImpl_New *PM;
}; };
/// FunctionPassManager_New manages FunctionPasses and BasicBlockPassManagers. /// FunctionPassManager manages FunctionPasses and BasicBlockPassManagers.
class FunctionPassManager_New { class FunctionPassManager {
public: public:
FunctionPassManager_New(ModuleProvider *P); FunctionPassManager(ModuleProvider *P);
FunctionPassManager_New(); FunctionPassManager();
~FunctionPassManager_New(); ~FunctionPassManager();
/// add - Add a pass to the queue of passes to run. This passes /// add - Add a pass to the queue of passes to run. This passes
/// ownership of the Pass to the PassManager. When the /// ownership of the Pass to the PassManager. When the
@ -150,6 +155,7 @@ private:
ModuleProvider *MP; ModuleProvider *MP;
}; };
#endif
} // End llvm namespace } // End llvm namespace

View File

@ -14,7 +14,9 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/PassManager.h" #include "llvm/PassManager.h"
#ifdef USE_OLD_PASSMANAGER
#include "PassManagerT.h" // PassManagerT implementation #include "PassManagerT.h" // PassManagerT implementation
#endif
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/ModuleProvider.h" #include "llvm/ModuleProvider.h"
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
@ -34,6 +36,7 @@ void AnalysisResolver::setAnalysisResolver(Pass *P, AnalysisResolver *AR) {
P->Resolver = AR; P->Resolver = AR;
} }
#ifdef USE_OLD_PASSMANAGER
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// PassManager implementation - The PassManager class is a simple Pimpl class // PassManager implementation - The PassManager class is a simple Pimpl class
// that wraps the PassManagerT template. // that wraps the PassManagerT template.
@ -158,17 +161,24 @@ void PMDebug::PrintAnalysisSetInfo(unsigned Depth, const char *Msg,
cerr << "\n"; cerr << "\n";
} }
} }
#endif
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Pass Implementation // Pass Implementation
// //
#ifdef USE_OLD_PASSMANAGER
void ModulePass::addToPassManager(ModulePassManager *PM, AnalysisUsage &AU) { void ModulePass::addToPassManager(ModulePassManager *PM, AnalysisUsage &AU) {
PM->addPass(this, AU); PM->addPass(this, AU);
} }
#endif
bool Pass::mustPreserveAnalysisID(const PassInfo *AnalysisID) const { bool Pass::mustPreserveAnalysisID(const PassInfo *AnalysisID) const {
#ifdef USE_OLD_PASSMANAGER
return Resolver->getAnalysisToUpdate(AnalysisID) != 0; return Resolver->getAnalysisToUpdate(AnalysisID) != 0;
#else
return Resolver_New->getAnalysisToUpdate(AnalysisID, true) != 0;
#endif
} }
// dumpPassStructure - Implement the -debug-passes=Structure option // dumpPassStructure - Implement the -debug-passes=Structure option
@ -200,11 +210,12 @@ void Pass::dump() const {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// ImmutablePass Implementation // ImmutablePass Implementation
// //
#ifdef USE_OLD_PASSMANAGER
void ImmutablePass::addToPassManager(ModulePassManager *PM, void ImmutablePass::addToPassManager(ModulePassManager *PM,
AnalysisUsage &AU) { AnalysisUsage &AU) {
PM->addPass(this, AU); PM->addPass(this, AU);
} }
#endif
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// FunctionPass Implementation // FunctionPass Implementation
@ -233,6 +244,7 @@ bool FunctionPass::run(Function &F) {
return Changed | doFinalization(*F.getParent()); return Changed | doFinalization(*F.getParent());
} }
#ifdef USE_OLD_PASSMANAGER
void FunctionPass::addToPassManager(ModulePassManager *PM, void FunctionPass::addToPassManager(ModulePassManager *PM,
AnalysisUsage &AU) { AnalysisUsage &AU) {
PM->addPass(this, AU); PM->addPass(this, AU);
@ -242,6 +254,7 @@ void FunctionPass::addToPassManager(FunctionPassManagerT *PM,
AnalysisUsage &AU) { AnalysisUsage &AU) {
PM->addPass(this, AU); PM->addPass(this, AU);
} }
#endif
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// BasicBlockPass Implementation // BasicBlockPass Implementation
@ -271,6 +284,7 @@ bool BasicBlockPass::runPass(BasicBlock &BB) {
return Changed; return Changed;
} }
#ifdef USE_OLD_PASSMANAGER
void BasicBlockPass::addToPassManager(FunctionPassManagerT *PM, void BasicBlockPass::addToPassManager(FunctionPassManagerT *PM,
AnalysisUsage &AU) { AnalysisUsage &AU) {
PM->addPass(this, AU); PM->addPass(this, AU);
@ -280,7 +294,7 @@ void BasicBlockPass::addToPassManager(BasicBlockPassManager *PM,
AnalysisUsage &AU) { AnalysisUsage &AU) {
PM->addPass(this, AU); PM->addPass(this, AU);
} }
#endif
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Pass Registration mechanism // Pass Registration mechanism

View File

@ -84,6 +84,7 @@ using namespace llvm;
// ModulePassManagers. // ModulePassManagers.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#ifndef USE_OLD_PASSMANAGER
namespace llvm { namespace llvm {
class PMDataManager; class PMDataManager;
@ -125,6 +126,10 @@ public:
/// then return NULL. /// then return NULL.
Pass *findAnalysisPass(AnalysisID AID); Pass *findAnalysisPass(AnalysisID AID);
inline void clearManagers() {
PassManagers.clear();
}
virtual ~PMTopLevelManager() { virtual ~PMTopLevelManager() {
for (std::vector<Pass *>::iterator I = PassManagers.begin(), for (std::vector<Pass *>::iterator I = PassManagers.begin(),
@ -291,16 +296,16 @@ private:
}; };
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// BasicBlockPassManager_New // BasicBlockPassManager
// //
/// BasicBlockPassManager_New manages BasicBlockPass. It batches all the /// BasicBlockPassManager manages BasicBlockPass. It batches all the
/// pass together and sequence them to process one basic block before /// pass together and sequence them to process one basic block before
/// processing next basic block. /// processing next basic block.
class BasicBlockPassManager_New : public PMDataManager, class BasicBlockPassManager : public PMDataManager,
public FunctionPass { public FunctionPass {
public: public:
BasicBlockPassManager_New(int D) : PMDataManager(D) { } BasicBlockPassManager(int D) : PMDataManager(D) { }
/// Add a pass into a passmanager queue. /// Add a pass into a passmanager queue.
bool addPass(Pass *p); bool addPass(Pass *p);
@ -407,20 +412,20 @@ public:
private: private:
// Active Pass Managers // Active Pass Managers
BasicBlockPassManager_New *activeBBPassManager; BasicBlockPassManager *activeBBPassManager;
}; };
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// ModulePassManager_New // ModulePassManager
// //
/// ModulePassManager_New manages ModulePasses and function pass managers. /// ModulePassManager manages ModulePasses and function pass managers.
/// It batches all Module passes passes and function pass managers together and /// It batches all Module passes passes and function pass managers together and
/// sequence them to process one module. /// sequence them to process one module.
class ModulePassManager_New : public Pass, class ModulePassManager : public Pass,
public PMDataManager { public PMDataManager {
public: public:
ModulePassManager_New(int D) : PMDataManager(D) { ModulePassManager(int D) : PMDataManager(D) {
activeFunctionPassManager = NULL; activeFunctionPassManager = NULL;
} }
@ -504,7 +509,7 @@ private:
bool addPass(Pass *p); bool addPass(Pass *p);
// Active Pass Manager // Active Pass Manager
ModulePassManager_New *activeManager; ModulePassManager *activeManager;
}; };
} // End of llvm namespace } // End of llvm namespace
@ -814,12 +819,12 @@ Pass *AnalysisResolver_New::getAnalysisToUpdate(AnalysisID ID, bool dir) const {
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// BasicBlockPassManager_New implementation // BasicBlockPassManager implementation
/// Add pass P into PassVector and return true. If this pass is not /// Add pass P into PassVector and return true. If this pass is not
/// manageable by this manager then return false. /// manageable by this manager then return false.
bool bool
BasicBlockPassManager_New::addPass(Pass *P) { BasicBlockPassManager::addPass(Pass *P) {
BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P); BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
if (!BP) if (!BP)
@ -839,7 +844,7 @@ BasicBlockPassManager_New::addPass(Pass *P) {
/// runOnBasicBlock method. Keep track of whether any of the passes modifies /// runOnBasicBlock method. Keep track of whether any of the passes modifies
/// the function, and if so, return true. /// the function, and if so, return true.
bool bool
BasicBlockPassManager_New::runOnFunction(Function &F) { BasicBlockPassManager::runOnFunction(Function &F) {
if (F.isExternal()) if (F.isExternal())
return false; return false;
@ -862,7 +867,7 @@ BasicBlockPassManager_New::runOnFunction(Function &F) {
} }
// Implement doInitialization and doFinalization // Implement doInitialization and doFinalization
inline bool BasicBlockPassManager_New::doInitialization(Module &M) { inline bool BasicBlockPassManager::doInitialization(Module &M) {
bool Changed = false; bool Changed = false;
for (std::vector<Pass *>::iterator itr = passVectorBegin(), for (std::vector<Pass *>::iterator itr = passVectorBegin(),
@ -875,7 +880,7 @@ inline bool BasicBlockPassManager_New::doInitialization(Module &M) {
return Changed; return Changed;
} }
inline bool BasicBlockPassManager_New::doFinalization(Module &M) { inline bool BasicBlockPassManager::doFinalization(Module &M) {
bool Changed = false; bool Changed = false;
for (std::vector<Pass *>::iterator itr = passVectorBegin(), for (std::vector<Pass *>::iterator itr = passVectorBegin(),
@ -888,7 +893,7 @@ inline bool BasicBlockPassManager_New::doFinalization(Module &M) {
return Changed; return Changed;
} }
inline bool BasicBlockPassManager_New::doInitialization(Function &F) { inline bool BasicBlockPassManager::doInitialization(Function &F) {
bool Changed = false; bool Changed = false;
for (std::vector<Pass *>::iterator itr = passVectorBegin(), for (std::vector<Pass *>::iterator itr = passVectorBegin(),
@ -901,7 +906,7 @@ inline bool BasicBlockPassManager_New::doInitialization(Function &F) {
return Changed; return Changed;
} }
inline bool BasicBlockPassManager_New::doFinalization(Function &F) { inline bool BasicBlockPassManager::doFinalization(Function &F) {
bool Changed = false; bool Changed = false;
for (std::vector<Pass *>::iterator itr = passVectorBegin(), for (std::vector<Pass *>::iterator itr = passVectorBegin(),
@ -916,10 +921,10 @@ inline bool BasicBlockPassManager_New::doFinalization(Function &F) {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// FunctionPassManager_New implementation // FunctionPassManager implementation
/// Create new Function pass manager /// Create new Function pass manager
FunctionPassManager_New::FunctionPassManager_New(ModuleProvider *P) { FunctionPassManager::FunctionPassManager(ModuleProvider *P) {
FPM = new FunctionPassManagerImpl_New(0); FPM = new FunctionPassManagerImpl_New(0);
// FPM is the top level manager. // FPM is the top level manager.
FPM->setTopLevelManager(FPM); FPM->setTopLevelManager(FPM);
@ -932,7 +937,14 @@ FunctionPassManager_New::FunctionPassManager_New(ModuleProvider *P) {
MP = P; MP = P;
} }
FunctionPassManager_New::~FunctionPassManager_New() { FunctionPassManager::~FunctionPassManager() {
// Note : FPM maintains one entry in PassManagers vector.
// This one entry is FPM itself. This is not ideal. One
// alternative is have one additional layer between
// FunctionPassManager and FunctionPassManagerImpl.
// Meanwhile, to avoid going into infinte loop, first
// remove FPM from its PassMangers vector.
FPM->clearManagers();
delete FPM; delete FPM;
} }
@ -941,7 +953,7 @@ FunctionPassManager_New::~FunctionPassManager_New() {
/// PassManager_X is destroyed, the pass will be destroyed as well, so /// PassManager_X is destroyed, the pass will be destroyed as well, so
/// there is no need to delete the pass. (TODO delete passes.) /// there is no need to delete the pass. (TODO delete passes.)
/// This implies that all passes MUST be allocated with 'new'. /// This implies that all passes MUST be allocated with 'new'.
void FunctionPassManager_New::add(Pass *P) { void FunctionPassManager::add(Pass *P) {
FPM->add(P); FPM->add(P);
} }
@ -949,7 +961,7 @@ void FunctionPassManager_New::add(Pass *P) {
/// track of whether any of the passes modifies the function, and if /// track of whether any of the passes modifies the function, and if
/// so, return true. /// so, return true.
/// ///
bool FunctionPassManager_New::run(Function &F) { bool FunctionPassManager::run(Function &F) {
std::string errstr; std::string errstr;
if (MP->materializeFunction(&F, &errstr)) { if (MP->materializeFunction(&F, &errstr)) {
cerr << "Error reading bytecode file: " << errstr << "\n"; cerr << "Error reading bytecode file: " << errstr << "\n";
@ -961,13 +973,13 @@ bool FunctionPassManager_New::run(Function &F) {
/// doInitialization - Run all of the initializers for the function passes. /// doInitialization - Run all of the initializers for the function passes.
/// ///
bool FunctionPassManager_New::doInitialization() { bool FunctionPassManager::doInitialization() {
return FPM->doInitialization(*MP->getModule()); return FPM->doInitialization(*MP->getModule());
} }
/// doFinalization - Run all of the initializers for the function passes. /// doFinalization - Run all of the initializers for the function passes.
/// ///
bool FunctionPassManager_New::doFinalization() { bool FunctionPassManager::doFinalization() {
return FPM->doFinalization(*MP->getModule()); return FPM->doFinalization(*MP->getModule());
} }
@ -980,7 +992,7 @@ bool FunctionPassManager_New::doFinalization() {
bool bool
FunctionPassManagerImpl_New::addPass(Pass *P) { FunctionPassManagerImpl_New::addPass(Pass *P) {
// If P is a BasicBlockPass then use BasicBlockPassManager_New. // If P is a BasicBlockPass then use BasicBlockPassManager.
if (BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P)) { if (BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P)) {
if (!activeBBPassManager || !activeBBPassManager->addPass(BP)) { if (!activeBBPassManager || !activeBBPassManager->addPass(BP)) {
@ -991,7 +1003,7 @@ FunctionPassManagerImpl_New::addPass(Pass *P) {
// Create and add new manager // Create and add new manager
activeBBPassManager = activeBBPassManager =
new BasicBlockPassManager_New(getDepth() + 1); new BasicBlockPassManager(getDepth() + 1);
// Inherit top level manager // Inherit top level manager
activeBBPassManager->setTopLevelManager(this->getTopLevelManager()); activeBBPassManager->setTopLevelManager(this->getTopLevelManager());
@ -1109,7 +1121,8 @@ bool FunctionPassManagerImpl_New::run(Function &F) {
bool Changed = false; bool Changed = false;
for (std::vector<Pass *>::iterator I = passManagersBegin(), for (std::vector<Pass *>::iterator I = passManagersBegin(),
E = passManagersEnd(); I != E; ++I) { E = passManagersEnd(); I != E; ++I) {
FunctionPass *FP = dynamic_cast<FunctionPass *>(*I); FunctionPassManagerImpl_New *FP =
dynamic_cast<FunctionPassManagerImpl_New *>(*I);
Changed |= FP->runOnFunction(F); Changed |= FP->runOnFunction(F);
} }
return Changed; return Changed;
@ -1122,7 +1135,7 @@ bool FunctionPassManagerImpl_New::run(Function &F) {
/// then use FunctionPassManagerImpl_New to manage it. Return false if P /// then use FunctionPassManagerImpl_New to manage it. Return false if P
/// is not manageable by this manager. /// is not manageable by this manager.
bool bool
ModulePassManager_New::addPass(Pass *P) { ModulePassManager::addPass(Pass *P) {
// If P is FunctionPass then use function pass maanager. // If P is FunctionPass then use function pass maanager.
if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P)) { if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P)) {
@ -1183,7 +1196,7 @@ ModulePassManager_New::addPass(Pass *P) {
/// runOnModule method. Keep track of whether any of the passes modifies /// runOnModule method. Keep track of whether any of the passes modifies
/// the module, and if so, return true. /// the module, and if so, return true.
bool bool
ModulePassManager_New::runOnModule(Module &M) { ModulePassManager::runOnModule(Module &M) {
bool Changed = false; bool Changed = false;
initializeAnalysisInfo(); initializeAnalysisInfo();
@ -1208,7 +1221,7 @@ ModulePassManager_New::runOnModule(Module &M) {
bool PassManagerImpl_New::addPass(Pass *P) { bool PassManagerImpl_New::addPass(Pass *P) {
if (!activeManager || !activeManager->addPass(P)) { if (!activeManager || !activeManager->addPass(P)) {
activeManager = new ModulePassManager_New(getDepth() + 1); activeManager = new ModulePassManager(getDepth() + 1);
// Inherit top level manager // Inherit top level manager
activeManager->setTopLevelManager(this->getTopLevelManager()); activeManager->setTopLevelManager(this->getTopLevelManager());
@ -1230,7 +1243,7 @@ bool PassManagerImpl_New::run(Module &M) {
bool Changed = false; bool Changed = false;
for (std::vector<Pass *>::iterator I = passManagersBegin(), for (std::vector<Pass *>::iterator I = passManagersBegin(),
E = passManagersEnd(); I != E; ++I) { E = passManagersEnd(); I != E; ++I) {
ModulePassManager_New *MP = dynamic_cast<ModulePassManager_New *>(*I); ModulePassManager *MP = dynamic_cast<ModulePassManager *>(*I);
Changed |= MP->runOnModule(M); Changed |= MP->runOnModule(M);
} }
return Changed; return Changed;
@ -1240,13 +1253,13 @@ bool PassManagerImpl_New::run(Module &M) {
// PassManager implementation // PassManager implementation
/// Create new pass manager /// Create new pass manager
PassManager_New::PassManager_New() { PassManager::PassManager() {
PM = new PassManagerImpl_New(0); PM = new PassManagerImpl_New(0);
// PM is the top level manager // PM is the top level manager
PM->setTopLevelManager(PM); PM->setTopLevelManager(PM);
} }
PassManager_New::~PassManager_New() { PassManager::~PassManager() {
delete PM; delete PM;
} }
@ -1255,14 +1268,15 @@ PassManager_New::~PassManager_New() {
/// will be destroyed as well, so there is no need to delete the pass. This /// will be destroyed as well, so there is no need to delete the pass. This
/// implies that all passes MUST be allocated with 'new'. /// implies that all passes MUST be allocated with 'new'.
void void
PassManager_New::add(Pass *P) { PassManager::add(Pass *P) {
PM->add(P); PM->add(P);
} }
/// run - Execute all of the passes scheduled for execution. Keep track of /// run - Execute all of the passes scheduled for execution. Keep track of
/// whether any of the passes modifies the module, and if so, return true. /// whether any of the passes modifies the module, and if so, return true.
bool bool
PassManager_New::run(Module &M) { PassManager::run(Module &M) {
return PM->run(M); return PM->run(M);
} }
#endif