mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 00:32:55 +00:00
Add FunctionPassManager_New.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31515 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5e213ea697
commit
448d27cd79
@ -108,6 +108,41 @@ private:
|
|||||||
std::vector<Pass *> PassVector;
|
std::vector<Pass *> PassVector;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// FunctionPassManager_New manages FunctionPasses and BasicBlockPassManagers.
|
||||||
|
/// It batches all function passes and basic block pass managers together and
|
||||||
|
/// sequence them to process one function at a time before processing next
|
||||||
|
/// function.
|
||||||
|
class FunctionPassManager_New:public Pass {
|
||||||
|
public:
|
||||||
|
FunctionPassManager_New(ModuleProvider *P) { /* TODO */ }
|
||||||
|
FunctionPassManager_New() {
|
||||||
|
activeBBPassManager = NULL;
|
||||||
|
}
|
||||||
|
~FunctionPassManager_New() { /* TODO */ };
|
||||||
|
|
||||||
|
/// add - Add a pass to the queue of passes to run. This passes
|
||||||
|
/// ownership of the Pass to the PassManager. When the
|
||||||
|
/// PassManager_X is destroyed, the pass will be destroyed as well, so
|
||||||
|
/// there is no need to delete the pass. (TODO delete passes.)
|
||||||
|
/// This implies that all passes MUST be allocated with 'new'.
|
||||||
|
void add(Pass *P) { /* TODO*/ }
|
||||||
|
|
||||||
|
/// Add pass into the pass manager queue.
|
||||||
|
bool addPass(Pass *P);
|
||||||
|
|
||||||
|
/// Execute all of the passes scheduled for execution. Keep
|
||||||
|
/// track of whether any of the passes modifies the function, and if
|
||||||
|
/// so, return true.
|
||||||
|
bool runOnModule(Module &M);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Collection of pass that are not yet scheduled
|
||||||
|
std::vector<Pass *> PassVector;
|
||||||
|
|
||||||
|
// Active Pass Managers
|
||||||
|
BasicBlockPassManager_New *activeBBPassManager;
|
||||||
|
};
|
||||||
|
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -54,3 +54,59 @@ BasicBlockPassManager_New::runOnFunction(Function &F) {
|
|||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FunctionPassManager_New implementation
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// FunctionPassManager
|
||||||
|
|
||||||
|
/// Add pass P into the pass manager queue. If P is a BasicBlockPass then
|
||||||
|
/// either use it into active basic block pass manager or create new basic
|
||||||
|
/// block pass manager to handle pass P.
|
||||||
|
bool
|
||||||
|
FunctionPassManager_New::addPass (Pass *P) {
|
||||||
|
|
||||||
|
// If P is a BasicBlockPass then use BasicBlockPassManager_New.
|
||||||
|
if (BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P)) {
|
||||||
|
|
||||||
|
if (!activeBBPassManager
|
||||||
|
|| !activeBBPassManager->addPass(BP)) {
|
||||||
|
|
||||||
|
activeBBPassManager = new BasicBlockPassManager_New();
|
||||||
|
|
||||||
|
PassVector.push_back(activeBBPassManager);
|
||||||
|
assert (!activeBBPassManager->addPass(BP) &&
|
||||||
|
"Unable to add Pass");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
FunctionPass *FP = dynamic_cast<FunctionPass *>(P);
|
||||||
|
if (!FP)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// TODO: Check if it suitable to manage P using this FunctionPassManager
|
||||||
|
// or we need another instance of BasicBlockPassManager
|
||||||
|
|
||||||
|
PassVector.push_back(FP);
|
||||||
|
activeBBPassManager = NULL;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Execute all of the passes scheduled for execution by invoking
|
||||||
|
/// runOnFunction method. Keep track of whether any of the passes modifies
|
||||||
|
/// the function, and if so, return true.
|
||||||
|
bool
|
||||||
|
FunctionPassManager_New::runOnModule(Module &M) {
|
||||||
|
|
||||||
|
bool Changed = false;
|
||||||
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
||||||
|
for (std::vector<Pass *>::iterator itr = PassVector.begin(),
|
||||||
|
e = PassVector.end(); itr != e; ++itr) {
|
||||||
|
Pass *P = *itr;
|
||||||
|
FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
|
||||||
|
Changed |= FP->runOnFunction(*I);
|
||||||
|
}
|
||||||
|
return Changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user