LLVM API Documentation
00001 //===- CallGraphSCCPass.cpp - Pass that operates BU on call graph ---------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the CallGraphSCCPass class, which is used for passes 00011 // which are implemented as bottom-up traversals on the call graph. Because 00012 // there may be cycles in the call graph, passes of this type operate on the 00013 // call-graph in SCC order: that is, they process function bottom-up, except for 00014 // recursive functions, which they process all at once. 00015 // 00016 //===----------------------------------------------------------------------===// 00017 00018 #include "llvm/CallGraphSCCPass.h" 00019 #include "llvm/Analysis/CallGraph.h" 00020 #include "llvm/ADT/SCCIterator.h" 00021 using namespace llvm; 00022 00023 /// getAnalysisUsage - For this class, we declare that we require and preserve 00024 /// the call graph. If the derived class implements this method, it should 00025 /// always explicitly call the implementation here. 00026 void CallGraphSCCPass::getAnalysisUsage(AnalysisUsage &AU) const { 00027 AU.addRequired<CallGraph>(); 00028 AU.addPreserved<CallGraph>(); 00029 } 00030 00031 bool CallGraphSCCPass::runOnModule(Module &M) { 00032 CallGraph &CG = getAnalysis<CallGraph>(); 00033 bool Changed = doInitialization(CG); 00034 for (scc_iterator<CallGraph*> I = scc_begin(&CG), E = scc_end(&CG); 00035 I != E; ++I) 00036 Changed = runOnSCC(*I); 00037 return Changed | doFinalization(CG); 00038 }