ExtractFunction.cpp revision 7546c3884a400b72d10fc19f120c6798b294a39d
1afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner//===- ExtractFunction.cpp - Extract a function from Program --------------===//
27c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell//
37c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell//                     The LLVM Compiler Infrastructure
47c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell//
57c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell// This file was developed by the LLVM research group and is distributed under
67c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell// the University of Illinois Open Source License. See LICENSE.TXT for details.
77c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell//
87c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell//===----------------------------------------------------------------------===//
9afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner//
10afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner// This file implements a method that extracts a function from program, cleans
11afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner// it up, and returns it as a new module.
12afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner//
13afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner//===----------------------------------------------------------------------===//
14afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
15afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner#include "BugDriver.h"
16e49603d79d220a795bd50684c8b1f503ee40f97fMisha Brukman#include "llvm/Constant.h"
17afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner#include "llvm/Module.h"
18afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner#include "llvm/PassManager.h"
19d1a85a744cc1001c2b7fc37cf37aca266964f519Brian Gaeke#include "llvm/Pass.h"
20e49603d79d220a795bd50684c8b1f503ee40f97fMisha Brukman#include "llvm/Type.h"
21e49603d79d220a795bd50684c8b1f503ee40f97fMisha Brukman#include "llvm/Analysis/Verifier.h"
22afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner#include "llvm/Transforms/IPO.h"
236520785dcd22012535934098942d57c07c7631c2Chris Lattner#include "llvm/Transforms/Scalar.h"
24afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner#include "llvm/Transforms/Utils/Cloning.h"
255da69c79f9c4490c6657c207430dfeb1060fc4ddChris Lattner#include "llvm/Target/TargetData.h"
266db70ef879916e6115ac97eb76e4fea973652e2cChris Lattner#include "Support/CommandLine.h"
27be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner#include "Support/Debug.h"
281b747167daf07a98f0ec33144b257c987c60e11dChris Lattner#include "Support/FileUtilities.h"
29c6b519d64ef55d39e66a49510d4703a49bf228ccChris Lattnerusing namespace llvm;
30d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
31d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
32c6b519d64ef55d39e66a49510d4703a49bf228ccChris Lattner  bool DisableSimplifyCFG = false;
33d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace
34d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
356db70ef879916e6115ac97eb76e4fea973652e2cChris Lattnernamespace {
366db70ef879916e6115ac97eb76e4fea973652e2cChris Lattner  cl::opt<bool>
376db70ef879916e6115ac97eb76e4fea973652e2cChris Lattner  NoDCE ("disable-dce",
386db70ef879916e6115ac97eb76e4fea973652e2cChris Lattner         cl::desc("Do not use the -dce pass to reduce testcases"));
3947ae4a1cee5eec5767a11403c0fac7c91ec45461Chris Lattner  cl::opt<bool, true>
4047ae4a1cee5eec5767a11403c0fac7c91ec45461Chris Lattner  NoSCFG("disable-simplifycfg", cl::location(DisableSimplifyCFG),
416db70ef879916e6115ac97eb76e4fea973652e2cChris Lattner         cl::desc("Do not use the -simplifycfg pass to reduce testcases"));
426db70ef879916e6115ac97eb76e4fea973652e2cChris Lattner}
43afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
446520785dcd22012535934098942d57c07c7631c2Chris Lattner/// deleteInstructionFromProgram - This method clones the current Program and
456520785dcd22012535934098942d57c07c7631c2Chris Lattner/// deletes the specified instruction from the cloned module.  It then runs a
466520785dcd22012535934098942d57c07c7631c2Chris Lattner/// series of cleanup passes (ADCE and SimplifyCFG) to eliminate any code which
476520785dcd22012535934098942d57c07c7631c2Chris Lattner/// depends on the value.  The modified module is then returned.
486520785dcd22012535934098942d57c07c7631c2Chris Lattner///
490cc8807029f577996a442b96d24c3346ed6de091Chris LattnerModule *BugDriver::deleteInstructionFromProgram(const Instruction *I,
506520785dcd22012535934098942d57c07c7631c2Chris Lattner                                                unsigned Simplification) const {
516520785dcd22012535934098942d57c07c7631c2Chris Lattner  Module *Result = CloneModule(Program);
526520785dcd22012535934098942d57c07c7631c2Chris Lattner
530cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  const BasicBlock *PBB = I->getParent();
540cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  const Function *PF = PBB->getParent();
556520785dcd22012535934098942d57c07c7631c2Chris Lattner
566520785dcd22012535934098942d57c07c7631c2Chris Lattner  Module::iterator RFI = Result->begin(); // Get iterator to corresponding fn
570cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  std::advance(RFI, std::distance(PF->getParent()->begin(),
580cc8807029f577996a442b96d24c3346ed6de091Chris Lattner                                  Module::const_iterator(PF)));
596520785dcd22012535934098942d57c07c7631c2Chris Lattner
606520785dcd22012535934098942d57c07c7631c2Chris Lattner  Function::iterator RBI = RFI->begin();  // Get iterator to corresponding BB
610cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  std::advance(RBI, std::distance(PF->begin(), Function::const_iterator(PBB)));
626520785dcd22012535934098942d57c07c7631c2Chris Lattner
636520785dcd22012535934098942d57c07c7631c2Chris Lattner  BasicBlock::iterator RI = RBI->begin(); // Get iterator to corresponding inst
640cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  std::advance(RI, std::distance(PBB->begin(), BasicBlock::const_iterator(I)));
650cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  Instruction *TheInst = RI;              // Got the corresponding instruction!
666520785dcd22012535934098942d57c07c7631c2Chris Lattner
676520785dcd22012535934098942d57c07c7631c2Chris Lattner  // If this instruction produces a value, replace any users with null values
680cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  if (TheInst->getType() != Type::VoidTy)
690cc8807029f577996a442b96d24c3346ed6de091Chris Lattner    TheInst->replaceAllUsesWith(Constant::getNullValue(TheInst->getType()));
706520785dcd22012535934098942d57c07c7631c2Chris Lattner
716520785dcd22012535934098942d57c07c7631c2Chris Lattner  // Remove the instruction from the program.
720cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  TheInst->getParent()->getInstList().erase(TheInst);
736520785dcd22012535934098942d57c07c7631c2Chris Lattner
7444be25716628941b4cccccf56a28ee0ba2606850Chris Lattner  // Spiff up the output a little bit.
756520785dcd22012535934098942d57c07c7631c2Chris Lattner  PassManager Passes;
765da69c79f9c4490c6657c207430dfeb1060fc4ddChris Lattner  // Make sure that the appropriate target data is always used...
775da69c79f9c4490c6657c207430dfeb1060fc4ddChris Lattner  Passes.add(new TargetData("bugpoint", Result));
785da69c79f9c4490c6657c207430dfeb1060fc4ddChris Lattner
796db70ef879916e6115ac97eb76e4fea973652e2cChris Lattner  if (Simplification > 1 && !NoDCE)
806520785dcd22012535934098942d57c07c7631c2Chris Lattner    Passes.add(createDeadCodeEliminationPass());
8147ae4a1cee5eec5767a11403c0fac7c91ec45461Chris Lattner  if (Simplification && !DisableSimplifyCFG)
826520785dcd22012535934098942d57c07c7631c2Chris Lattner    Passes.add(createCFGSimplificationPass());      // Delete dead control flow
8310f22cb1a0f2755050218cd0e07221a0985c6b63Chris Lattner
8410f22cb1a0f2755050218cd0e07221a0985c6b63Chris Lattner  Passes.add(createVerifierPass());
856520785dcd22012535934098942d57c07c7631c2Chris Lattner  Passes.run(*Result);
866520785dcd22012535934098942d57c07c7631c2Chris Lattner  return Result;
876520785dcd22012535934098942d57c07c7631c2Chris Lattner}
88ba386d943f4a83095d9c625cb0d46c1afe45ed1fChris Lattner
89fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattnerstatic const PassInfo *getPI(Pass *P) {
90fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner  const PassInfo *PI = P->getPassInfo();
91fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner  delete P;
92fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner  return PI;
93fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner}
94fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner
95ba386d943f4a83095d9c625cb0d46c1afe45ed1fChris Lattner/// performFinalCleanups - This method clones the current Program and performs
96ba386d943f4a83095d9c625cb0d46c1afe45ed1fChris Lattner/// a series of cleanups intended to get rid of extra cruft on the module
97ba386d943f4a83095d9c625cb0d46c1afe45ed1fChris Lattner/// before handing it to the user...
98ba386d943f4a83095d9c625cb0d46c1afe45ed1fChris Lattner///
99fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris LattnerModule *BugDriver::performFinalCleanups(Module *M, bool MayModifySemantics) {
10028b8ed90c75ce6c271500fa778fef252f267a5ffChris Lattner  // Make all functions external, so GlobalDCE doesn't delete them...
10128b8ed90c75ce6c271500fa778fef252f267a5ffChris Lattner  for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
10228b8ed90c75ce6c271500fa778fef252f267a5ffChris Lattner    I->setLinkage(GlobalValue::ExternalLinkage);
103dbe48dcaec69ff78e39e2d5faf4323ade6fffb04Chris Lattner
104fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner  std::vector<const PassInfo*> CleanupPasses;
105fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner  CleanupPasses.push_back(getPI(createFunctionResolvingPass()));
106fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner  CleanupPasses.push_back(getPI(createGlobalDCEPass()));
107fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner  CleanupPasses.push_back(getPI(createDeadTypeEliminationPass()));
108fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner
109c6b519d64ef55d39e66a49510d4703a49bf228ccChris Lattner  if (MayModifySemantics)
110c6b519d64ef55d39e66a49510d4703a49bf228ccChris Lattner    CleanupPasses.push_back(getPI(createDeadArgHackingPass()));
111c6b519d64ef55d39e66a49510d4703a49bf228ccChris Lattner  else
112c6b519d64ef55d39e66a49510d4703a49bf228ccChris Lattner    CleanupPasses.push_back(getPI(createDeadArgEliminationPass()));
113c6b519d64ef55d39e66a49510d4703a49bf228ccChris Lattner
114fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner  std::swap(Program, M);
115fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner  std::string Filename;
116fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner  bool Failed = runPasses(CleanupPasses, Filename);
117fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner  std::swap(Program, M);
118fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner
119fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner  if (Failed) {
1207546c3884a400b72d10fc19f120c6798b294a39dChris Lattner    std::cerr << "Final cleanups failed.  Sorry. :(  Please report a bug!\n";
121fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner  } else {
122fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner    delete M;
123fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner    M = ParseInputFile(Filename);
124fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner    if (M == 0) {
125fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner      std::cerr << getToolName() << ": Error reading bytecode file '"
126fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner                << Filename << "'!\n";
127fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner      exit(1);
128fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner    }
1291b747167daf07a98f0ec33144b257c987c60e11dChris Lattner    removeFile(Filename);
130fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner  }
131fcb6ec0c7e37c2d15ddb04878f05cbd69d1da036Chris Lattner  return M;
132ba386d943f4a83095d9c625cb0d46c1afe45ed1fChris Lattner}
133be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner
134be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner
1357546c3884a400b72d10fc19f120c6798b294a39dChris Lattner/// ExtractLoop - Given a module, extract up to one loop from it into a new
1367546c3884a400b72d10fc19f120c6798b294a39dChris Lattner/// function.  This returns null if there are no extractable loops in the
1377546c3884a400b72d10fc19f120c6798b294a39dChris Lattner/// program or if the loop extractor crashes.
1387546c3884a400b72d10fc19f120c6798b294a39dChris LattnerModule *BugDriver::ExtractLoop(Module *M) {
1397546c3884a400b72d10fc19f120c6798b294a39dChris Lattner  std::vector<const PassInfo*> LoopExtractPasses;
1407546c3884a400b72d10fc19f120c6798b294a39dChris Lattner  LoopExtractPasses.push_back(getPI(createSingleLoopExtractorPass()));
1417546c3884a400b72d10fc19f120c6798b294a39dChris Lattner
1427546c3884a400b72d10fc19f120c6798b294a39dChris Lattner  std::swap(Program, M);
1437546c3884a400b72d10fc19f120c6798b294a39dChris Lattner  std::string Filename;
1447546c3884a400b72d10fc19f120c6798b294a39dChris Lattner  bool Failed = runPasses(LoopExtractPasses, Filename);
1457546c3884a400b72d10fc19f120c6798b294a39dChris Lattner  std::swap(Program, M);
1467546c3884a400b72d10fc19f120c6798b294a39dChris Lattner
1477546c3884a400b72d10fc19f120c6798b294a39dChris Lattner  if (Failed) {
1487546c3884a400b72d10fc19f120c6798b294a39dChris Lattner    std::cerr << "Loop extraction failed.  Sorry. :(  Please report a bug!\n";
1497546c3884a400b72d10fc19f120c6798b294a39dChris Lattner    return 0;
1507546c3884a400b72d10fc19f120c6798b294a39dChris Lattner  } else {
1517546c3884a400b72d10fc19f120c6798b294a39dChris Lattner    Module *NewM = ParseInputFile(Filename);
1527546c3884a400b72d10fc19f120c6798b294a39dChris Lattner    if (NewM == 0) {
1537546c3884a400b72d10fc19f120c6798b294a39dChris Lattner      std::cerr << getToolName() << ": Error reading bytecode file '"
1547546c3884a400b72d10fc19f120c6798b294a39dChris Lattner                << Filename << "'!\n";
1557546c3884a400b72d10fc19f120c6798b294a39dChris Lattner      exit(1);
1567546c3884a400b72d10fc19f120c6798b294a39dChris Lattner    }
1577546c3884a400b72d10fc19f120c6798b294a39dChris Lattner    removeFile(Filename);
1587546c3884a400b72d10fc19f120c6798b294a39dChris Lattner
1597546c3884a400b72d10fc19f120c6798b294a39dChris Lattner    // Check to see if we created any new functions.  If not, no loops were
1607546c3884a400b72d10fc19f120c6798b294a39dChris Lattner    // extracted and we should return null.
1617546c3884a400b72d10fc19f120c6798b294a39dChris Lattner    if (M->size() != NewM->size()) {
1627546c3884a400b72d10fc19f120c6798b294a39dChris Lattner      delete NewM;
1637546c3884a400b72d10fc19f120c6798b294a39dChris Lattner      return 0;
1647546c3884a400b72d10fc19f120c6798b294a39dChris Lattner    }
1657546c3884a400b72d10fc19f120c6798b294a39dChris Lattner
1667546c3884a400b72d10fc19f120c6798b294a39dChris Lattner    return NewM;
1677546c3884a400b72d10fc19f120c6798b294a39dChris Lattner  }
1687546c3884a400b72d10fc19f120c6798b294a39dChris Lattner}
1697546c3884a400b72d10fc19f120c6798b294a39dChris Lattner
1707546c3884a400b72d10fc19f120c6798b294a39dChris Lattner
171be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner// DeleteFunctionBody - "Remove" the function by deleting all of its basic
172be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner// blocks, making it external.
173be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner//
174be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattnervoid llvm::DeleteFunctionBody(Function *F) {
175be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner  // delete the body of the function...
176be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner  F->deleteBody();
177be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner  assert(F->isExternal() && "This didn't make the function external!");
178be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner}
179be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner
180be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner/// SplitFunctionsOutOfModule - Given a module and a list of functions in the
181be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner/// module, split the functions OUT of the specified module, and place them in
182be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner/// the new module.
1835eda1f2f65941a24ef9a5a85addf4d90eb13fa9dChris Lattner///
1845eda1f2f65941a24ef9a5a85addf4d90eb13fa9dChris Lattner/// FIXME: this could be made DRAMATICALLY more efficient for large programs if
1855eda1f2f65941a24ef9a5a85addf4d90eb13fa9dChris Lattner/// we just MOVED functions from one module to the other, instead of cloning the
1865eda1f2f65941a24ef9a5a85addf4d90eb13fa9dChris Lattner/// whole module, then proceeding to delete an entire module's worth of stuff.
1875eda1f2f65941a24ef9a5a85addf4d90eb13fa9dChris Lattner///
188be21ca54e08339ede5dd4bbb882182d22e274988Chris LattnerModule *llvm::SplitFunctionsOutOfModule(Module *M,
189be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner                                        const std::vector<Function*> &F) {
190be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner  // Make sure functions & globals are all external so that linkage
191be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner  // between the two modules will work.
192be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner  for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
193be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner    I->setLinkage(GlobalValue::ExternalLinkage);
194be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner  for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I)
195be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner    I->setLinkage(GlobalValue::ExternalLinkage);
196be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner
197be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner  Module *New = CloneModule(M);
198be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner
199be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner  // Make sure global initializers exist only in the safe module (CBE->.so)
200be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner  for (Module::giterator I = New->gbegin(), E = New->gend(); I != E; ++I)
201be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner    I->setInitializer(0);  // Delete the initializer to make it external
202be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner
203be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner  // Remove the Test functions from the Safe module
204be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner  for (unsigned i = 0, e = F.size(); i != e; ++i) {
205be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner    Function *TNOF = M->getFunction(F[i]->getName(), F[i]->getFunctionType());
206be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner    DEBUG(std::cerr << "Removing function " << F[i]->getName() << "\n");
207be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner    assert(TNOF && "Function doesn't exist in module!");
208be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner    DeleteFunctionBody(TNOF);       // Function is now external in this module!
209be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner  }
210be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner
211be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner  // Remove the Safe functions from the Test module
212be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner  for (Module::iterator I = New->begin(), E = New->end(); I != E; ++I) {
213be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner    bool funcFound = false;
214be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner    for (std::vector<Function*>::const_iterator FI = F.begin(), Fe = F.end();
215be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner         FI != Fe; ++FI)
216be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner      if (I->getName() == (*FI)->getName()) funcFound = true;
217be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner
218be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner    if (!funcFound)
219be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner      DeleteFunctionBody(I);
220be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner  }
221be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner  return New;
222be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner}
223