summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-03-14 20:02:07 +0000
committerChris Lattner <sabre@nondot.org>2004-03-14 20:02:07 +0000
commit3fe96bc9fd0e246a3d1467d24d47cb85b5d95a6c (patch)
tree62671f94d1ab4fa1a52d6074b58a7256d8c3222b
parenta1672c1bd8ffab07924ba221e726e8d174f28484 (diff)
downloadbcm5719-llvm-3fe96bc9fd0e246a3d1467d24d47cb85b5d95a6c.tar.gz
bcm5719-llvm-3fe96bc9fd0e246a3d1467d24d47cb85b5d95a6c.zip
Add a method to extract a loop
llvm-svn: 12391
-rw-r--r--llvm/tools/bugpoint/BugDriver.h5
-rw-r--r--llvm/tools/bugpoint/ExtractFunction.cpp38
2 files changed, 42 insertions, 1 deletions
diff --git a/llvm/tools/bugpoint/BugDriver.h b/llvm/tools/bugpoint/BugDriver.h
index f15481fde72..eb48eb7d9c3 100644
--- a/llvm/tools/bugpoint/BugDriver.h
+++ b/llvm/tools/bugpoint/BugDriver.h
@@ -178,6 +178,11 @@ public:
///
Module *performFinalCleanups(Module *M, bool MayModifySemantics = false);
+ /// ExtractLoop - Given a module, extract up to one loop from it into a new
+ /// function. This returns null if there are no extractable loops in the
+ /// program or if the loop extractor crashes.
+ Module *ExtractLoop(Module *M);
+
private:
/// ParseInputFile - Given a bytecode or assembly input filename, parse and
/// return it, or return null if not possible.
diff --git a/llvm/tools/bugpoint/ExtractFunction.cpp b/llvm/tools/bugpoint/ExtractFunction.cpp
index 41b5641ff50..8e392613c93 100644
--- a/llvm/tools/bugpoint/ExtractFunction.cpp
+++ b/llvm/tools/bugpoint/ExtractFunction.cpp
@@ -117,7 +117,7 @@ Module *BugDriver::performFinalCleanups(Module *M, bool MayModifySemantics) {
std::swap(Program, M);
if (Failed) {
- std::cerr << "Final cleanups failed. Sorry. :(\n";
+ std::cerr << "Final cleanups failed. Sorry. :( Please report a bug!\n";
} else {
delete M;
M = ParseInputFile(Filename);
@@ -132,6 +132,42 @@ Module *BugDriver::performFinalCleanups(Module *M, bool MayModifySemantics) {
}
+/// ExtractLoop - Given a module, extract up to one loop from it into a new
+/// function. This returns null if there are no extractable loops in the
+/// program or if the loop extractor crashes.
+Module *BugDriver::ExtractLoop(Module *M) {
+ std::vector<const PassInfo*> LoopExtractPasses;
+ LoopExtractPasses.push_back(getPI(createSingleLoopExtractorPass()));
+
+ std::swap(Program, M);
+ std::string Filename;
+ bool Failed = runPasses(LoopExtractPasses, Filename);
+ std::swap(Program, M);
+
+ if (Failed) {
+ std::cerr << "Loop extraction failed. Sorry. :( Please report a bug!\n";
+ return 0;
+ } else {
+ Module *NewM = ParseInputFile(Filename);
+ if (NewM == 0) {
+ std::cerr << getToolName() << ": Error reading bytecode file '"
+ << Filename << "'!\n";
+ exit(1);
+ }
+ removeFile(Filename);
+
+ // Check to see if we created any new functions. If not, no loops were
+ // extracted and we should return null.
+ if (M->size() != NewM->size()) {
+ delete NewM;
+ return 0;
+ }
+
+ return NewM;
+ }
+}
+
+
// DeleteFunctionBody - "Remove" the function by deleting all of its basic
// blocks, making it external.
//
OpenPOWER on IntegriCloud