mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 05:01:59 +01:00
[bugpoint] Extract helper functions for readability [NFCI]
And remove the use of a label(!) in the process. llvm-svn: 274087
This commit is contained in:
parent
8a4b0078c7
commit
4503ee726b
@ -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,6 +701,97 @@ static bool DebugACrash(BugDriver &BD,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
std::vector<const Instruction*> Insts;
|
||||
for (const Function &F : *BD.getProgram())
|
||||
for (const BasicBlock &BB : F)
|
||||
for (const Instruction &I : BB)
|
||||
if (!isa<TerminatorInst>(&I))
|
||||
Insts.push_back(&I);
|
||||
|
||||
ReduceCrashingInstructions(BD, TestFn).reduceList(Insts, Error);
|
||||
}
|
||||
|
||||
unsigned Simplification = 2;
|
||||
do {
|
||||
if (BugpointIsInterrupted)
|
||||
return;
|
||||
--Simplification;
|
||||
outs() << "\n*** Attempting to reduce testcase by deleting instruc"
|
||||
<< "tions: Simplification Level #" << Simplification << '\n';
|
||||
|
||||
// Now that we have deleted the functions that are unnecessary for the
|
||||
// program, try to remove instructions that are not necessary to cause the
|
||||
// crash. To do this, we loop through all of the instructions in the
|
||||
// remaining functions, deleting them (replacing any values produced with
|
||||
// nulls), and then running ADCE and SimplifyCFG. If the transformed input
|
||||
// still triggers failure, keep deleting until we cannot trigger failure
|
||||
// anymore.
|
||||
//
|
||||
unsigned InstructionsToSkipBeforeDeleting = 0;
|
||||
TryAgain:
|
||||
|
||||
// Loop over all of the (non-terminator) instructions remaining in the
|
||||
// function, attempting to delete them.
|
||||
unsigned CurInstructionNum = 0;
|
||||
for (Module::const_iterator FI = BD.getProgram()->begin(),
|
||||
E = BD.getProgram()->end(); FI != E; ++FI)
|
||||
if (!FI->isDeclaration())
|
||||
for (Function::const_iterator BI = FI->begin(), E = FI->end(); BI != E;
|
||||
++BI)
|
||||
for (BasicBlock::const_iterator I = BI->begin(), E = --BI->end();
|
||||
I != E; ++I, ++CurInstructionNum) {
|
||||
if (InstructionsToSkipBeforeDeleting) {
|
||||
--InstructionsToSkipBeforeDeleting;
|
||||
} else {
|
||||
if (BugpointIsInterrupted)
|
||||
return;
|
||||
|
||||
if (I->isEHPad() || I->getType()->isTokenTy())
|
||||
continue;
|
||||
|
||||
outs() << "Checking instruction: " << *I;
|
||||
std::unique_ptr<Module> M =
|
||||
BD.deleteInstructionFromProgram(&*I, Simplification);
|
||||
|
||||
// Find out if the pass still crashes on this pass...
|
||||
if (TestFn(BD, M.get())) {
|
||||
// Yup, it does, we delete the old module, and continue trying
|
||||
// to reduce the testcase...
|
||||
BD.setNewProgram(M.release());
|
||||
InstructionsToSkipBeforeDeleting = CurInstructionNum;
|
||||
goto TryAgain; // I wish I had a multi-level break here!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (InstructionsToSkipBeforeDeleting) {
|
||||
InstructionsToSkipBeforeDeleting = 0;
|
||||
goto TryAgain;
|
||||
}
|
||||
|
||||
} 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;
|
||||
@ -744,77 +828,8 @@ static bool DebugACrash(BugDriver &BD,
|
||||
|
||||
// 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) {
|
||||
std::vector<const Instruction*> Insts;
|
||||
for (const Function &F : *BD.getProgram())
|
||||
for (const BasicBlock &BB : F)
|
||||
for (const Instruction &I : BB)
|
||||
if (!isa<TerminatorInst>(&I))
|
||||
Insts.push_back(&I);
|
||||
|
||||
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;
|
||||
--Simplification;
|
||||
outs() << "\n*** Attempting to reduce testcase by deleting instruc"
|
||||
<< "tions: Simplification Level #" << Simplification << '\n';
|
||||
|
||||
// Now that we have deleted the functions that are unnecessary for the
|
||||
// program, try to remove instructions that are not necessary to cause the
|
||||
// crash. To do this, we loop through all of the instructions in the
|
||||
// remaining functions, deleting them (replacing any values produced with
|
||||
// nulls), and then running ADCE and SimplifyCFG. If the transformed input
|
||||
// still triggers failure, keep deleting until we cannot trigger failure
|
||||
// anymore.
|
||||
//
|
||||
unsigned InstructionsToSkipBeforeDeleting = 0;
|
||||
TryAgain:
|
||||
|
||||
// Loop over all of the (non-terminator) instructions remaining in the
|
||||
// function, attempting to delete them.
|
||||
unsigned CurInstructionNum = 0;
|
||||
for (Module::const_iterator FI = BD.getProgram()->begin(),
|
||||
E = BD.getProgram()->end(); FI != E; ++FI)
|
||||
if (!FI->isDeclaration())
|
||||
for (Function::const_iterator BI = FI->begin(), E = FI->end(); BI != E;
|
||||
++BI)
|
||||
for (BasicBlock::const_iterator I = BI->begin(), E = --BI->end();
|
||||
I != E; ++I, ++CurInstructionNum) {
|
||||
if (InstructionsToSkipBeforeDeleting) {
|
||||
--InstructionsToSkipBeforeDeleting;
|
||||
} else {
|
||||
if (BugpointIsInterrupted) goto ExitLoops;
|
||||
|
||||
if (I->isEHPad() || I->getType()->isTokenTy())
|
||||
continue;
|
||||
|
||||
outs() << "Checking instruction: " << *I;
|
||||
std::unique_ptr<Module> M =
|
||||
BD.deleteInstructionFromProgram(&*I, Simplification);
|
||||
|
||||
// Find out if the pass still crashes on this pass...
|
||||
if (TestFn(BD, M.get())) {
|
||||
// Yup, it does, we delete the old module, and continue trying
|
||||
// to reduce the testcase...
|
||||
BD.setNewProgram(M.release());
|
||||
InstructionsToSkipBeforeDeleting = CurInstructionNum;
|
||||
goto TryAgain; // I wish I had a multi-level break here!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (InstructionsToSkipBeforeDeleting) {
|
||||
InstructionsToSkipBeforeDeleting = 0;
|
||||
goto TryAgain;
|
||||
}
|
||||
|
||||
} while (Simplification);
|
||||
BD.EmitProgressBitcode(BD.getProgram(), "reduced-instructions");
|
||||
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: ";
|
||||
|
Loading…
x
Reference in New Issue
Block a user