summaryrefslogtreecommitdiff
path: root/tools/bugpoint/ExtractFunction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/bugpoint/ExtractFunction.cpp')
-rw-r--r--tools/bugpoint/ExtractFunction.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp
new file mode 100644
index 0000000000..76b2258f8a
--- /dev/null
+++ b/tools/bugpoint/ExtractFunction.cpp
@@ -0,0 +1,34 @@
+//===- ExtractFunction.cpp - Extract a function from Program --------------===//
+//
+// This file implements a method that extracts a function from program, cleans
+// it up, and returns it as a new module.
+//
+//===----------------------------------------------------------------------===//
+
+#include "BugDriver.h"
+#include "llvm/Module.h"
+#include "llvm/PassManager.h"
+#include "llvm/Transforms/IPO.h"
+#include "llvm/Transforms/Utils/Cloning.h"
+
+/// extractFunctionFromModule - This method is used to extract the specified
+/// (non-external) function from the current program, slim down the module, and
+/// then return it. This does not modify Program at all, it modifies a copy,
+/// which it returns.
+Module *BugDriver::extractFunctionFromModule(Function *F) const {
+ Module *Result = CloneModule(Program);
+
+ // Translate from the old module to the new copied module...
+ F = Result->getFunction(F->getName(), F->getFunctionType());
+
+ // In addition to just parsing the input from GCC, we also want to spiff it up
+ // a little bit. Do this now.
+ //
+ PassManager Passes;
+ Passes.add(createFunctionExtractionPass(F)); // Extract the function
+ Passes.add(createGlobalDCEPass()); // Delete unreachable globals
+ Passes.add(createFunctionResolvingPass()); // Delete prototypes
+ Passes.add(createDeadTypeEliminationPass()); // Remove dead types...
+ Passes.run(*Result);
+ return Result;
+}