X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fbugpoint%2FExecutionDriver.cpp;h=77c01ac552b3bec1a95abb91f77683b788ae6d85;hb=d589099eec8d120b5a7227072c4e717856e2276f;hp=ceaf8f498bc64c4979f24e67ecd337ed162eb416;hpb=86c006a971eb6fab6bd4923ff7ec1c0bc9c28f74;p=oota-llvm.git diff --git a/tools/bugpoint/ExecutionDriver.cpp b/tools/bugpoint/ExecutionDriver.cpp index ceaf8f498bc..77c01ac552b 100644 --- a/tools/bugpoint/ExecutionDriver.cpp +++ b/tools/bugpoint/ExecutionDriver.cpp @@ -18,6 +18,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/FileUtilities.h" #include "llvm/Support/SystemUtils.h" +#include "llvm/Support/raw_ostream.h" #include using namespace llvm; @@ -27,7 +28,8 @@ namespace { // for miscompilation. // enum OutputType { - AutoPick, RunLLI, RunJIT, RunLLC, RunCBE, CBE_bug, LLC_Safe, Custom + AutoPick, RunLLI, RunJIT, RunLLC, RunLLCIA, RunCBE, CBE_bug, LLC_Safe, + CompileCustom, Custom }; cl::opt @@ -44,9 +46,14 @@ namespace { "Execute with the interpreter"), clEnumValN(RunJIT, "run-jit", "Execute with JIT"), clEnumValN(RunLLC, "run-llc", "Compile with LLC"), + clEnumValN(RunLLCIA, "run-llc-ia", + "Compile with LLC with integrated assembler"), clEnumValN(RunCBE, "run-cbe", "Compile with CBE"), clEnumValN(CBE_bug,"cbe-bug", "Find CBE bugs"), clEnumValN(LLC_Safe, "llc-safe", "Use LLC for all"), + clEnumValN(CompileCustom, "compile-custom", + "Use -compile-command to define a command to " + "compile the bitcode. Useful to avoid linking."), clEnumValN(Custom, "run-custom", "Use -exec-command to define a command to execute " "the bitcode. Useful for cross-compilation."), @@ -84,9 +91,14 @@ namespace { "into executing programs")); cl::list - AdditionalLinkerArgs("Xlinker", + AdditionalLinkerArgs("Xlinker", cl::desc("Additional arguments to pass to the linker")); + cl::opt + CustomCompileCommand("compile-command", cl::init("llc"), + cl::desc("Command to compile the bitcode (use with -compile-custom) " + "(default: llc)")); + cl::opt CustomExecCommand("exec-command", cl::init("simulate"), cl::desc("Command to execute the bitcode (use with -run-custom) " @@ -99,6 +111,10 @@ namespace llvm { cl::list InputArgv("args", cl::Positional, cl::desc("..."), cl::ZeroOrMore, cl::PositionalEatsArgs); + + cl::opt + OutputPrefix("output-prefix", cl::init("bugpoint"), + cl::desc("Prefix to use for outputs (default: 'bugpoint')")); } namespace { @@ -111,6 +127,10 @@ namespace { cl::desc("..."), cl::ZeroOrMore, cl::PositionalEatsArgs); + cl::opt + GCCBinary("gcc", cl::init("gcc"), + cl::desc("The gcc binary to use. (default 'gcc')")); + cl::list GCCToolArgv("gcc-tool-args", cl::Positional, cl::desc("..."), @@ -136,8 +156,8 @@ bool BugDriver::initializeExecutionEnvironment() { case AutoPick: InterpreterSel = RunCBE; Interpreter = - AbstractInterpreter::createCBE(getToolName(), Message, &ToolArgv, - &GCCToolArgv); + AbstractInterpreter::createCBE(getToolName(), Message, GCCBinary, + &ToolArgv, &GCCToolArgv); if (!Interpreter) { InterpreterSel = RunJIT; Interpreter = AbstractInterpreter::createJIT(getToolName(), Message, @@ -146,7 +166,8 @@ bool BugDriver::initializeExecutionEnvironment() { if (!Interpreter) { InterpreterSel = RunLLC; Interpreter = AbstractInterpreter::createLLC(getToolName(), Message, - &ToolArgv, &GCCToolArgv); + GCCBinary, &ToolArgv, + &GCCToolArgv); } if (!Interpreter) { InterpreterSel = RunLLI; @@ -163,9 +184,12 @@ bool BugDriver::initializeExecutionEnvironment() { &ToolArgv); break; case RunLLC: + case RunLLCIA: case LLC_Safe: Interpreter = AbstractInterpreter::createLLC(getToolName(), Message, - &ToolArgv, &GCCToolArgv); + GCCBinary, &ToolArgv, + &GCCToolArgv, + InterpreterSel == RunLLCIA); break; case RunJIT: Interpreter = AbstractInterpreter::createJIT(getToolName(), Message, @@ -174,11 +198,16 @@ bool BugDriver::initializeExecutionEnvironment() { case RunCBE: case CBE_bug: Interpreter = AbstractInterpreter::createCBE(getToolName(), Message, - &ToolArgv, &GCCToolArgv); + GCCBinary, &ToolArgv, + &GCCToolArgv); + break; + case CompileCustom: + Interpreter = + AbstractInterpreter::createCustomCompiler(Message, CustomCompileCommand); break; case Custom: - Interpreter = AbstractInterpreter::createCustom(getToolName(), Message, - CustomExecCommand); + Interpreter = + AbstractInterpreter::createCustomExecutor(Message, CustomExecCommand); break; default: Message = "Sorry, this back-end is not supported by bugpoint right now!\n"; @@ -200,7 +229,8 @@ bool BugDriver::initializeExecutionEnvironment() { InterpreterSel == CBE_bug) { SafeInterpreterSel = RunLLC; SafeToolArgs.push_back("--relocation-model=pic"); - SafeInterpreter = AbstractInterpreter::createLLC(Path, Message, + SafeInterpreter = AbstractInterpreter::createLLC(Path.c_str(), Message, + GCCBinary, &SafeToolArgs, &GCCToolArgv); } @@ -210,7 +240,8 @@ bool BugDriver::initializeExecutionEnvironment() { InterpreterSel == LLC_Safe) { SafeInterpreterSel = RunLLC; SafeToolArgs.push_back("--relocation-model=pic"); - SafeInterpreter = AbstractInterpreter::createLLC(Path, Message, + SafeInterpreter = AbstractInterpreter::createLLC(Path.c_str(), Message, + GCCBinary, &SafeToolArgs, &GCCToolArgv); } @@ -221,7 +252,8 @@ bool BugDriver::initializeExecutionEnvironment() { if (!SafeInterpreter && InterpreterSel != RunCBE) { SafeInterpreterSel = RunCBE; - SafeInterpreter = AbstractInterpreter::createCBE(Path, Message, + SafeInterpreter = AbstractInterpreter::createCBE(Path.c_str(), Message, + GCCBinary, &SafeToolArgs, &GCCToolArgv); } @@ -230,7 +262,8 @@ bool BugDriver::initializeExecutionEnvironment() { InterpreterSel != RunJIT) { SafeInterpreterSel = RunLLC; SafeToolArgs.push_back("--relocation-model=pic"); - SafeInterpreter = AbstractInterpreter::createLLC(Path, Message, + SafeInterpreter = AbstractInterpreter::createLLC(Path.c_str(), Message, + GCCBinary, &SafeToolArgs, &GCCToolArgv); } @@ -240,19 +273,21 @@ bool BugDriver::initializeExecutionEnvironment() { } break; case RunLLC: + case RunLLCIA: SafeToolArgs.push_back("--relocation-model=pic"); - SafeInterpreter = AbstractInterpreter::createLLC(Path, Message, - &SafeToolArgs, - &GCCToolArgv); + SafeInterpreter = AbstractInterpreter::createLLC(Path.c_str(), Message, + GCCBinary, &SafeToolArgs, + &GCCToolArgv, + SafeInterpreterSel == RunLLCIA); break; case RunCBE: - SafeInterpreter = AbstractInterpreter::createCBE(Path, Message, - &SafeToolArgs, + SafeInterpreter = AbstractInterpreter::createCBE(Path.c_str(), Message, + GCCBinary, &SafeToolArgs, &GCCToolArgv); break; case Custom: - SafeInterpreter = AbstractInterpreter::createCustom(Path, Message, - CustomExecCommand); + SafeInterpreter = + AbstractInterpreter::createCustomExecutor(Message, CustomExecCommand); break; default: Message = "Sorry, this back-end is not supported by bugpoint as the " @@ -260,38 +295,38 @@ bool BugDriver::initializeExecutionEnvironment() { break; } if (!SafeInterpreter) { outs() << Message << "\nExiting.\n"; exit(1); } - - gcc = GCC::create(getToolName(), Message, &GCCToolArgv); + + gcc = GCC::create(Message, GCCBinary, &GCCToolArgv); if (!gcc) { outs() << Message << "\nExiting.\n"; exit(1); } // If there was an error creating the selected interpreter, quit with error. return Interpreter == 0; } -/// compileProgram - Try to compile the specified module, throwing an exception -/// if an error occurs, or returning normally if not. This is used for code -/// generation crash testing. +/// compileProgram - Try to compile the specified module, returning false and +/// setting Error if an error occurs. This is used for code generation +/// crash testing. /// -void BugDriver::compileProgram(Module *M) { +void BugDriver::compileProgram(Module *M, std::string *Error) const { // Emit the program to a bitcode file... - sys::Path BitcodeFile ("bugpoint-test-program.bc"); + sys::Path BitcodeFile (OutputPrefix + "-test-program.bc"); std::string ErrMsg; - if (BitcodeFile.makeUnique(true,&ErrMsg)) { - errs() << ToolName << ": Error making unique filename: " << ErrMsg + if (BitcodeFile.makeUnique(true, &ErrMsg)) { + errs() << ToolName << ": Error making unique filename: " << ErrMsg << "\n"; exit(1); } - if (writeProgramToFile(BitcodeFile.toString(), M)) { + if (writeProgramToFile(BitcodeFile.str(), M)) { errs() << ToolName << ": Error emitting bitcode to file '" - << BitcodeFile << "'!\n"; + << BitcodeFile.str() << "'!\n"; exit(1); } - // Remove the temporary bitcode file when we are done. - FileRemover BitcodeFileRemover(BitcodeFile, !SaveTemps); + // Remove the temporary bitcode file when we are done. + FileRemover BitcodeFileRemover(BitcodeFile.str(), !SaveTemps); // Actually compile the program! - Interpreter->compileProgram(BitcodeFile.toString()); + Interpreter->compileProgram(BitcodeFile.str(), Error, Timeout, MemoryLimit); } @@ -299,24 +334,25 @@ void BugDriver::compileProgram(Module *M) { /// program to a file, returning the filename of the file. A recommended /// filename may be optionally specified. /// -std::string BugDriver::executeProgram(std::string OutputFile, +std::string BugDriver::executeProgram(const Module *Program, + std::string OutputFile, std::string BitcodeFile, const std::string &SharedObj, AbstractInterpreter *AI, - bool *ProgramExitedNonzero) { + std::string *Error) const { if (AI == 0) AI = Interpreter; assert(AI && "Interpreter should have been created already!"); bool CreatedBitcode = false; std::string ErrMsg; if (BitcodeFile.empty()) { // Emit the program to a bitcode file... - sys::Path uniqueFilename("bugpoint-test-program.bc"); + sys::Path uniqueFilename(OutputPrefix + "-test-program.bc"); if (uniqueFilename.makeUnique(true, &ErrMsg)) { errs() << ToolName << ": Error making unique filename: " << ErrMsg << "!\n"; exit(1); } - BitcodeFile = uniqueFilename.toString(); + BitcodeFile = uniqueFilename.str(); if (writeProgramToFile(BitcodeFile, Program)) { errs() << ToolName << ": Error emitting bitcode to file '" @@ -327,10 +363,11 @@ std::string BugDriver::executeProgram(std::string OutputFile, } // Remove the temporary bitcode file when we are done. - sys::Path BitcodePath (BitcodeFile); - FileRemover BitcodeFileRemover(BitcodePath, CreatedBitcode && !SaveTemps); + sys::Path BitcodePath(BitcodeFile); + FileRemover BitcodeFileRemover(BitcodePath.str(), + CreatedBitcode && !SaveTemps); - if (OutputFile.empty()) OutputFile = "bugpoint-execution-output"; + if (OutputFile.empty()) OutputFile = OutputPrefix + "-execution-output"; // Check to see if this is a valid output filename... sys::Path uniqueFile(OutputFile); @@ -339,16 +376,18 @@ std::string BugDriver::executeProgram(std::string OutputFile, << ErrMsg << "\n"; exit(1); } - OutputFile = uniqueFile.toString(); + OutputFile = uniqueFile.str(); // Figure out which shared objects to run, if any. std::vector SharedObjs(AdditionalSOs); if (!SharedObj.empty()) SharedObjs.push_back(SharedObj); - int RetVal = AI->ExecuteProgram(BitcodeFile, InputArgv, InputFile, - OutputFile, AdditionalLinkerArgs, SharedObjs, + int RetVal = AI->ExecuteProgram(BitcodeFile, InputArgv, InputFile, OutputFile, + Error, AdditionalLinkerArgs, SharedObjs, Timeout, MemoryLimit); + if (!Error->empty()) + return OutputFile; if (RetVal == -1) { errs() << ""; @@ -369,9 +408,6 @@ std::string BugDriver::executeProgram(std::string OutputFile, outFile.close(); } - if (ProgramExitedNonzero != 0) - *ProgramExitedNonzero = (RetVal != 0); - // Return the filename we captured the output to. return OutputFile; } @@ -379,23 +415,29 @@ std::string BugDriver::executeProgram(std::string OutputFile, /// executeProgramSafely - Used to create reference output with the "safe" /// backend, if reference output is not provided. /// -std::string BugDriver::executeProgramSafely(std::string OutputFile) { - bool ProgramExitedNonzero; - std::string outFN = executeProgram(OutputFile, "", "", SafeInterpreter, - &ProgramExitedNonzero); - return outFN; +std::string BugDriver::executeProgramSafely(const Module *Program, + std::string OutputFile, + std::string *Error) const { + return executeProgram(Program, OutputFile, "", "", SafeInterpreter, Error); } -std::string BugDriver::compileSharedObject(const std::string &BitcodeFile) { +std::string BugDriver::compileSharedObject(const std::string &BitcodeFile, + std::string &Error) { assert(Interpreter && "Interpreter should have been created already!"); sys::Path OutputFile; // Using the known-good backend. - GCC::FileType FT = SafeInterpreter->OutputCode(BitcodeFile, OutputFile); + GCC::FileType FT = SafeInterpreter->OutputCode(BitcodeFile, OutputFile, + Error); + if (!Error.empty()) + return ""; std::string SharedObjectFile; - if (gcc->MakeSharedObject(OutputFile.toString(), FT, - SharedObjectFile, AdditionalLinkerArgs)) + bool Failure = gcc->MakeSharedObject(OutputFile.str(), FT, SharedObjectFile, + AdditionalLinkerArgs, Error); + if (!Error.empty()) + return ""; + if (Failure) exit(1); // Remove the intermediate C file @@ -405,21 +447,19 @@ std::string BugDriver::compileSharedObject(const std::string &BitcodeFile) { } /// createReferenceFile - calls compileProgram and then records the output -/// into ReferenceOutputFile. Returns true if reference file created, false +/// into ReferenceOutputFile. Returns true if reference file created, false /// otherwise. Note: initializeExecutionEnvironment should be called BEFORE /// this function. /// bool BugDriver::createReferenceFile(Module *M, const std::string &Filename) { - try { - compileProgram(Program); - } catch (ToolExecutionError &) { + std::string Error; + compileProgram(Program, &Error); + if (!Error.empty()) return false; - } - try { - ReferenceOutputFile = executeProgramSafely(Filename); - outs() << "\nReference output is: " << ReferenceOutputFile << "\n\n"; - } catch (ToolExecutionError &TEE) { - errs() << TEE.what(); + + ReferenceOutputFile = executeProgramSafely(Program, Filename, &Error); + if (!Error.empty()) { + errs() << Error; if (Interpreter != SafeInterpreter) { errs() << "*** There is a bug running the \"safe\" backend. Either" << " debug it (for example with the -run-cbe bugpoint option," @@ -428,27 +468,30 @@ bool BugDriver::createReferenceFile(Module *M, const std::string &Filename) { } return false; } + outs() << "\nReference output is: " << ReferenceOutputFile << "\n\n"; return true; } /// diffProgram - This method executes the specified module and diffs the /// output against the file specified by ReferenceOutputFile. If the output -/// is different, true is returned. If there is a problem with the code -/// generator (e.g., llc crashes), this will throw an exception. +/// is different, 1 is returned. If there is a problem with the code +/// generator (e.g., llc crashes), this will set ErrMsg. /// -bool BugDriver::diffProgram(const std::string &BitcodeFile, +bool BugDriver::diffProgram(const Module *Program, + const std::string &BitcodeFile, const std::string &SharedObject, - bool RemoveBitcode) { - bool ProgramExitedNonzero; - + bool RemoveBitcode, + std::string *ErrMsg) const { // Execute the program, generating an output file... - sys::Path Output(executeProgram("", BitcodeFile, SharedObject, 0, - &ProgramExitedNonzero)); + sys::Path Output(executeProgram(Program, "", BitcodeFile, SharedObject, 0, + ErrMsg)); + if (!ErrMsg->empty()) + return false; std::string Error; bool FilesDifferent = false; if (int Diff = DiffFilesWithTolerance(sys::Path(ReferenceOutputFile), - sys::Path(Output.toString()), + sys::Path(Output.str()), AbsTolerance, RelTolerance, &Error)) { if (Diff == 2) { errs() << "While diffing output: " << Error << '\n';