[llvm-commits] CVS: llvm/tools/bugpoint/BugDriver.h CrashDebugger.cpp ListReducer.h Miscompilation.cpp bugpoint.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Aug 1 19:16:28 PDT 2005



Changes in directory llvm/tools/bugpoint:

BugDriver.h updated: 1.40 -> 1.41
CrashDebugger.cpp updated: 1.44 -> 1.45
ListReducer.h updated: 1.13 -> 1.14
Miscompilation.cpp updated: 1.69 -> 1.70
bugpoint.cpp updated: 1.24 -> 1.25
---
Log message:

When the user hits ctrl-c, bugpoint should attempt to stop reduction as
quickly as possible and output what it has so far.  If they hit it twice,
bugpoint is killed.


---
Diffs of the changes:  (+60 -31)

 BugDriver.h        |    4 ++++
 CrashDebugger.cpp  |   43 +++++++++++++++++++++----------------------
 ListReducer.h      |   13 +++++++++++++
 Miscompilation.cpp |   21 +++++++++++++--------
 bugpoint.cpp       |   10 +++++++++-
 5 files changed, 60 insertions(+), 31 deletions(-)


Index: llvm/tools/bugpoint/BugDriver.h
diff -u llvm/tools/bugpoint/BugDriver.h:1.40 llvm/tools/bugpoint/BugDriver.h:1.41
--- llvm/tools/bugpoint/BugDriver.h:1.40	Thu Apr 21 23:13:13 2005
+++ llvm/tools/bugpoint/BugDriver.h	Mon Aug  1 21:16:17 2005
@@ -35,6 +35,10 @@
 
 extern bool DisableSimplifyCFG;
 
