CallGraphSCCPass.cpp revision b576c94c15af9a440f69d9d03c2afead7971118c
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
224a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner/// getAnalysisUsage - For this class, we declare that we require and preserve
234a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner/// the call graph.  If the derived class implements this method, it should
244a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner/// always explicitly call the implementation here.
254a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattnervoid CallGraphSCCPass::getAnalysisUsage(AnalysisUsage &AU) const {
264a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner  AU.addRequired<CallGraph>();
274a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner  AU.addPreserved<CallGraph>();
284a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner}
294a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner
304a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattnerbool CallGraphSCCPass::run(Module &M) {
314a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner  CallGraph &CG = getAnalysis<CallGraph>();
324a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner  bool Changed = false;
3355b2eb3ef828819a623444ce966e70ad86ad6da4Chris Lattner  for (scc_iterator<CallGraph*> I = scc_begin(&CG), E = scc_end(&CG);
344a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner       I != E; ++I)
356c5fd8e0551f99ce46908fedd502b0dbf5864c74Chris Lattner    Changed = runOnSCC(*I);
364a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner  return Changed;
374a81067a84e18c44898149f5afdbaa3e18b3e821Chris Lattner}
38