blob: 23aedb0731f37e47af3305e011d5e0bfe667ed5d [file] [log] [blame]
Chris Lattner4a810672003-08-31 01:54:59 +00001//===- CallGraphSCCPass.cpp - Pass that operates BU on call graph ---------===//
John Criswellb576c942003-10-20 19:43:21 +00002//
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 Lattner4a810672003-08-31 01:54:59 +00009//
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 Lattner55b2eb32003-08-31 20:01:57 +000020#include "Support/SCCIterator.h"
Chris Lattnera10df502004-04-20 21:30:06 +000021using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000022
Chris Lattner4a810672003-08-31 01:54:59 +000023/// getAnalysisUsage - For this class, we declare that we require and preserve
24/// the call graph. If the derived class implements this method, it should
25/// always explicitly call the implementation here.
26void CallGraphSCCPass::getAnalysisUsage(AnalysisUsage &AU) const {
27 AU.addRequired<CallGraph>();
28 AU.addPreserved<CallGraph>();
29}
30
31bool CallGraphSCCPass::run(Module &M) {
32 CallGraph &CG = getAnalysis<CallGraph>();
Chris Lattnera10df502004-04-20 21:30:06 +000033 bool Changed = doInitialization(M);
Chris Lattner55b2eb32003-08-31 20:01:57 +000034 for (scc_iterator<CallGraph*> I = scc_begin(&CG), E = scc_end(&CG);
Chris Lattner4a810672003-08-31 01:54:59 +000035 I != E; ++I)
Chris Lattner6c5fd8e2003-08-31 19:35:16 +000036 Changed = runOnSCC(*I);
Chris Lattnera10df502004-04-20 21:30:06 +000037 return Changed | doFinalization(M);
Chris Lattner4a810672003-08-31 01:54:59 +000038}