diff options
author | Justin Bogner <mail@justinbogner.com> | 2016-09-02 01:21:37 +0000 |
---|---|---|
committer | Justin Bogner <mail@justinbogner.com> | 2016-09-02 01:21:37 +0000 |
commit | 8d0a08115a382983cf553bc834b20253bf82a5c2 (patch) | |
tree | d6d915ea669e8e2978e1c158b7c34e7d9394d38e /llvm/tools/bugpoint/ExecutionDriver.cpp | |
parent | bc469276599aa69c4804d47e2fd9f8bc51ea60f0 (diff) | |
download | bcm5719-llvm-8d0a08115a382983cf553bc834b20253bf82a5c2.tar.gz bcm5719-llvm-8d0a08115a382983cf553bc834b20253bf82a5c2.zip |
bugpoint: clang-format all of bugpoint. NFC
I'm going to clean up the APIs here a bit and touch many many lines
anyway.
llvm-svn: 280450
Diffstat (limited to 'llvm/tools/bugpoint/ExecutionDriver.cpp')
-rw-r--r-- | llvm/tools/bugpoint/ExecutionDriver.cpp | 337 |
1 files changed, 165 insertions, 172 deletions
diff --git a/llvm/tools/bugpoint/ExecutionDriver.cpp b/llvm/tools/bugpoint/ExecutionDriver.cpp index ab9c05fa924..695461e2d50 100644 --- a/llvm/tools/bugpoint/ExecutionDriver.cpp +++ b/llvm/tools/bugpoint/ExecutionDriver.cpp @@ -25,112 +25,113 @@ using namespace llvm; namespace { - // OutputType - Allow the user to specify the way code should be run, to test - // for miscompilation. - // - enum OutputType { - AutoPick, RunLLI, RunJIT, RunLLC, RunLLCIA, LLC_Safe, CompileCustom, Custom - }; - - cl::opt<double> - AbsTolerance("abs-tolerance", cl::desc("Absolute error tolerated"), - cl::init(0.0)); - cl::opt<double> - RelTolerance("rel-tolerance", cl::desc("Relative error tolerated"), - cl::init(0.0)); - - cl::opt<OutputType> - InterpreterSel(cl::desc("Specify the \"test\" i.e. suspect back-end:"), - cl::values(clEnumValN(AutoPick, "auto", "Use best guess"), - clEnumValN(RunLLI, "run-int", - "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(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."), - clEnumValEnd), - cl::init(AutoPick)); - - cl::opt<OutputType> - SafeInterpreterSel(cl::desc("Specify \"safe\" i.e. known-good backend:"), - cl::values(clEnumValN(AutoPick, "safe-auto", "Use best guess"), - clEnumValN(RunLLC, "safe-run-llc", "Compile with LLC"), - clEnumValN(Custom, "safe-run-custom", - "Use -exec-command to define a command to execute " - "the bitcode. Useful for cross-compilation."), - clEnumValEnd), - cl::init(AutoPick)); - - cl::opt<std::string> - SafeInterpreterPath("safe-path", - cl::desc("Specify the path to the \"safe\" backend program"), - cl::init("")); - - cl::opt<bool> - AppendProgramExitCode("append-exit-code", - cl::desc("Append the exit code to the output so it gets diff'd too"), - cl::init(false)); - - cl::opt<std::string> - InputFile("input", cl::init("/dev/null"), - cl::desc("Filename to pipe in as stdin (default: /dev/null)")); - - cl::list<std::string> - AdditionalSOs("additional-so", - cl::desc("Additional shared objects to load " - "into executing programs")); - - cl::list<std::string> - AdditionalLinkerArgs("Xlinker", - cl::desc("Additional arguments to pass to the linker")); - - cl::opt<std::string> - CustomCompileCommand("compile-command", cl::init("llc"), - cl::desc("Command to compile the bitcode (use with -compile-custom) " - "(default: llc)")); - - cl::opt<std::string> - CustomExecCommand("exec-command", cl::init("simulate"), - cl::desc("Command to execute the bitcode (use with -run-custom) " - "(default: simulate)")); +// OutputType - Allow the user to specify the way code should be run, to test +// for miscompilation. +// +enum OutputType { + AutoPick, + RunLLI, + RunJIT, + RunLLC, + RunLLCIA, + LLC_Safe, + CompileCustom, + Custom +}; + +cl::opt<double> AbsTolerance("abs-tolerance", + cl::desc("Absolute error tolerated"), + cl::init(0.0)); +cl::opt<double> RelTolerance("rel-tolerance", + cl::desc("Relative error tolerated"), + cl::init(0.0)); + +cl::opt<OutputType> InterpreterSel( + cl::desc("Specify the \"test\" i.e. suspect back-end:"), + cl::values(clEnumValN(AutoPick, "auto", "Use best guess"), + clEnumValN(RunLLI, "run-int", "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(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."), + clEnumValEnd), + cl::init(AutoPick)); + +cl::opt<OutputType> SafeInterpreterSel( + cl::desc("Specify \"safe\" i.e. known-good backend:"), + cl::values(clEnumValN(AutoPick, "safe-auto", "Use best guess"), + clEnumValN(RunLLC, "safe-run-llc", "Compile with LLC"), + clEnumValN(Custom, "safe-run-custom", + "Use -exec-command to define a command to execute " + "the bitcode. Useful for cross-compilation."), + clEnumValEnd), + cl::init(AutoPick)); + +cl::opt<std::string> SafeInterpreterPath( + "safe-path", cl::desc("Specify the path to the \"safe\" backend program"), + cl::init("")); + +cl::opt<bool> AppendProgramExitCode( + "append-exit-code", + cl::desc("Append the exit code to the output so it gets diff'd too"), + cl::init(false)); + +cl::opt<std::string> + InputFile("input", cl::init("/dev/null"), + cl::desc("Filename to pipe in as stdin (default: /dev/null)")); + +cl::list<std::string> + AdditionalSOs("additional-so", cl::desc("Additional shared objects to load " + "into executing programs")); + +cl::list<std::string> AdditionalLinkerArgs( + "Xlinker", cl::desc("Additional arguments to pass to the linker")); + +cl::opt<std::string> CustomCompileCommand( + "compile-command", cl::init("llc"), + cl::desc("Command to compile the bitcode (use with -compile-custom) " + "(default: llc)")); + +cl::opt<std::string> CustomExecCommand( + "exec-command", cl::init("simulate"), + cl::desc("Command to execute the bitcode (use with -run-custom) " + "(default: simulate)")); } namespace llvm { - // Anything specified after the --args option are taken as arguments to the - // program being debugged. - cl::list<std::string> - InputArgv("args", cl::Positional, cl::desc("<program arguments>..."), - cl::ZeroOrMore, cl::PositionalEatsArgs); - - cl::opt<std::string> - OutputPrefix("output-prefix", cl::init("bugpoint"), - cl::desc("Prefix to use for outputs (default: 'bugpoint')")); +// Anything specified after the --args option are taken as arguments to the +// program being debugged. +cl::list<std::string> InputArgv("args", cl::Positional, + cl::desc("<program arguments>..."), + cl::ZeroOrMore, cl::PositionalEatsArgs); + +cl::opt<std::string> + OutputPrefix("output-prefix", cl::init("bugpoint"), + cl::desc("Prefix to use for outputs (default: 'bugpoint')")); } namespace { - cl::list<std::string> - ToolArgv("tool-args", cl::Positional, cl::desc("<tool arguments>..."), - cl::ZeroOrMore, cl::PositionalEatsArgs); - - cl::list<std::string> - SafeToolArgv("safe-tool-args", cl::Positional, - cl::desc("<safe-tool arguments>..."), - cl::ZeroOrMore, cl::PositionalEatsArgs); - - cl::opt<std::string> - CCBinary("gcc", cl::init(""), cl::desc("The gcc binary to use.")); - - cl::list<std::string> - CCToolArgv("gcc-tool-args", cl::Positional, - cl::desc("<gcc-tool arguments>..."), - cl::ZeroOrMore, cl::PositionalEatsArgs); +cl::list<std::string> ToolArgv("tool-args", cl::Positional, + cl::desc("<tool arguments>..."), cl::ZeroOrMore, + cl::PositionalEatsArgs); + +cl::list<std::string> SafeToolArgv("safe-tool-args", cl::Positional, + cl::desc("<safe-tool arguments>..."), + cl::ZeroOrMore, cl::PositionalEatsArgs); + +cl::opt<std::string> CCBinary("gcc", cl::init(""), + cl::desc("The gcc binary to use.")); + +cl::list<std::string> CCToolArgv("gcc-tool-args", cl::Positional, + cl::desc("<gcc-tool arguments>..."), + cl::ZeroOrMore, cl::PositionalEatsArgs); } //===----------------------------------------------------------------------===// @@ -159,19 +160,18 @@ bool BugDriver::initializeExecutionEnvironment() { case AutoPick: if (!Interpreter) { InterpreterSel = RunJIT; - Interpreter = AbstractInterpreter::createJIT(getToolName(), Message, - &ToolArgv); + Interpreter = + AbstractInterpreter::createJIT(getToolName(), Message, &ToolArgv); } if (!Interpreter) { InterpreterSel = RunLLC; - Interpreter = AbstractInterpreter::createLLC(getToolName(), Message, - CCBinary, &ToolArgv, - &CCToolArgv); + Interpreter = AbstractInterpreter::createLLC( + getToolName(), Message, CCBinary, &ToolArgv, &CCToolArgv); } if (!Interpreter) { InterpreterSel = RunLLI; - Interpreter = AbstractInterpreter::createLLI(getToolName(), Message, - &ToolArgv); + Interpreter = + AbstractInterpreter::createLLI(getToolName(), Message, &ToolArgv); } if (!Interpreter) { InterpreterSel = AutoPick; @@ -179,28 +179,27 @@ bool BugDriver::initializeExecutionEnvironment() { } break; case RunLLI: - Interpreter = AbstractInterpreter::createLLI(getToolName(), Message, - &ToolArgv); + Interpreter = + AbstractInterpreter::createLLI(getToolName(), Message, &ToolArgv); break; case RunLLC: case RunLLCIA: case LLC_Safe: - Interpreter = AbstractInterpreter::createLLC(getToolName(), Message, - CCBinary, &ToolArgv, - &CCToolArgv, - InterpreterSel == RunLLCIA); + Interpreter = AbstractInterpreter::createLLC( + getToolName(), Message, CCBinary, &ToolArgv, &CCToolArgv, + InterpreterSel == RunLLCIA); break; case RunJIT: - Interpreter = AbstractInterpreter::createJIT(getToolName(), Message, - &ToolArgv); + Interpreter = + AbstractInterpreter::createJIT(getToolName(), Message, &ToolArgv); break; case CompileCustom: - Interpreter = - AbstractInterpreter::createCustomCompiler(Message, CustomCompileCommand); + Interpreter = AbstractInterpreter::createCustomCompiler( + Message, CustomCompileCommand); break; case Custom: Interpreter = - AbstractInterpreter::createCustomExecutor(Message, CustomExecCommand); + AbstractInterpreter::createCustomExecutor(Message, CustomExecCommand); break; } if (!Interpreter) @@ -215,25 +214,19 @@ bool BugDriver::initializeExecutionEnvironment() { switch (SafeInterpreterSel) { case AutoPick: // In "llc-safe" mode, default to using LLC as the "safe" backend. - if (!SafeInterpreter && - InterpreterSel == LLC_Safe) { + if (!SafeInterpreter && InterpreterSel == LLC_Safe) { SafeInterpreterSel = RunLLC; SafeToolArgs.push_back("--relocation-model=pic"); - SafeInterpreter = AbstractInterpreter::createLLC(Path.c_str(), Message, - CCBinary, - &SafeToolArgs, - &CCToolArgv); + SafeInterpreter = AbstractInterpreter::createLLC( + Path.c_str(), Message, CCBinary, &SafeToolArgs, &CCToolArgv); } - if (!SafeInterpreter && - InterpreterSel != RunLLC && + if (!SafeInterpreter && InterpreterSel != RunLLC && InterpreterSel != RunJIT) { SafeInterpreterSel = RunLLC; SafeToolArgs.push_back("--relocation-model=pic"); - SafeInterpreter = AbstractInterpreter::createLLC(Path.c_str(), Message, - CCBinary, - &SafeToolArgs, - &CCToolArgv); + SafeInterpreter = AbstractInterpreter::createLLC( + Path.c_str(), Message, CCBinary, &SafeToolArgs, &CCToolArgv); } if (!SafeInterpreter) { SafeInterpreterSel = AutoPick; @@ -243,24 +236,29 @@ bool BugDriver::initializeExecutionEnvironment() { case RunLLC: case RunLLCIA: SafeToolArgs.push_back("--relocation-model=pic"); - SafeInterpreter = AbstractInterpreter::createLLC(Path.c_str(), Message, - CCBinary, &SafeToolArgs, - &CCToolArgv, - SafeInterpreterSel == RunLLCIA); + SafeInterpreter = AbstractInterpreter::createLLC( + Path.c_str(), Message, CCBinary, &SafeToolArgs, &CCToolArgv, + SafeInterpreterSel == RunLLCIA); break; case Custom: SafeInterpreter = - AbstractInterpreter::createCustomExecutor(Message, CustomExecCommand); + AbstractInterpreter::createCustomExecutor(Message, CustomExecCommand); break; default: Message = "Sorry, this back-end is not supported by bugpoint as the " "\"safe\" backend right now!\n"; break; } - if (!SafeInterpreter) { outs() << Message << "\nExiting.\n"; exit(1); } + if (!SafeInterpreter) { + outs() << Message << "\nExiting.\n"; + exit(1); + } cc = CC::create(Message, CCBinary, &CCToolArgv); - if (!cc) { outs() << Message << "\nExiting.\n"; exit(1); } + if (!cc) { + outs() << Message << "\nExiting.\n"; + exit(1); + } // If there was an error creating the selected interpreter, quit with error. return Interpreter == nullptr; @@ -294,18 +292,16 @@ void BugDriver::compileProgram(Module *M, std::string *Error) const { Interpreter->compileProgram(BitcodeFile.str(), Error, Timeout, MemoryLimit); } - /// executeProgram - This method runs "Program", capturing the output of the /// program to a file, returning the filename of the file. A recommended /// filename may be optionally specified. /// -std::string BugDriver::executeProgram(const Module *Program, - std::string OutputFile, - std::string BitcodeFile, - const std::string &SharedObj, - AbstractInterpreter *AI, - std::string *Error) const { - if (!AI) AI = Interpreter; +std::string +BugDriver::executeProgram(const Module *Program, std::string OutputFile, + std::string BitcodeFile, const std::string &SharedObj, + AbstractInterpreter *AI, std::string *Error) const { + if (!AI) + AI = Interpreter; assert(AI && "Interpreter should have been created already!"); bool CreatedBitcode = false; if (BitcodeFile.empty()) { @@ -315,15 +311,15 @@ std::string BugDriver::executeProgram(const Module *Program, std::error_code EC = sys::fs::createUniqueFile( OutputPrefix + "-test-program-%%%%%%%.bc", UniqueFD, UniqueFilename); if (EC) { - errs() << ToolName << ": Error making unique filename: " - << EC.message() << "!\n"; + errs() << ToolName << ": Error making unique filename: " << EC.message() + << "!\n"; exit(1); } BitcodeFile = UniqueFilename.str(); if (writeProgramToFile(BitcodeFile, UniqueFD, Program)) { - errs() << ToolName << ": Error emitting bitcode to file '" - << BitcodeFile << "'!\n"; + errs() << ToolName << ": Error emitting bitcode to file '" << BitcodeFile + << "'!\n"; exit(1); } CreatedBitcode = true; @@ -331,17 +327,17 @@ std::string BugDriver::executeProgram(const Module *Program, // Remove the temporary bitcode file when we are done. std::string BitcodePath(BitcodeFile); - FileRemover BitcodeFileRemover(BitcodePath, - CreatedBitcode && !SaveTemps); + FileRemover BitcodeFileRemover(BitcodePath, CreatedBitcode && !SaveTemps); - if (OutputFile.empty()) OutputFile = OutputPrefix + "-execution-output-%%%%%%%"; + if (OutputFile.empty()) + OutputFile = OutputPrefix + "-execution-output-%%%%%%%"; // Check to see if this is a valid output filename... SmallString<128> UniqueFile; std::error_code EC = sys::fs::createUniqueFile(OutputFile, UniqueFile); if (EC) { - errs() << ToolName << ": Error making unique filename: " - << EC.message() << "\n"; + errs() << ToolName << ": Error making unique filename: " << EC.message() + << "\n"; exit(1); } OutputFile = UniqueFile.str(); @@ -361,11 +357,15 @@ std::string BugDriver::executeProgram(const Module *Program, errs() << "<timeout>"; static bool FirstTimeout = true; if (FirstTimeout) { - outs() << "\n" - "*** Program execution timed out! This mechanism is designed to handle\n" - " programs stuck in infinite loops gracefully. The -timeout option\n" - " can be used to change the timeout threshold or disable it completely\n" - " (with -timeout=0). This message is only displayed once.\n"; + outs() + << "\n" + "*** Program execution timed out! This mechanism is designed to " + "handle\n" + " programs stuck in infinite loops gracefully. The -timeout " + "option\n" + " can be used to change the timeout threshold or disable it " + "completely\n" + " (with -timeout=0). This message is only displayed once.\n"; FirstTimeout = false; } } @@ -395,14 +395,13 @@ std::string BugDriver::compileSharedObject(const std::string &BitcodeFile, std::string OutputFile; // Using the known-good backend. - CC::FileType FT = SafeInterpreter->OutputCode(BitcodeFile, OutputFile, - Error); + CC::FileType FT = SafeInterpreter->OutputCode(BitcodeFile, OutputFile, Error); if (!Error.empty()) return ""; std::string SharedObjectFile; bool Failure = cc->MakeSharedObject(OutputFile, FT, SharedObjectFile, - AdditionalLinkerArgs, Error); + AdditionalLinkerArgs, Error); if (!Error.empty()) return ""; if (Failure) @@ -447,8 +446,7 @@ bool BugDriver::createReferenceFile(Module *M, const std::string &Filename) { /// bool BugDriver::diffProgram(const Module *Program, const std::string &BitcodeFile, - const std::string &SharedObject, - bool RemoveBitcode, + const std::string &SharedObject, bool RemoveBitcode, std::string *ErrMsg) const { // Execute the program, generating an output file... std::string Output( @@ -458,16 +456,14 @@ bool BugDriver::diffProgram(const Module *Program, std::string Error; bool FilesDifferent = false; - if (int Diff = DiffFilesWithTolerance(ReferenceOutputFile, - Output, + if (int Diff = DiffFilesWithTolerance(ReferenceOutputFile, Output, AbsTolerance, RelTolerance, &Error)) { if (Diff == 2) { errs() << "While diffing output: " << Error << '\n'; exit(1); } FilesDifferent = true; - } - else { + } else { // Remove the generated output if there are no differences. sys::fs::remove(Output); } @@ -478,7 +474,4 @@ bool BugDriver::diffProgram(const Module *Program, return FilesDifferent; } -bool BugDriver::isExecutingJIT() { - return InterpreterSel == RunJIT; -} - +bool BugDriver::isExecutingJIT() { return InterpreterSel == RunJIT; } |