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, bool RemoveBitcode = false,
std::string *Error = 0); std::string *Error = 0);
/// EmitProgressBitcode - This function is used to output the current Program /// EmitProgressBitcode - This function is used to output M to a file named
/// to a file named "bugpoint-ID.bc". /// "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 /// deleteInstructionFromProgram - This method clones the current Program and
/// deletes the specified instruction from the cloned module. It then runs a /// 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 /// writeProgramToFile - This writes the current "Program" to the named
/// bitcode file. If an error occurs, true is returned. /// 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: private:
/// runPasses - Just like the method above, but this just returns true or /// 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; return true;
if (GVs.size() < OldSize) 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); ReduceCrashingFunctions(BD, TestFn).reduceList(Functions, Error);
if (Functions.size() < OldSize) 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 // 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(); unsigned OldSize = Blocks.size();
ReduceCrashingBlocks(BD, TestFn).reduceList(Blocks, Error); ReduceCrashingBlocks(BD, TestFn).reduceList(Blocks, Error);
if (Blocks.size() < OldSize) 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 // 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; return false;
} }
@@ -628,7 +628,7 @@ bool BugDriver::debugOptimizerCrash(const std::string &ID) {
<< (PassesToRun.size() == 1 ? ": " : "es: ") << (PassesToRun.size() == 1 ? ": " : "es: ")
<< getPassesString(PassesToRun) << '\n'; << getPassesString(PassesToRun) << '\n';
EmitProgressBitcode(ID); EmitProgressBitcode(Program, ID);
bool Success = DebugACrash(*this, TestForOptimizerCrash, Error); bool Success = DebugACrash(*this, TestForOptimizerCrash, Error);
assert(Error.empty()); assert(Error.empty());

View File

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

View File

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

View File

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