1 //===- ExtractFunction.cpp - Extract a function from Program --------------===//
3 // This file implements a method that extracts a function from program, cleans
4 // it up, and returns it as a new module.
6 //===----------------------------------------------------------------------===//
9 #include "llvm/Module.h"
10 #include "llvm/PassManager.h"
11 #include "llvm/Transforms/IPO.h"
12 #include "llvm/Transforms/Utils/Cloning.h"
14 /// extractFunctionFromModule - This method is used to extract the specified
15 /// (non-external) function from the current program, slim down the module, and
16 /// then return it. This does not modify Program at all, it modifies a copy,
18 Module *BugDriver::extractFunctionFromModule(Function *F) const {
19 Module *Result = CloneModule(Program);
21 // Translate from the old module to the new copied module...
22 F = Result->getFunction(F->getName(), F->getFunctionType());
24 // In addition to just parsing the input from GCC, we also want to spiff it up
25 // a little bit. Do this now.
28 Passes.add(createFunctionExtractionPass(F)); // Extract the function
29 Passes.add(createGlobalDCEPass()); // Delete unreachable globals
30 Passes.add(createFunctionResolvingPass()); // Delete prototypes
31 Passes.add(createDeadTypeEliminationPass()); // Remove dead types...