Add a new BasicBlockPass::doInitialization/Finalization(Function &) pair of

methods that may be useful for BasicBlockPasses.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3688 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2002-09-12 17:06:40 +00:00
parent 287d4436c5
commit e0a54f88a0
2 changed files with 22 additions and 4 deletions

View File

@ -341,18 +341,20 @@ void FunctionPass::addToPassManager(PassManagerT<Function> *PM,
// function.
//
bool BasicBlockPass::runOnFunction(Function &F) {
bool Changed = false;
bool Changed = doInitialization(F);
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
Changed |= runOnBasicBlock(*I);
return Changed;
return Changed | doFinalization(F);
}
// To run directly on the basic block, we initialize, runOnBasicBlock, then
// finalize.
//
bool BasicBlockPass::run(BasicBlock &BB) {
Module &M = *BB.getParent()->getParent();
return doInitialization(M) | runOnBasicBlock(BB) | doFinalization(M);
Function &F = *BB.getParent();
Module &M = *F.getParent();
return doInitialization(M) | doInitialization(F) | runOnBasicBlock(BB) |
doFinalization(F) | doFinalization(M);
}
void BasicBlockPass::addToPassManager(PassManagerT<Function> *PM,

View File

@ -525,7 +525,9 @@ template<> struct PassManagerTraits<BasicBlock> : public BasicBlockPass {
// Implement the BasicBlockPass interface...
virtual bool doInitialization(Module &M);
virtual bool doInitialization(Function &F);
virtual bool runOnBasicBlock(BasicBlock &BB);
virtual bool doFinalization(Function &F);
virtual bool doFinalization(Module &M);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
@ -657,10 +659,24 @@ inline bool PassManagerTraits<BasicBlock>::doInitialization(Module &M) {
return Changed;
}
inline bool PassManagerTraits<BasicBlock>::doInitialization(Function &F) {
bool Changed = false;
for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
((PMType*)this)->Passes[i]->doInitialization(F);
return Changed;
}
inline bool PassManagerTraits<BasicBlock>::runOnBasicBlock(BasicBlock &BB) {
return ((PMType*)this)->runOnUnit(&BB);
}
inline bool PassManagerTraits<BasicBlock>::doFinalization(Function &F) {
bool Changed = false;
for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
((PMType*)this)->Passes[i]->doFinalization(F);
return Changed;
}
inline bool PassManagerTraits<BasicBlock>::doFinalization(Module &M) {
bool Changed = false;
for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)