From c290c8a2c80627631eebfe97dac203a9ce42e9b8 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Tue, 7 Nov 2006 22:23:34 +0000 Subject: [PATCH] Add PassManager_New. llvm-svn: 31521 --- llvm/include/llvm/PassManager.h | 34 +++++++++++++++++++++++++++ llvm/lib/VMCore/PassManager.cpp | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/llvm/include/llvm/PassManager.h b/llvm/include/llvm/PassManager.h index 0bcf318f5d09..7e1d903d553d 100644 --- a/llvm/include/llvm/PassManager.h +++ b/llvm/include/llvm/PassManager.h @@ -166,6 +166,40 @@ private: FunctionPassManager_New *activeFunctionPassManager; }; +/// PassManager_New manages ModulePassManagers +class PassManager_New: public Pass { + +public: + + /// 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 + /// will be destroyed as well, so there is no need to delete the pass. This + /// implies that all passes MUST be allocated with 'new'. + void add(Pass *P); + + /// 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. + bool run(Module &M); + +private: + + /// Add a pass into a passmanager queue. This is used by schedulePasses + bool addPass(Pass *p); + + /// Schedule all passes collected in pass queue using add(). Add all the + /// schedule passes into various manager's queue using addPass(). + void schedulePasses(); + + // Collection of pass managers + std::vector PassManagers; + + // Collection of pass that are not yet scheduled + std::vector PassVector; + + // Active Pass Manager + ModulePassManager_New *activeManager; +}; + } // End llvm namespace #endif diff --git a/llvm/lib/VMCore/PassManager.cpp b/llvm/lib/VMCore/PassManager.cpp index 31849a0ac0b7..c87d33305a76 100644 --- a/llvm/lib/VMCore/PassManager.cpp +++ b/llvm/lib/VMCore/PassManager.cpp @@ -163,3 +163,44 @@ ModulePassManager_New::runOnModule(Module &M) { return Changed; } +/// Schedule all passes from the queue by adding them in their +/// respective manager's queue. +void +PassManager_New::schedulePasses() { + /* TODO */ +} + +/// Add pass P to the queue of passes to run. +void +PassManager_New::add(Pass *P) { + /* TODO */ +} + +// PassManager_New implementation +/// Add P into active pass manager or use new module pass manager to +/// manage it. +bool +PassManager_New::addPass (Pass *P) { + + if (!activeManager) { + activeManager = new ModulePassManager_New(); + PassManagers.push_back(activeManager); + } + + return activeManager->addPass(P); +} + +/// 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. +bool +PassManager_New::run(Module &M) { + + schedulePasses(); + bool Changed = false; + for (std::vector::iterator itr = PassManagers.begin(), + e = PassManagers.end(); itr != e; ++itr) { + ModulePassManager_New *pm = *itr; + Changed |= pm->runOnModule(M); + } + return Changed; +}