Inliner.cpp revision b11a99bd39ec12733527bde330302b435b8d9f1a
1237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner//===- InlineCommon.cpp - Code common to all inliners ---------------------===//
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//===----------------------------------------------------------------------===//
9237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner//
10befa499d45ffcc32bd9902518aec18589464e47cChris Lattner// This file implements the mechanics required to implement inlining without
11befa499d45ffcc32bd9902518aec18589464e47cChris Lattner// missing any calls and updating the call graph.  The decisions of which calls
12befa499d45ffcc32bd9902518aec18589464e47cChris Lattner// are profitable to inline are implemented elsewhere.
13237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner//
14237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner//===----------------------------------------------------------------------===//
15237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner
16237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner#include "Inliner.h"
17bb9ae1512e1179681c1774f2f1a9d8c042941a56Chris Lattner#include "llvm/Constants.h"   // ConstantPointerRef should die
18237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner#include "llvm/Module.h"
19237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner#include "llvm/iOther.h"
20237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner#include "llvm/iTerminators.h"
21237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner#include "llvm/Analysis/CallGraph.h"
22237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner#include "llvm/Support/CallSite.h"
23237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner#include "llvm/Transforms/Utils/Cloning.h"
24237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner#include "Support/CommandLine.h"
25237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner#include "Support/Debug.h"
26237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner#include "Support/Statistic.h"
27befa499d45ffcc32bd9902518aec18589464e47cChris Lattner#include <set>
28a51bcb50b0c74adc741361824ef81dbefb715c53Chris Lattnerusing namespace llvm;
29d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
30237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattnernamespace {
31237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner  Statistic<> NumInlined("inline", "Number of functions inlined");
32237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner  Statistic<> NumDeleted("inline", "Number of functions deleted because all callers found");
33237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner  cl::opt<unsigned>             // FIXME: 200 is VERY conservative
34237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner  InlineLimit("inline-threshold", cl::Hidden, cl::init(200),
35237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner              cl::desc("Control the amount of inlining to perform (default = 200)"));
36237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner}
37237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner
38237ef567f6764f24a47c63121cc0a599ddc8f56dChris LattnerInliner::Inliner() : InlineThreshold(InlineLimit) {}
39237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner
40befa499d45ffcc32bd9902518aec18589464e47cChris Lattner// InlineCallIfPossible - If it is possible to inline the specified call site,
41befa499d45ffcc32bd9902518aec18589464e47cChris Lattner// do so and update the CallGraph for this operation.
42befa499d45ffcc32bd9902518aec18589464e47cChris Lattnerstatic bool InlineCallIfPossible(CallSite CS, CallGraph &CG,
43befa499d45ffcc32bd9902518aec18589464e47cChris Lattner                                 const std::set<Function*> &SCCFunctions) {
44befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  Function *Caller = CS.getInstruction()->getParent()->getParent();
45befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  Function *Callee = CS.getCalledFunction();
46befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  if (!InlineFunction(CS)) return false;
47befa499d45ffcc32bd9902518aec18589464e47cChris Lattner
48befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  // Update the call graph by deleting the edge from Callee to Caller
49befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  CallGraphNode *CalleeNode = CG[Callee];
50befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  CallGraphNode *CallerNode = CG[Caller];
51befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  CallerNode->removeCallEdgeTo(CalleeNode);
52befa499d45ffcc32bd9902518aec18589464e47cChris Lattner
53befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  // Since we inlined all uninlined call sites in the callee into the caller,
54befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  // add edges from the caller to all of the callees of the callee.
55befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  for (CallGraphNode::iterator I = CalleeNode->begin(),
56befa499d45ffcc32bd9902518aec18589464e47cChris Lattner         E = CalleeNode->end(); I != E; ++I)
57befa499d45ffcc32bd9902518aec18589464e47cChris Lattner    CallerNode->addCalledFunction(*I);
58befa499d45ffcc32bd9902518aec18589464e47cChris Lattner
59befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  // If we inlined the last possible call site to the function,
60befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  // delete the function body now.
61befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  if (Callee->use_empty() && Callee->hasInternalLinkage() &&
62befa499d45ffcc32bd9902518aec18589464e47cChris Lattner      !SCCFunctions.count(Callee)) {
63befa499d45ffcc32bd9902518aec18589464e47cChris Lattner    DEBUG(std::cerr << "    -> Deleting dead function: "
64befa499d45ffcc32bd9902518aec18589464e47cChris Lattner                    << Callee->getName() << "\n");
65befa499d45ffcc32bd9902518aec18589464e47cChris Lattner
66befa499d45ffcc32bd9902518aec18589464e47cChris Lattner    // Remove any call graph edges from the callee to its callees.
67befa499d45ffcc32bd9902518aec18589464e47cChris Lattner    while (CalleeNode->begin() != CalleeNode->end())
68befa499d45ffcc32bd9902518aec18589464e47cChris Lattner      CalleeNode->removeCallEdgeTo(*(CalleeNode->end()-1));
69befa499d45ffcc32bd9902518aec18589464e47cChris Lattner
70befa499d45ffcc32bd9902518aec18589464e47cChris Lattner    // Removing the node for callee from the call graph and delete it.
71befa499d45ffcc32bd9902518aec18589464e47cChris Lattner    delete CG.removeFunctionFromModule(CalleeNode);
72befa499d45ffcc32bd9902518aec18589464e47cChris Lattner    ++NumDeleted;
73befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  }
74befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  return true;
75237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner}
76237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner
77237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattnerbool Inliner::runOnSCC(const std::vector<CallGraphNode*> &SCC) {
78237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner  CallGraph &CG = getAnalysis<CallGraph>();
79237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner
80237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner  std::set<Function*> SCCFunctions;
81237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner  DEBUG(std::cerr << "Inliner visiting SCC:");
82237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner  for (unsigned i = 0, e = SCC.size(); i != e; ++i) {
83befa499d45ffcc32bd9902518aec18589464e47cChris Lattner    Function *F = SCC[i]->getFunction();
84befa499d45ffcc32bd9902518aec18589464e47cChris Lattner    if (F) SCCFunctions.insert(F);
85befa499d45ffcc32bd9902518aec18589464e47cChris Lattner    DEBUG(std::cerr << " " << (F ? F->getName() : "INDIRECTNODE"));
86237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner  }
87237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner
88befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  // Scan through and identify all call sites ahead of time so that we only
89befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  // inline call sites in the original functions, not call sites that result
90befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  // from inlining other functions.
91befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  std::vector<CallSite> CallSites;
92befa499d45ffcc32bd9902518aec18589464e47cChris Lattner
93237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner  for (std::set<Function*>::iterator SCCI = SCCFunctions.begin(),
94befa499d45ffcc32bd9902518aec18589464e47cChris Lattner         E = SCCFunctions.end(); SCCI != E; ++SCCI)
95befa499d45ffcc32bd9902518aec18589464e47cChris Lattner    if (Function *F = *SCCI)
96befa499d45ffcc32bd9902518aec18589464e47cChris Lattner      for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
97befa499d45ffcc32bd9902518aec18589464e47cChris Lattner        for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
98befa499d45ffcc32bd9902518aec18589464e47cChris Lattner          CallSite CS = CallSite::get(I);
99befa499d45ffcc32bd9902518aec18589464e47cChris Lattner          if (CS.getInstruction() && (!CS.getCalledFunction() ||
100befa499d45ffcc32bd9902518aec18589464e47cChris Lattner                                      !CS.getCalledFunction()->isExternal()))
101befa499d45ffcc32bd9902518aec18589464e47cChris Lattner            CallSites.push_back(CS);
102befa499d45ffcc32bd9902518aec18589464e47cChris Lattner        }
103237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner
104befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  DEBUG(std::cerr << ": " << CallSites.size() << " call sites.\n");
105befa499d45ffcc32bd9902518aec18589464e47cChris Lattner
106befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  // Now that we have all of the call sites, move the ones to functions in the
107befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  // current SCC to the end of the list.
108befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  unsigned FirstCallInSCC = CallSites.size();
109befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  for (unsigned i = 0; i < FirstCallInSCC; ++i)
110befa499d45ffcc32bd9902518aec18589464e47cChris Lattner    if (Function *F = CallSites[i].getCalledFunction())
111befa499d45ffcc32bd9902518aec18589464e47cChris Lattner      if (SCCFunctions.count(F))
112befa499d45ffcc32bd9902518aec18589464e47cChris Lattner        std::swap(CallSites[i--], CallSites[--FirstCallInSCC]);
113befa499d45ffcc32bd9902518aec18589464e47cChris Lattner
114befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  // Now that we have all of the call sites, loop over them and inline them if
115befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  // it looks profitable to do so.
116befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  bool Changed = false;
117befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  bool LocalChange;
118befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  do {
119befa499d45ffcc32bd9902518aec18589464e47cChris Lattner    LocalChange = false;
120befa499d45ffcc32bd9902518aec18589464e47cChris Lattner    // Iterate over the outer loop because inlining functions can cause indirect
121befa499d45ffcc32bd9902518aec18589464e47cChris Lattner    // calls to become direct calls.
122befa499d45ffcc32bd9902518aec18589464e47cChris Lattner    for (unsigned CSi = 0; CSi != CallSites.size(); ++CSi)
123befa499d45ffcc32bd9902518aec18589464e47cChris Lattner      if (Function *Callee = CallSites[CSi].getCalledFunction()) {
124befa499d45ffcc32bd9902518aec18589464e47cChris Lattner        // Calls to external functions are never inlinable.
125befa499d45ffcc32bd9902518aec18589464e47cChris Lattner        if (Callee->isExternal() ||
126befa499d45ffcc32bd9902518aec18589464e47cChris Lattner            CallSites[CSi].getInstruction()->getParent()->getParent() ==Callee){
127befa499d45ffcc32bd9902518aec18589464e47cChris Lattner          std::swap(CallSites[CSi], CallSites.back());
128b11a99bd39ec12733527bde330302b435b8d9f1aChris Lattner          CallSites.pop_back();
129befa499d45ffcc32bd9902518aec18589464e47cChris Lattner          --CSi;
130befa499d45ffcc32bd9902518aec18589464e47cChris Lattner          continue;
131befa499d45ffcc32bd9902518aec18589464e47cChris Lattner        }
132befa499d45ffcc32bd9902518aec18589464e47cChris Lattner
133befa499d45ffcc32bd9902518aec18589464e47cChris Lattner        // If the policy determines that we should inline this function,
134befa499d45ffcc32bd9902518aec18589464e47cChris Lattner        // try to do so.
135befa499d45ffcc32bd9902518aec18589464e47cChris Lattner        CallSite CS = CallSites[CSi];
136befa499d45ffcc32bd9902518aec18589464e47cChris Lattner        int InlineCost = getInlineCost(CS);
137befa499d45ffcc32bd9902518aec18589464e47cChris Lattner        if (InlineCost >= (int)InlineThreshold) {
138befa499d45ffcc32bd9902518aec18589464e47cChris Lattner          DEBUG(std::cerr << "    NOT Inlining: cost=" << InlineCost
139befa499d45ffcc32bd9902518aec18589464e47cChris Lattner                << ", Call: " << *CS.getInstruction());
140befa499d45ffcc32bd9902518aec18589464e47cChris Lattner        } else {
141befa499d45ffcc32bd9902518aec18589464e47cChris Lattner          DEBUG(std::cerr << "    Inlining: cost=" << InlineCost
142befa499d45ffcc32bd9902518aec18589464e47cChris Lattner                << ", Call: " << *CS.getInstruction());
143befa499d45ffcc32bd9902518aec18589464e47cChris Lattner
144befa499d45ffcc32bd9902518aec18589464e47cChris Lattner          Function *Caller = CS.getInstruction()->getParent()->getParent();
145befa499d45ffcc32bd9902518aec18589464e47cChris Lattner
146befa499d45ffcc32bd9902518aec18589464e47cChris Lattner          // Attempt to inline the function...
147befa499d45ffcc32bd9902518aec18589464e47cChris Lattner          if (InlineCallIfPossible(CS, CG, SCCFunctions)) {
148befa499d45ffcc32bd9902518aec18589464e47cChris Lattner            // Remove this call site from the list.
149befa499d45ffcc32bd9902518aec18589464e47cChris Lattner            std::swap(CallSites[CSi], CallSites.back());
150befa499d45ffcc32bd9902518aec18589464e47cChris Lattner            CallSites.pop_back();
151befa499d45ffcc32bd9902518aec18589464e47cChris Lattner            --CSi;
152befa499d45ffcc32bd9902518aec18589464e47cChris Lattner
153befa499d45ffcc32bd9902518aec18589464e47cChris Lattner            ++NumInlined;
154befa499d45ffcc32bd9902518aec18589464e47cChris Lattner            Changed = true;
155befa499d45ffcc32bd9902518aec18589464e47cChris Lattner            LocalChange = true;
156775cbdd51a3b33dd5eb343689f65ab5cc8ac7118Chris Lattner          }
157237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner        }
158237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner      }
159befa499d45ffcc32bd9902518aec18589464e47cChris Lattner  } while (LocalChange);
160237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner
161775cbdd51a3b33dd5eb343689f65ab5cc8ac7118Chris Lattner  return Changed;
162237ef567f6764f24a47c63121cc0a599ddc8f56dChris Lattner}
163d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
16468d57e7ae80044401efd889270a12c71b3efb9abChris Lattner// doFinalization - Remove now-dead linkonce functions at the end of
16568d57e7ae80044401efd889270a12c71b3efb9abChris Lattner// processing to avoid breaking the SCC traversal.
16668d57e7ae80044401efd889270a12c71b3efb9abChris Lattnerbool Inliner::doFinalization(CallGraph &CG) {
1673e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner  std::set<CallGraphNode*> FunctionsToRemove;
1683e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner
1693e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner  // Scan for all of the functions, looking for ones that should now be removed
1703e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner  // from the program.  Insert the dead ones in the FunctionsToRemove set.
1713e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner  for (CallGraph::iterator I = CG.begin(), E = CG.end(); I != E; ++I) {
1723e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner    CallGraphNode *CGN = I->second;
17368d57e7ae80044401efd889270a12c71b3efb9abChris Lattner    Function *F = CGN ? CGN->getFunction() : 0;
1743e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner
1753e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner    // If the only remaining use of the function is a dead constant
1763e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner    // pointer ref, remove it.
1773e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner    if (F && F->hasOneUse())
1783e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner      if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(F->use_back()))
1793e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner        if (CPR->use_empty()) {
1803e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner          CPR->destroyConstant();
1813e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner          if (F->hasInternalLinkage()) {
1823e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner            // There *MAY* be an edge from the external call node to this
1833e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner            // function.  If so, remove it.
1843e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner            CallGraphNode *EN = CG.getExternalCallingNode();
1853e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner            CallGraphNode::iterator I = std::find(EN->begin(), EN->end(), CGN);
1863e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner            if (I != EN->end()) EN->removeCallEdgeTo(CGN);
1873e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner          }
1883e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner        }
1893e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner
19068d57e7ae80044401efd889270a12c71b3efb9abChris Lattner    if (F && (F->hasLinkOnceLinkage() || F->hasInternalLinkage()) &&
19168d57e7ae80044401efd889270a12c71b3efb9abChris Lattner        F->use_empty()) {
1923e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner      // Remove any call graph edges from the function to its callees.
19368d57e7ae80044401efd889270a12c71b3efb9abChris Lattner      while (CGN->begin() != CGN->end())
19468d57e7ae80044401efd889270a12c71b3efb9abChris Lattner        CGN->removeCallEdgeTo(*(CGN->end()-1));
19568d57e7ae80044401efd889270a12c71b3efb9abChris Lattner
1963e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner      // If the function has external linkage (basically if it's a linkonce
1973e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner      // function) remove the edge from the external node to the callee node.
19868d57e7ae80044401efd889270a12c71b3efb9abChris Lattner      if (!F->hasInternalLinkage())
19968d57e7ae80044401efd889270a12c71b3efb9abChris Lattner        CG.getExternalCallingNode()->removeCallEdgeTo(CGN);
20068d57e7ae80044401efd889270a12c71b3efb9abChris Lattner
20168d57e7ae80044401efd889270a12c71b3efb9abChris Lattner      // Removing the node for callee from the call graph and delete it.
2023e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner      FunctionsToRemove.insert(CGN);
20368d57e7ae80044401efd889270a12c71b3efb9abChris Lattner    }
20468d57e7ae80044401efd889270a12c71b3efb9abChris Lattner  }
2053e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner
2063e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner  // Now that we know which functions to delete, do so.  We didn't want to do
2073e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner  // this inline, because that would invalidate our CallGraph::iterator
2083e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner  // objects. :(
2093e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner  bool Changed = false;
2103e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner  for (std::set<CallGraphNode*>::iterator I = FunctionsToRemove.begin(),
2113e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner         E = FunctionsToRemove.end(); I != E; ++I) {
2123e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner    delete CG.removeFunctionFromModule(*I);
2133e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner    ++NumDeleted;
2143e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner    Changed = true;
2153e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner  }
2163e1358a9fa1ebd3f51c94eb69da55d693895fe7cChris Lattner
21768d57e7ae80044401efd889270a12c71b3efb9abChris Lattner  return Changed;
21868d57e7ae80044401efd889270a12c71b3efb9abChris Lattner}
219