blob: 031fb02d00225518481c15230d75d9100ad356a6 [file] [log] [blame]
Chris Lattner4a810672003-08-31 01:54:59 +00001//===- 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.
18void CallGraphSCCPass::getAnalysisUsage(AnalysisUsage &AU) const {
19 AU.addRequired<CallGraph>();
20 AU.addPreserved<CallGraph>();
21}
22
23bool 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)
Chris Lattner6c5fd8e2003-08-31 19:35:16 +000028 Changed = runOnSCC(*I);
Chris Lattner4a810672003-08-31 01:54:59 +000029 return Changed;
30}