namespace llvm {
class CallGraphNode;
+class Module;
struct CallGraphSCCPass : public Pass {
+ /// doInitialization - This method is called before the SCC's of the program
+ /// has been processed, allowing the pass to do initialization as necessary.
+ virtual bool doInitialization(Module &M) {
+ return false;
+ }
+
/// runOnSCC - This method should be implemented by the subclass to perform
/// whatever action is necessary for the specified SCC. Note that
/// non-recursive (or only self-recursive) functions will have an SCC size of
///
virtual bool runOnSCC(const std::vector<CallGraphNode *> &SCC) = 0;
+ /// doFinalization - This method is called after the SCC's of the program has
+ /// been processed, allowing the pass to do final cleanup as necessary.
+ virtual bool doFinalization(Module &M) {
+ return false;
+ }
+
/// run - Run this pass, returning true if a modification was made to the
/// module argument. This is implemented in terms of the runOnSCC method.
///
#include "llvm/CallGraphSCCPass.h"
#include "llvm/Analysis/CallGraph.h"
#include "Support/SCCIterator.h"
-
-namespace llvm {
+using namespace llvm;
/// getAnalysisUsage - For this class, we declare that we require and preserve
/// the call graph. If the derived class implements this method, it should
bool CallGraphSCCPass::run(Module &M) {
CallGraph &CG = getAnalysis<CallGraph>();
- bool Changed = false;
+ bool Changed = doInitialization(M);
for (scc_iterator<CallGraph*> I = scc_begin(&CG), E = scc_end(&CG);
I != E; ++I)
Changed = runOnSCC(*I);
- return Changed;
+ return Changed | doFinalization(M);
}
-
-} // End llvm namespace