diff --git a/tools/bugpoint/BugDriver.h b/tools/bugpoint/BugDriver.h index 4f6bae5d5ab..6a7f47130a9 100644 --- a/tools/bugpoint/BugDriver.h +++ b/tools/bugpoint/BugDriver.h @@ -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 diff --git a/tools/bugpoint/CrashDebugger.cpp b/tools/bugpoint/CrashDebugger.cpp index 2d0631cdad9..272ec7eb75d 100644 --- a/tools/bugpoint/CrashDebugger.cpp +++ b/tools/bugpoint/CrashDebugger.cpp @@ -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()); diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp index d5611b58ae2..c03d86ca1fe 100644 --- a/tools/bugpoint/ExtractFunction.cpp +++ b/tools/bugpoint/ExtractFunction.cpp @@ -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::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; } diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp index 3ceb573d60d..7b2dad8451f 100644 --- a/tools/bugpoint/Miscompilation.cpp +++ b/tools/bugpoint/Miscompilation.cpp @@ -71,7 +71,7 @@ ReduceMiscompilingPasses::doTest(std::vector &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 &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 &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 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; } diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp index 3a6149b24a5..48936caf5fd 100644 --- a/tools/bugpoint/OptimizerDriver.cpp +++ b/tools/bugpoint/OptimizerDriver.cpp @@ -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);