[llvm] r274087 - [bugpoint] Extract helper functions for readability [NFCI]

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 28 17:43:19 PDT 2016


Author: reames
Date: Tue Jun 28 19:43:18 2016
New Revision: 274087

URL: http://llvm.org/viewvc/llvm-project?rev=274087&view=rev
Log:
[bugpoint] Extract helper functions for readability [NFCI]

And remove the use of a label(!) in the process.  


Modified:
    llvm/trunk/tools/bugpoint/CrashDebugger.cpp

Modified: llvm/trunk/tools/bugpoint/CrashDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/CrashDebugger.cpp?rev=274087&r1=274086&r2=274087&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/CrashDebugger.cpp (original)
+++ llvm/trunk/tools/bugpoint/CrashDebugger.cpp Tue Jun 28 19:43:18 2016
@@ -649,16 +649,10 @@ bool ReduceCrashingNamedMDOps::TestNamed
   return false;
 }
 
-/// DebugACrash - Given a predicate that determines whether a component crashes
-/// on a program, try to destructively reduce the program while still keeping
-/// the predicate true.
-static bool DebugACrash(BugDriver &BD,
-                        bool (*TestFn)(const BugDriver &, Module *),
-                        std::string &Error) {
-  // See if we can get away with nuking some of the global variable initializers
-  // in the program...
-  if (!NoGlobalRM &&
-      BD.getProgram()->global_begin() != BD.getProgram()->global_end()) {
+static void ReduceGlobalInitializers(BugDriver &BD,
+                                     bool (*TestFn)(const BugDriver &, Module *),
+                                     std::string &Error) {
+  if (BD.getProgram()->global_begin() != BD.getProgram()->global_end()) {
     // Now try to reduce the number of global variable initializers in the
     // module to something small.
     Module *M = CloneModule(BD.getProgram()).release();
@@ -699,8 +693,7 @@ static bool DebugACrash(BugDriver &BD,
 
           unsigned OldSize = GVs.size();
           ReduceCrashingGlobalVariables(BD, TestFn).reduceList(GVs, Error);
-          if (!Error.empty())
-            return true;
+          assert(!Error.empty());
 
           if (GVs.size() < OldSize)
             BD.EmitProgressBitcode(BD.getProgram(), "reduced-global-variables");
@@ -708,40 +701,11 @@ static bool DebugACrash(BugDriver &BD,
       }
     }
   }
+}
 
-  // Now try to reduce the number of functions in the module to something small.
-  std::vector<Function*> Functions;
-  for (Function &F : *BD.getProgram())
-    if (!F.isDeclaration())
-      Functions.push_back(&F);
-
-  if (Functions.size() > 1 && !BugpointIsInterrupted) {
-    outs() << "\n*** Attempting to reduce the number of functions "
-      "in the testcase\n";
-
-    unsigned OldSize = Functions.size();
-    ReduceCrashingFunctions(BD, TestFn).reduceList(Functions, Error);
-
-    if (Functions.size() < OldSize)
-      BD.EmitProgressBitcode(BD.getProgram(), "reduced-function");
-  }
-
-  // Attempt to delete entire basic blocks at a time to speed up
-  // convergence... this actually works by setting the terminator of the blocks
-  // to a return instruction then running simplifycfg, which can potentially
-  // shrinks the code dramatically quickly
-  //
-  if (!DisableSimplifyCFG && !BugpointIsInterrupted) {
-    std::vector<const BasicBlock*> Blocks;
-    for (Function &F : *BD.getProgram())
-      for (BasicBlock &BB : F)
-        Blocks.push_back(&BB);
-    unsigned OldSize = Blocks.size();
-    ReduceCrashingBlocks(BD, TestFn).reduceList(Blocks, Error);
-    if (Blocks.size() < OldSize)
-      BD.EmitProgressBitcode(BD.getProgram(), "reduced-blocks");
-  }
-
+static void ReduceInsts(BugDriver &BD,
+                        bool (*TestFn)(const BugDriver &, Module *),
+                        std::string &Error) {
   // Attempt to delete instructions using bisection. This should help out nasty
   // cases with large basic blocks where the problem is at one end.
   if (!BugpointIsInterrupted) {
@@ -755,11 +719,10 @@ static bool DebugACrash(BugDriver &BD,
     ReduceCrashingInstructions(BD, TestFn).reduceList(Insts, Error);
   }
 
-  // FIXME: This should use the list reducer to converge faster by deleting
-  // larger chunks of instructions at a time!
   unsigned Simplification = 2;
   do {
-    if (BugpointIsInterrupted) break;
+    if (BugpointIsInterrupted)
+      return;
     --Simplification;
     outs() << "\n*** Attempting to reduce testcase by deleting instruc"
            << "tions: Simplification Level #" << Simplification << '\n';
@@ -788,7 +751,8 @@ static bool DebugACrash(BugDriver &BD,
             if (InstructionsToSkipBeforeDeleting) {
               --InstructionsToSkipBeforeDeleting;
             } else {
-              if (BugpointIsInterrupted) goto ExitLoops;
+              if (BugpointIsInterrupted)
+                return;
 
               if (I->isEHPad() || I->getType()->isTokenTy())
                 continue;
@@ -815,6 +779,57 @@ static bool DebugACrash(BugDriver &BD,
 
   } while (Simplification);
   BD.EmitProgressBitcode(BD.getProgram(), "reduced-instructions");
+}
+
+
+/// DebugACrash - Given a predicate that determines whether a component crashes
+/// on a program, try to destructively reduce the program while still keeping
+/// the predicate true.
+static bool DebugACrash(BugDriver &BD,
+                        bool (*TestFn)(const BugDriver &, Module *),
+                        std::string &Error) {
+  // See if we can get away with nuking some of the global variable initializers
+  // in the program...
+  if (!NoGlobalRM)
+    ReduceGlobalInitializers(BD, TestFn, Error);
+
+  // Now try to reduce the number of functions in the module to something small.
+  std::vector<Function*> Functions;
+  for (Function &F : *BD.getProgram())
+    if (!F.isDeclaration())
+      Functions.push_back(&F);
+
+  if (Functions.size() > 1 && !BugpointIsInterrupted) {
+    outs() << "\n*** Attempting to reduce the number of functions "
+      "in the testcase\n";
+
+    unsigned OldSize = Functions.size();
+    ReduceCrashingFunctions(BD, TestFn).reduceList(Functions, Error);
+
+    if (Functions.size() < OldSize)
+      BD.EmitProgressBitcode(BD.getProgram(), "reduced-function");
+  }
+
+  // Attempt to delete entire basic blocks at a time to speed up
+  // convergence... this actually works by setting the terminator of the blocks
+  // to a return instruction then running simplifycfg, which can potentially
+  // shrinks the code dramatically quickly
+  //
+  if (!DisableSimplifyCFG && !BugpointIsInterrupted) {
+    std::vector<const BasicBlock*> Blocks;
+    for (Function &F : *BD.getProgram())
+      for (BasicBlock &BB : F)
+        Blocks.push_back(&BB);
+    unsigned OldSize = Blocks.size();
+    ReduceCrashingBlocks(BD, TestFn).reduceList(Blocks, Error);
+    if (Blocks.size() < OldSize)
+      BD.EmitProgressBitcode(BD.getProgram(), "reduced-blocks");
+  }
+
+  // Attempt to delete instructions using bisection. This should help out nasty
+  // cases with large basic blocks where the problem is at one end.
+  if (!BugpointIsInterrupted)
+    ReduceInsts(BD, TestFn, Error);
 
   if (!NoNamedMDRM) {
     if (!BugpointIsInterrupted) {
@@ -839,8 +854,6 @@ static bool DebugACrash(BugDriver &BD,
     BD.EmitProgressBitcode(BD.getProgram(), "reduced-named-md");
   }
 
-ExitLoops:
-
   // Try to clean up the testcase by running funcresolve and globaldce...
   if (!BugpointIsInterrupted) {
     outs() << "\n*** Attempting to perform final cleanups: ";




More information about the llvm-commits mailing list