blob: 4f363dc1a0d72732a9a6747d3054c6588834dfd0 [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"
Chris Lattner55b2eb32003-08-31 20:01:57 +000013#include "Support/SCCIterator.h"
Chris Lattner4a810672003-08-31 01:54:59 +000014
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;
Chris Lattner55b2eb32003-08-31 20:01:57 +000026 for (scc_iterator<CallGraph*> I = scc_begin(&CG), E = scc_end(&CG);
Chris Lattner4a810672003-08-31 01:54:59 +000027 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}