Instead of abusing swapProgramIn, just add a Module argument to

EmitProgressBitcode.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109602 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2010-07-28 18:12:30 +00:00
parent c19d865474
commit bae1b71cbb
5 changed files with 28 additions and 36 deletions

View File

@ -205,10 +205,11 @@ public:
bool RemoveBitcode = false,
std::string *Error = 0);
/// EmitProgressBitcode - This function is used to output the current Program
/// to a file named "bugpoint-ID.bc".
/// EmitProgressBitcode - This function is used to output M to a file named
/// "bugpoint-ID.bc".
///
void EmitProgressBitcode(const std::string &ID, bool NoFlyer = false);
void EmitProgressBitcode(const Module *M, const std::string &ID,
bool NoFlyer = false);
/// deleteInstructionFromProgram - This method clones the current Program and
/// deletes the specified instruction from the cloned module. It then runs a
@ -274,7 +275,7 @@ public:
/// writeProgramToFile - This writes the current "Program" to the named
/// bitcode file. If an error occurs, true is returned.
///
bool writeProgramToFile(const std::string &Filename, Module *M = 0) const;
bool writeProgramToFile(const std::string &Filename, const Module *M) const;
private:
/// runPasses - Just like the method above, but this just returns true or

View File

@ -471,7 +471,7 @@ static bool DebugACrash(BugDriver &BD, bool (*TestFn)(BugDriver &, Module *),
return true;
if (GVs.size() < OldSize)
BD.EmitProgressBitcode("reduced-global-variables");
BD.EmitProgressBitcode(BD.getProgram(), "reduced-global-variables");
}
}
}
@ -492,7 +492,7 @@ static bool DebugACrash(BugDriver &BD, bool (*TestFn)(BugDriver &, Module *),
ReduceCrashingFunctions(BD, TestFn).reduceList(Functions, Error);
if (Functions.size() < OldSize)
BD.EmitProgressBitcode("reduced-function");
BD.EmitProgressBitcode(BD.getProgram(), "reduced-function");
}
// Attempt to delete entire basic blocks at a time to speed up
@ -509,7 +509,7 @@ static bool DebugACrash(BugDriver &BD, bool (*TestFn)(BugDriver &, Module *),
unsigned OldSize = Blocks.size();
ReduceCrashingBlocks(BD, TestFn).reduceList(Blocks, Error);
if (Blocks.size() < OldSize)
BD.EmitProgressBitcode("reduced-blocks");
BD.EmitProgressBitcode(BD.getProgram(), "reduced-blocks");
}
// Attempt to delete instructions using bisection. This should help out nasty
@ -602,7 +602,7 @@ ExitLoops:
}
}
BD.EmitProgressBitcode("reduced-simplified");
BD.EmitProgressBitcode(BD.getProgram(), "reduced-simplified");
return false;
}
@ -628,7 +628,7 @@ bool BugDriver::debugOptimizerCrash(const std::string &ID) {
<< (PassesToRun.size() == 1 ? ": " : "es: ")
<< getPassesString(PassesToRun) << '\n';
EmitProgressBitcode(ID);
EmitProgressBitcode(Program, ID);
bool Success = DebugACrash(*this, TestForOptimizerCrash, Error);
assert(Error.empty());

View File

@ -143,11 +143,9 @@ Module *BugDriver::ExtractLoop(Module *M) {
Module *NewM = runPassesOn(M, LoopExtractPasses);
if (NewM == 0) {
Module *Old = swapProgramIn(M);
outs() << "*** Loop extraction failed: ";
EmitProgressBitcode("loopextraction", true);
EmitProgressBitcode(M, "loopextraction", true);
outs() << "*** Sorry. :( Please report a bug!\n";
swapProgramIn(Old);
return 0;
}
@ -327,9 +325,7 @@ Module *BugDriver::ExtractMappedBlocksFromModule(const
if (uniqueFilename.createTemporaryFileOnDisk(true, &ErrMsg)) {
outs() << "*** Basic Block extraction failed!\n";
errs() << "Error creating temporary file: " << ErrMsg << "\n";
M = swapProgramIn(M);
EmitProgressBitcode("basicblockextractfail", true);
swapProgramIn(M);
EmitProgressBitcode(M, "basicblockextractfail", true);
return 0;
}
sys::RemoveFileOnSignal(uniqueFilename);
@ -340,9 +336,7 @@ Module *BugDriver::ExtractMappedBlocksFromModule(const
outs() << "*** Basic Block extraction failed!\n";
errs() << "Error writing list of blocks to not extract: " << ErrorInfo
<< "\n";
M = swapProgramIn(M);
EmitProgressBitcode("basicblockextractfail", true);
swapProgramIn(M);
EmitProgressBitcode(M, "basicblockextractfail", true);
return 0;
}
for (std::vector<BasicBlock*>::const_iterator I = BBs.begin(), E = BBs.end();
@ -368,9 +362,7 @@ Module *BugDriver::ExtractMappedBlocksFromModule(const
if (Ret == 0) {
outs() << "*** Basic Block extraction failed, please report a bug!\n";
M = swapProgramIn(M);
EmitProgressBitcode("basicblockextractfail", true);
swapProgramIn(M);
EmitProgressBitcode(M, "basicblockextractfail", true);
}
return Ret;
}

View File

@ -71,7 +71,7 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
errs() << " Error running this sequence of passes"
<< " on the input program!\n";
BD.setPassesToRun(Suffix);
BD.EmitProgressBitcode("pass-error", false);
BD.EmitProgressBitcode(BD.getProgram(), "pass-error", false);
exit(BD.debugOptimizerCrash());
}
@ -108,7 +108,7 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
errs() << " Error running this sequence of passes"
<< " on the input program!\n";
BD.setPassesToRun(Prefix);
BD.EmitProgressBitcode("pass-error", false);
BD.EmitProgressBitcode(BD.getProgram(), "pass-error", false);
exit(BD.debugOptimizerCrash());
}
@ -148,7 +148,7 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
errs() << " Error running this sequence of passes"
<< " on the input program!\n";
BD.setPassesToRun(Suffix);
BD.EmitProgressBitcode("pass-error", false);
BD.EmitProgressBitcode(BD.getProgram(), "pass-error", false);
exit(BD.debugOptimizerCrash());
}
@ -699,7 +699,7 @@ void BugDriver::debugMiscompilation(std::string *Error) {
outs() << "\n*** Found miscompiling pass"
<< (getPassesToRun().size() == 1 ? "" : "es") << ": "
<< getPassesString(getPassesToRun()) << '\n';
EmitProgressBitcode("passinput");
EmitProgressBitcode(Program, "passinput");
std::vector<Function *> MiscompiledFunctions =
DebugAMiscompilation(*this, TestOptimizer, *Error);
@ -715,14 +715,12 @@ void BugDriver::debugMiscompilation(std::string *Error) {
VMap);
outs() << " Non-optimized portion: ";
ToNotOptimize = swapProgramIn(ToNotOptimize);
EmitProgressBitcode("tonotoptimize", true);
setNewProgram(ToNotOptimize); // Delete hacked module.
EmitProgressBitcode(ToNotOptimize, "tonotoptimize", true);
delete ToNotOptimize; // Delete hacked module.
outs() << " Portion that is input to optimizer: ";
ToOptimize = swapProgramIn(ToOptimize);
EmitProgressBitcode("tooptimize");
setNewProgram(ToOptimize); // Delete hacked module.
EmitProgressBitcode(ToOptimize, "tooptimize");
delete ToOptimize; // Delete hacked module.
return;
}

View File

@ -51,13 +51,13 @@ namespace {
/// file. If an error occurs, true is returned.
///
bool BugDriver::writeProgramToFile(const std::string &Filename,
Module *M) const {
const Module *M) const {
std::string ErrInfo;
raw_fd_ostream Out(Filename.c_str(), ErrInfo,
raw_fd_ostream::F_Binary);
if (!ErrInfo.empty()) return true;
WriteBitcodeToFile(M ? M : Program, Out);
WriteBitcodeToFile(M, Out);
return false;
}
@ -65,12 +65,13 @@ bool BugDriver::writeProgramToFile(const std::string &Filename,
/// EmitProgressBitcode - This function is used to output the current Program
/// to a file named "bugpoint-ID.bc".
///
void BugDriver::EmitProgressBitcode(const std::string &ID, bool NoFlyer) {
void BugDriver::EmitProgressBitcode(const Module *M,
const std::string &ID, bool NoFlyer) {
// Output the input to the current pass to a bitcode file, emit a message
// telling the user how to reproduce it: opt -foo blah.bc
//
std::string Filename = OutputPrefix + "-" + ID + ".bc";
if (writeProgramToFile(Filename)) {
if (writeProgramToFile(Filename, M)) {
errs() << "Error opening file '" << Filename << "' for writing!\n";
return;
}
@ -246,7 +247,7 @@ Module *BugDriver::runPassesOn(Module *M,
errs() << " Error running this sequence of passes"
<< " on the input program!\n";
delete OldProgram;
EmitProgressBitcode("pass-error", false);
EmitProgressBitcode(Program, "pass-error", false);
exit(debugOptimizerCrash());
}
swapProgramIn(OldProgram);