+/// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
+///
+extern bool BugpointIsInterrupted;
+
 class BugDriver {
   const std::string ToolName;  // Name of bugpoint
   std::string ReferenceOutputFile; // Name of `good' output file


Index: llvm/tools/bugpoint/CrashDebugger.cpp
diff -u llvm/tools/bugpoint/CrashDebugger.cpp:1.44 llvm/tools/bugpoint/CrashDebugger.cpp:1.45
--- llvm/tools/bugpoint/CrashDebugger.cpp:1.44	Thu Jul  7 22:08:58 2005
+++ llvm/tools/bugpoint/CrashDebugger.cpp	Mon Aug  1 21:16:17 2005
@@ -261,8 +261,6 @@
 /// on a program, try to destructively reduce the program while still keeping
 /// the predicate true.
 static bool DebugACrash(BugDriver &BD,  bool (*TestFn)(BugDriver &, Module *)) {
-  bool AnyReduction = false;
-
   // See if we can get away with nuking all of the global variable initializers
   // in the program...
   if (BD.getProgram()->global_begin() != BD.getProgram()->global_end()) {
@@ -282,7 +280,6 @@
       std::cout << "\nChecking to see if we can delete global inits: ";
       if (TestFn(BD, M)) {  // Still crashes?
         BD.setNewProgram(M);
-        AnyReduction = true;
         std::cout << "\n*** Able to remove all global initializers!\n";
       } else {                       // No longer crashes?
         std::cout << "  - Removing all global inits hides problem!\n";
@@ -298,17 +295,15 @@
     if (!I->isExternal())
       Functions.push_back(I);
 
-  if (Functions.size() > 1) {
+  if (Functions.size() > 1 && !BugpointIsInterrupted) {
     std::cout << "\n*** Attempting to reduce the number of functions "
       "in the testcase\n";
 
     unsigned OldSize = Functions.size();
     ReduceCrashingFunctions(BD, TestFn).reduceList(Functions);
 
-    if (Functions.size() < OldSize) {
+    if (Functions.size() < OldSize)
       BD.EmitProgressBytecode("reduced-function");
-      AnyReduction = true;
-    }
   }
 
   // Attempt to delete entire basic blocks at a time to speed up
@@ -316,7 +311,7 @@
   // to a return instruction then running simplifycfg, which can potentially
   // shrinks the code dramatically quickly
   //
-  if (!DisableSimplifyCFG) {
+  if (!DisableSimplifyCFG && !BugpointIsInterrupted) {
     std::vector<const BasicBlock*> Blocks;
     for (Module::const_iterator I = BD.getProgram()->begin(),
            E = BD.getProgram()->end(); I != E; ++I)
@@ -329,6 +324,7 @@
   // larger chunks of instructions at a time!
   unsigned Simplification = 2;
   do {
+    if (BugpointIsInterrupted) break;
     --Simplification;
     std::cout << "\n*** Attempting to reduce testcase by deleting instruc"
               << "tions: Simplification Level #" << Simplification << '\n';
@@ -357,6 +353,8 @@
             if (InstructionsToSkipBeforeDeleting) {
               --InstructionsToSkipBeforeDeleting;
             } else {
+              if (BugpointIsInterrupted) goto ExitLoops;
+
               std::cout << "Checking instruction '" << I->getName() << "': ";
               Module *M = BD.deleteInstructionFromProgram(I, Simplification);
 
@@ -365,7 +363,6 @@
                 // Yup, it does, we delete the old module, and continue trying
                 // to reduce the testcase...
                 BD.setNewProgram(M);
-                AnyReduction = true;
                 InstructionsToSkipBeforeDeleting = CurInstructionNum;
                 goto TryAgain;  // I wish I had a multi-level break here!
               }
@@ -381,22 +378,23 @@
     }
 
   } while (Simplification);
+ExitLoops:
 
   // Try to clean up the testcase by running funcresolve and globaldce...
-  std::cout << "\n*** Attempting to perform final cleanups: ";
-  Module *M = CloneModule(BD.getProgram());
-  M = BD.performFinalCleanups(M, true);
-
-  // Find out if the pass still crashes on the cleaned up program...
-  if (TestFn(BD, M)) {
-    BD.setNewProgram(M);     // Yup, it does, keep the reduced version...
-    AnyReduction = true;
-  } else {
-    delete M;
+  if (!BugpointIsInterrupted) {
+    std::cout << "\n*** Attempting to perform final cleanups: ";
+    Module *M = CloneModule(BD.getProgram());
+    M = BD.performFinalCleanups(M, true);
+
+    // Find out if the pass still crashes on the cleaned up program...
+    if (TestFn(BD, M)) {
+      BD.setNewProgram(M);     // Yup, it does, keep the reduced version...
+    } else {
+      delete M;
+    }
   }
 
-  if (AnyReduction)
-    BD.EmitProgressBytecode("reduced-simplified");
+  BD.EmitProgressBytecode("reduced-simplified");
 
   return false;
 }
@@ -414,7 +412,8 @@
 
   // Reduce the list of passes which causes the optimizer to crash...
   unsigned OldSize = PassesToRun.size();
-  ReducePassList(*this).reduceList(PassesToRun);
+  if (!BugpointIsInterrupted)
+    ReducePassList(*this).reduceList(PassesToRun);
 
   std::cout << "\n*** Found crashing pass"
             << (PassesToRun.size() == 1 ? ": " : "es: ")


Index: llvm/tools/bugpoint/ListReducer.h
diff -u llvm/tools/bugpoint/ListReducer.h:1.13 llvm/tools/bugpoint/ListReducer.h:1.14
--- llvm/tools/bugpoint/ListReducer.h:1.13	Thu Apr 21 18:59:23 2005
+++ llvm/tools/bugpoint/ListReducer.h	Mon Aug  1 21:16:17 2005
@@ -19,6 +19,8 @@
 #include <iostream>
 
 namespace llvm {
+  
+  extern bool BugpointIsInterrupted;
 
 template<typename ElTy>
 struct ListReducer {
@@ -62,6 +64,12 @@
 
     unsigned MidTop = TheList.size();
     while (MidTop > 1) {
+      // Halt if the user presses ctrl-c.
+      if (BugpointIsInterrupted) {
+        std::cerr << "\n\n*** Reduction Interrupted, cleaning up...\n\n";
+        return true;
+      }
+      
       unsigned Mid = MidTop / 2;
       std::vector<ElTy> Prefix(TheList.begin(), TheList.begin()+Mid);
       std::vector<ElTy> Suffix(TheList.begin()+Mid, TheList.end());
@@ -97,6 +105,11 @@
         Changed = false;
         std::vector<ElTy> TrimmedList;
         for (unsigned i = 1; i < TheList.size()-1; ++i) { // Check interior elts
+          if (BugpointIsInterrupted) {
+            std::cerr << "\n\n*** Reduction Interrupted, cleaning up...\n\n";
+            return true;
+          }
+          
           std::vector<ElTy> TestList(TheList);
           TestList.erase(TestList.begin()+i);
 


Index: llvm/tools/bugpoint/Miscompilation.cpp
diff -u llvm/tools/bugpoint/Miscompilation.cpp:1.69 llvm/tools/bugpoint/Miscompilation.cpp:1.70
--- llvm/tools/bugpoint/Miscompilation.cpp:1.69	Wed Jul 27 01:12:34 2005
+++ llvm/tools/bugpoint/Miscompilation.cpp	Mon Aug  1 21:16:17 2005
@@ -407,6 +407,8 @@
 static bool ExtractBlocks(BugDriver &BD,
                           bool (*TestFn)(BugDriver &, Module *, Module *),
                           std::vector<Function*> &MiscompiledFunctions) {
+  if (BugpointIsInterrupted) return false;
+  
   std::vector<BasicBlock*> Blocks;
   for (unsigned i = 0, e = MiscompiledFunctions.size(); i != e; ++i)
     for (Function::iterator I = MiscompiledFunctions[i]->begin(),
@@ -493,7 +495,8 @@
       MiscompiledFunctions.push_back(I);
 
   // Do the reduction...
-  ReduceMiscompilingFunctions(BD, TestFn).reduceList(MiscompiledFunctions);
+  if (!BugpointIsInterrupted)
+    ReduceMiscompilingFunctions(BD, TestFn).reduceList(MiscompiledFunctions);
 
   std::cout << "\n*** The following function"
             << (MiscompiledFunctions.size() == 1 ? " is" : "s are")
@@ -513,7 +516,8 @@
     DisambiguateGlobalSymbols(BD.getProgram());
 
     // Do the reduction...
-    ReduceMiscompilingFunctions(BD, TestFn).reduceList(MiscompiledFunctions);
+    if (!BugpointIsInterrupted)
+      ReduceMiscompilingFunctions(BD, TestFn).reduceList(MiscompiledFunctions);
 
     std::cout << "\n*** The following function"
               << (MiscompiledFunctions.size() == 1 ? " is" : "s are")
@@ -570,11 +574,12 @@
 ///
 bool BugDriver::debugMiscompilation() {
   // Make sure something was miscompiled...
-  if (!ReduceMiscompilingPasses(*this).reduceList(PassesToRun)) {
-    std::cerr << "*** Optimized program matches reference output!  No problem "
-              << "detected...\nbugpoint can't help you with your problem!\n";
-    return false;
-  }
+  if (!BugpointIsInterrupted)
+    if (!ReduceMiscompilingPasses(*this).reduceList(PassesToRun)) {
+      std::cerr << "*** Optimized program matches reference output!  No problem"
+                << " detected...\nbugpoint can't help you with your problem!\n";
+      return false;
+    }
 
   std::cout << "\n*** Found miscompiling pass"
             << (getPassesToRun().size() == 1 ? "" : "es") << ": "
@@ -663,7 +668,7 @@
   for (Module::iterator F = Safe->begin(), E = Safe->end(); F != E; ++F) {
     if (F->isExternal() && !F->use_empty() && &*F != resolverFunc &&
         F->getIntrinsicID() == 0 /* ignore intrinsics */) {
-      Function *TestFn = Test->getFunction(F->getName(), F->getFunctionType());
+      Function *TestFn = Test->getNamedFunction(F->getName());
 
       // Don't forward functions which are external in the test module too.
       if (TestFn && !TestFn->isExternal()) {


Index: llvm/tools/bugpoint/bugpoint.cpp
diff -u llvm/tools/bugpoint/bugpoint.cpp:1.24 llvm/tools/bugpoint/bugpoint.cpp:1.25
--- llvm/tools/bugpoint/bugpoint.cpp:1.24	Thu Apr 21 18:59:23 2005
+++ llvm/tools/bugpoint/bugpoint.cpp	Mon Aug  1 21:16:17 2005
@@ -32,13 +32,21 @@
 static cl::list<const PassInfo*, bool, PassNameParser>
 PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
 
+/// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
+bool llvm::BugpointIsInterrupted = false;
+
+static void BugpointInterruptFunction() {
+  BugpointIsInterrupted = true;
+}
+
 int main(int argc, char **argv) {
   cl::ParseCommandLineOptions(argc, argv,
                               " LLVM automatic testcase reducer. See\nhttp://"
                               "llvm.cs.uiuc.edu/docs/CommandGuide/bugpoint.html"
                               " for more information.\n");
   sys::PrintStackTraceOnErrorSignal();
-
+  sys::SetInterruptFunction(BugpointInterruptFunction);
+  
   BugDriver D(argv[0]);
   if (D.addSources(InputFilenames)) return 1;
   D.addPasses(PassList.begin(), PassList.end());






More information about the llvm-commits mailing list