Chris Lattner | 4a81067 | 2003-08-31 01:54:59 +0000 | [diff] [blame^] | 1 | //===- CallGraphSCCPass.cpp - Pass that operates BU on call graph ---------===// |
| 2 | // |
| 3 | // This file implements the CallGraphSCCPass class, which is used for passes |
| 4 | // which are implemented as bottom-up traversals on the call graph. Because |
| 5 | // there may be cycles in the call graph, passes of this type operate on the |
| 6 | // call-graph in SCC order: that is, they process function bottom-up, except for |
| 7 | // recursive functions, which they process all at once. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #include "llvm/CallGraphSCCPass.h" |
| 12 | #include "llvm/Analysis/CallGraph.h" |
| 13 | #include "Support/TarjanSCCIterator.h" |
| 14 | |
| 15 | /// getAnalysisUsage - For this class, we declare that we require and preserve |
| 16 | /// the call graph. If the derived class implements this method, it should |
| 17 | /// always explicitly call the implementation here. |
| 18 | void CallGraphSCCPass::getAnalysisUsage(AnalysisUsage &AU) const { |
| 19 | AU.addRequired<CallGraph>(); |
| 20 | AU.addPreserved<CallGraph>(); |
| 21 | } |
| 22 | |
| 23 | bool CallGraphSCCPass::run(Module &M) { |
| 24 | CallGraph &CG = getAnalysis<CallGraph>(); |
| 25 | bool Changed = false; |
| 26 | for (TarjanSCC_iterator<CallGraph*> I = tarj_begin(&CG), E = tarj_end(&CG); |
| 27 | I != E; ++I) |
| 28 | Changed = runOnSCC(**I); |
| 29 | return Changed; |
| 30 | } |