CallGraphSCCPass.cpp revision d0fde30ce850b78371fd1386338350591f9ff494
14a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner//===- CallGraphSCCPass.cpp - Pass that operates BU on call graph ---------===// 2b576c94c15af9a440f69d9d03c2afead7971118cJohn Criswell// 3b576c94c15af9a440f69d9d03c2afead7971118cJohn Criswell// The LLVM Compiler Infrastructure 4b576c94c15af9a440f69d9d03c2afead7971118cJohn Criswell// 5b576c94c15af9a440f69d9d03c2afead7971118cJohn Criswell// This file was developed by the LLVM research group and is distributed under 6b576c94c15af9a440f69d9d03c2afead7971118cJohn Criswell// the University of Illinois Open Source License. See LICENSE.TXT for details. 7b576c94c15af9a440f69d9d03c2afead7971118cJohn Criswell// 8b576c94c15af9a440f69d9d03c2afead7971118cJohn Criswell//===----------------------------------------------------------------------===// 94a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner// 104a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner// This file implements the CallGraphSCCPass class, which is used for passes 114a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner// which are implemented as bottom-up traversals on the call graph. Because 124a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner// there may be cycles in the call graph, passes of this type operate on the 134a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner// call-graph in SCC order: that is, they process function bottom-up, except for 144a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner// recursive functions, which they process all at once. 154a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner// 164a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner//===----------------------------------------------------------------------===// 174a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner 184a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner#include "llvm/CallGraphSCCPass.h" 194a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner#include "llvm/Analysis/CallGraph.h" 2055b2eb3ef828819a623444ce966e70ad86ad6da4Chris Lattner#include "Support/SCCIterator.h" 214a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner 22d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm { 23d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 244a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner/// getAnalysisUsage - For this class, we declare that we require and preserve 254a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner/// the call graph. If the derived class implements this method, it should 264a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner/// always explicitly call the implementation here. 274a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattnervoid CallGraphSCCPass::getAnalysisUsage(AnalysisUsage &AU) const { 284a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner AU.addRequired<CallGraph>(); 294a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner AU.addPreserved<CallGraph>(); 304a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner} 314a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner 324a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattnerbool CallGraphSCCPass::run(Module &M) { 334a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner CallGraph &CG = getAnalysis<CallGraph>(); 344a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner bool Changed = false; 3555b2eb3ef828819a623444ce966e70ad86ad6da4Chris Lattner for (scc_iterator<CallGraph*> I = scc_begin(&CG), E = scc_end(&CG); 364a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner I != E; ++I) 376c5fd8e0551f99ce46908fedd502b0dbf5864c74Chris Lattner Changed = runOnSCC(*I); 384a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner return Changed; 394a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner} 40d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 41d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace 42