Add a method to extract a loop
authorChris Lattner <sabre@nondot.org>
Sun, 14 Mar 2004 20:02:07 +0000 (20:02 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 14 Mar 2004 20:02:07 +0000 (20:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12391 91177308-0d34-0410-b5e6-96231b3b80d8

tools/bugpoint/BugDriver.h
tools/bugpoint/ExtractFunction.cpp

index f15481fde726bfd001874485a49f19829a914868..eb48eb7d9c31cbeca28da09aa355590a2fa0dfaf 100644 (file)
@@ -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.
index 41b5641ff50630db69a7d4a01184087bca276b17..8e392613c933e882a47056f6093c35204ce8d63b 100644 (file)
@@ -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.
 //