From 67d87be67842f44dfac2d220acd836067643deed Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Wed, 29 Jun 2016 00:43:18 +0000 Subject: [PATCH] [bugpoint] Extract helper functions for readability [NFCI] And remove the use of a label(!) in the process. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274087 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/bugpoint/CrashDebugger.cpp | 115 +++++++++++++++++-------------- 1 file changed, 64 insertions(+), 51 deletions(-) diff --git a/tools/bugpoint/CrashDebugger.cpp b/tools/bugpoint/CrashDebugger.cpp index fe015f81349..052874dbf44 100644 --- a/tools/bugpoint/CrashDebugger.cpp +++ b/tools/bugpoint/CrashDebugger.cpp @@ -649,16 +649,10 @@ bool ReduceCrashingNamedMDOps::TestNamedMDOps( 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 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 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 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 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: "; -- 2.50.1