CallGraphSCCPass.cpp revision 6c5fd8e0551f99ce46908fedd502b0dbf5864c74
14a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner//===- CallGraphSCCPass.cpp - Pass that operates BU on call graph ---------===// 24a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner// 34a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner// This file implements the CallGraphSCCPass class, which is used for passes 44a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner// which are implemented as bottom-up traversals on the call graph. Because 54a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner// there may be cycles in the call graph, passes of this type operate on the 64a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner// call-graph in SCC order: that is, they process function bottom-up, except for 74a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner// recursive functions, which they process all at once. 84a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner// 94a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner//===----------------------------------------------------------------------===// 104a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner 114a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner#include "llvm/CallGraphSCCPass.h" 124a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner#include "llvm/Analysis/CallGraph.h" 134a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner#include "Support/TarjanSCCIterator.h" 144a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner 154a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner/// getAnalysisUsage - For this class, we declare that we require and preserve 164a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner/// the call graph. If the derived class implements this method, it should 174a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner/// always explicitly call the implementation here. 184a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattnervoid CallGraphSCCPass::getAnalysisUsage(AnalysisUsage &AU) const { 194a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner AU.addRequired<CallGraph>(); 204a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner AU.addPreserved<CallGraph>(); 214a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner} 224a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner 234a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattnerbool CallGraphSCCPass::run(Module &M) { 244a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner CallGraph &CG = getAnalysis<CallGraph>(); 254a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner bool Changed = false; 264a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner for (TarjanSCC_iterator<CallGraph*> I = tarj_begin(&CG), E = tarj_end(&CG); 274a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner I != E; ++I) 286c5fd8e0551f99ce46908fedd502b0dbf5864c74Chris Lattner Changed = runOnSCC(*I); 294a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner return Changed; 304a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner} 31