diff --git a/tools/bugpoint/BugDriver.h b/tools/bugpoint/BugDriver.h index 6c48c04fa55..e1af721a75c 100644 --- a/tools/bugpoint/BugDriver.h +++ b/tools/bugpoint/BugDriver.h @@ -120,7 +120,7 @@ private: /// EmitProgressBytecode - This function is used to output the current Program - /// to a file named "bugpoing-ID.bc". + /// to a file named "bugpoint-ID.bc". /// void EmitProgressBytecode(const std::string &ID, bool NoFlyer = false); @@ -162,7 +162,7 @@ private: /// the MayModifySemantics argument is true, then the cleanups is allowed to /// modify how the code behaves. /// - void performFinalCleanups(Module *M, bool MayModifySemantics = false) const; + Module *performFinalCleanups(Module *M, bool MayModifySemantics = false); /// initializeExecutionEnvironment - This method is used to set up the /// environment for executing LLVM programs. diff --git a/tools/bugpoint/CodeGeneratorBug.cpp b/tools/bugpoint/CodeGeneratorBug.cpp index 29a9f6823ab..41df79a110a 100644 --- a/tools/bugpoint/CodeGeneratorBug.cpp +++ b/tools/bugpoint/CodeGeneratorBug.cpp @@ -224,8 +224,8 @@ bool ReduceMisCodegenFunctions::TestFuncs(const std::vector &Funcs, } // Clean up the modules, removing extra cruft that we don't need anymore... - BD.performFinalCleanups(SafeModule); - BD.performFinalCleanups(TestModule); + SafeModule = BD.performFinalCleanups(SafeModule); + TestModule = BD.performFinalCleanups(TestModule); if (BD.writeProgramToFile(TestModuleBC, TestModule)) { std::cerr << "Error writing bytecode to `" << SafeModuleBC << "'\nExiting."; diff --git a/tools/bugpoint/CrashDebugger.cpp b/tools/bugpoint/CrashDebugger.cpp index 27e99b994ba..0b2851f220c 100644 --- a/tools/bugpoint/CrashDebugger.cpp +++ b/tools/bugpoint/CrashDebugger.cpp @@ -379,7 +379,7 @@ bool BugDriver::debugCrash() { // Try to clean up the testcase by running funcresolve and globaldce... std::cout << "\n*** Attempting to perform final cleanups: "; Module *M = CloneModule(Program); - performFinalCleanups(M, true); + M = performFinalCleanups(M, true); std::swap(Program, M); // Find out if the pass still crashes on the cleaned up program... diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp index 2d7747af775..38e25864e4c 100644 --- a/tools/bugpoint/ExtractFunction.cpp +++ b/tools/bugpoint/ExtractFunction.cpp @@ -37,9 +37,6 @@ namespace { cl::opt NoSCFG("disable-simplifycfg", cl::location(DisableSimplifyCFG), cl::desc("Do not use the -simplifycfg pass to reduce testcases")); - cl::opt - NoFinalCleanup("disable-final-cleanup", - cl::desc("Disable the final cleanup phase of narrowing")); } /// deleteInstructionFromProgram - This method clones the current Program and @@ -89,29 +86,42 @@ Module *BugDriver::deleteInstructionFromProgram(Instruction *I, return Result; } +static const PassInfo *getPI(Pass *P) { + const PassInfo *PI = P->getPassInfo(); + delete P; + return PI; +} + /// performFinalCleanups - This method clones the current Program and performs /// a series of cleanups intended to get rid of extra cruft on the module /// before handing it to the user... /// -void BugDriver::performFinalCleanups(Module *M, bool MayModifySemantics) const { - // Allow disabling these passes if they crash bugpoint. - // - // FIXME: This should eventually run these passes in a pass list to prevent - // them from being able to crash bugpoint at all! - // - if (NoFinalCleanup) return; - +Module *BugDriver::performFinalCleanups(Module *M, bool MayModifySemantics) { // Make all functions external, so GlobalDCE doesn't delete them... for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) I->setLinkage(GlobalValue::ExternalLinkage); - PassManager CleanupPasses; - // Make sure that the appropriate target data is always used... - CleanupPasses.add(new TargetData("bugpoint", M)); - CleanupPasses.add(createFunctionResolvingPass()); - CleanupPasses.add(createGlobalDCEPass()); - CleanupPasses.add(createDeadTypeEliminationPass()); - CleanupPasses.add(createDeadArgEliminationPass(MayModifySemantics)); - CleanupPasses.add(createVerifierPass()); - CleanupPasses.run(*M); + std::vector CleanupPasses; + CleanupPasses.push_back(getPI(createFunctionResolvingPass())); + CleanupPasses.push_back(getPI(createGlobalDCEPass())); + CleanupPasses.push_back(getPI(createDeadTypeEliminationPass())); + CleanupPasses.push_back(getPI(createDeadArgHackingPass())); + + std::swap(Program, M); + std::string Filename; + bool Failed = runPasses(CleanupPasses, Filename); + std::swap(Program, M); + + if (Failed) { + std::cerr << "Final cleanups failed. Sorry. :(\n"; + } else { + delete M; + M = ParseInputFile(Filename); + if (M == 0) { + std::cerr << getToolName() << ": Error reading bytecode file '" + << Filename << "'!\n"; + exit(1); + } + } + return M; }