Chris Lattner | 4a81067 | 2003-08-31 01:54:59 +0000 | [diff] [blame] | 1 | //===- CallGraphSCCPass.cpp - Pass that operates BU on call graph ---------===// |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame^] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4a81067 | 2003-08-31 01:54:59 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file implements the CallGraphSCCPass class, which is used for passes |
| 11 | // which are implemented as bottom-up traversals on the call graph. Because |
| 12 | // there may be cycles in the call graph, passes of this type operate on the |
| 13 | // call-graph in SCC order: that is, they process function bottom-up, except for |
| 14 | // recursive functions, which they process all at once. |
| 15 | // |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
| 18 | #include "llvm/CallGraphSCCPass.h" |
| 19 | #include "llvm/Analysis/CallGraph.h" |
Chris Lattner | 55b2eb3 | 2003-08-31 20:01:57 +0000 | [diff] [blame] | 20 | #include "Support/SCCIterator.h" |
Chris Lattner | 4a81067 | 2003-08-31 01:54:59 +0000 | [diff] [blame] | 21 | |
| 22 | /// getAnalysisUsage - For this class, we declare that we require and preserve |
| 23 | /// the call graph. If the derived class implements this method, it should |
| 24 | /// always explicitly call the implementation here. |
| 25 | void CallGraphSCCPass::getAnalysisUsage(AnalysisUsage &AU) const { |
| 26 | AU.addRequired<CallGraph>(); |
| 27 | AU.addPreserved<CallGraph>(); |
| 28 | } |
| 29 | |
| 30 | bool CallGraphSCCPass::run(Module &M) { |
| 31 | CallGraph &CG = getAnalysis<CallGraph>(); |
| 32 | bool Changed = false; |
Chris Lattner | 55b2eb3 | 2003-08-31 20:01:57 +0000 | [diff] [blame] | 33 | for (scc_iterator<CallGraph*> I = scc_begin(&CG), E = scc_end(&CG); |
Chris Lattner | 4a81067 | 2003-08-31 01:54:59 +0000 | [diff] [blame] | 34 | I != E; ++I) |
Chris Lattner | 6c5fd8e | 2003-08-31 19:35:16 +0000 | [diff] [blame] | 35 | Changed = runOnSCC(*I); |
Chris Lattner | 4a81067 | 2003-08-31 01:54:59 +0000 | [diff] [blame] | 36 | return Changed; |
| 37 | } |