Remove dead argument and clean whitespace. No functionality change.
[oota-llvm.git] / tools / bugpoint / ExecutionDriver.cpp
index 7fd01ef2418bb5ae0c50a61a41da3ef040f3bb72..3b93a1a3224b0f51d6e88e290999d49774fdcbcd 100644 (file)
@@ -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 <fstream>
 
 using namespace llvm;
@@ -27,7 +28,7 @@ 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,Custom
   };
 
   cl::opt<double>
@@ -44,6 +45,8 @@ 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"),
@@ -55,19 +58,19 @@ namespace {
 
   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(RunCBE, "safe-run-cbe", "Compile with CBE"),
-                                clEnumValN(Custom, "safe-run-custom",
-                                "Use -exec-command to define a command to execute "
-                                "the bitcode. Useful for cross-compilation."),
-                                clEnumValEnd),
+              cl::values(clEnumValN(AutoPick, "safe-auto", "Use best guess"),
+                         clEnumValN(RunLLC, "safe-run-llc", "Compile with LLC"),
+                         clEnumValN(RunCBE, "safe-run-cbe", "Compile with CBE"),
+                         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::desc("Specify the path to the \"safe\" backend program"),
+                   cl::init(""));
 
   cl::opt<bool>
   AppendProgramExitCode("append-exit-code",
@@ -99,6 +102,10 @@ namespace llvm {
   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 {
@@ -163,9 +170,11 @@ bool BugDriver::initializeExecutionEnvironment() {
                                                  &ToolArgv);
     break;
   case RunLLC:
+  case RunLLCIA:
   case LLC_Safe:
     Interpreter = AbstractInterpreter::createLLC(getToolName(), Message,
-                                                 &ToolArgv, &GCCToolArgv);
+                                                 &ToolArgv, &GCCToolArgv,
+                                                 InterpreterSel == RunLLCIA);
     break;
   case RunJIT:
     Interpreter = AbstractInterpreter::createJIT(getToolName(), Message,
@@ -177,8 +186,7 @@ bool BugDriver::initializeExecutionEnvironment() {
                                                  &ToolArgv, &GCCToolArgv);
     break;
   case Custom:
-    Interpreter = AbstractInterpreter::createCustom(getToolName(), Message,
-                                                    CustomExecCommand);
+    Interpreter = AbstractInterpreter::createCustom(Message, CustomExecCommand);
     break;
   default:
     Message = "Sorry, this back-end is not supported by bugpoint right now!\n";
@@ -200,7 +208,7 @@ 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,
                                                        &SafeToolArgs,
                                                        &GCCToolArgv);
     }
@@ -210,7 +218,7 @@ 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,
                                                        &SafeToolArgs,
                                                        &GCCToolArgv);
     }
@@ -221,7 +229,7 @@ bool BugDriver::initializeExecutionEnvironment() {
     if (!SafeInterpreter &&
         InterpreterSel != RunCBE) {
       SafeInterpreterSel = RunCBE;
-      SafeInterpreter = AbstractInterpreter::createCBE(Path, Message,
+      SafeInterpreter = AbstractInterpreter::createCBE(Path.c_str(), Message,
                                                        &SafeToolArgs,
                                                        &GCCToolArgv);
     }
@@ -230,7 +238,7 @@ 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,
                                                        &SafeToolArgs,
                                                        &GCCToolArgv);
     }
@@ -240,18 +248,20 @@ bool BugDriver::initializeExecutionEnvironment() {
     }
     break;
   case RunLLC:
+  case RunLLCIA:
     SafeToolArgs.push_back("--relocation-model=pic");
-    SafeInterpreter = AbstractInterpreter::createLLC(Path, Message,
+    SafeInterpreter = AbstractInterpreter::createLLC(Path.c_str(), Message,
                                                      &SafeToolArgs,
-                                                     &GCCToolArgv);
+                                                     &GCCToolArgv,
+                                                SafeInterpreterSel == RunLLCIA);
     break;
   case RunCBE:
-    SafeInterpreter = AbstractInterpreter::createCBE(Path, Message,
+    SafeInterpreter = AbstractInterpreter::createCBE(Path.c_str(), Message,
                                                      &SafeToolArgs,
                                                      &GCCToolArgv);
     break;
   case Custom:
-    SafeInterpreter = AbstractInterpreter::createCustom(Path, Message,
+    SafeInterpreter = AbstractInterpreter::createCustom(Message,
                                                         CustomExecCommand);
     break;
   default:
@@ -261,7 +271,7 @@ bool BugDriver::initializeExecutionEnvironment() {
   }
   if (!SafeInterpreter) { outs() << Message << "\nExiting.\n"; exit(1); }
   
-  gcc = GCC::create(getToolName(), Message, &GCCToolArgv);
+  gcc = GCC::create(Message, &GCCToolArgv);
   if (!gcc) { outs() << Message << "\nExiting.\n"; exit(1); }
 
   // If there was an error creating the selected interpreter, quit with error.
@@ -274,24 +284,24 @@ bool BugDriver::initializeExecutionEnvironment() {
 ///
 void BugDriver::compileProgram(Module *M) {
   // 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 
            << "\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);
+  FileRemover BitcodeFileRemover(BitcodeFile, !SaveTemps);
 
   // Actually compile the program!
-  Interpreter->compileProgram(BitcodeFile.toString());
+  Interpreter->compileProgram(BitcodeFile.str());
 }
 
 
@@ -302,21 +312,20 @@ void BugDriver::compileProgram(Module *M) {
 std::string BugDriver::executeProgram(std::string OutputFile,
                                       std::string BitcodeFile,
                                       const std::string &SharedObj,
-                                      AbstractInterpreter *AI,
-                                      bool *ProgramExitedNonzero) {
+                                      AbstractInterpreter *AI) {
   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 +336,10 @@ std::string BugDriver::executeProgram(std::string OutputFile,
   }
 
   // Remove the temporary bitcode file when we are done.
-  sys::Path BitcodePath (BitcodeFile);
-  FileRemover BitcodeFileRemover(BitcodePath, CreatedBitcode);
+  sys::Path BitcodePath(BitcodeFile);
+  FileRemover BitcodeFileRemover(BitcodePath, 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,7 +348,7 @@ 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<std::string> SharedObjs(AdditionalSOs);
@@ -369,9 +378,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;
 }
@@ -380,9 +386,7 @@ std::string BugDriver::executeProgram(std::string OutputFile,
 /// backend, if reference output is not provided.
 ///
 std::string BugDriver::executeProgramSafely(std::string OutputFile) {
-  bool ProgramExitedNonzero;
-  std::string outFN = executeProgram(OutputFile, "", "", SafeInterpreter,
-                                     &ProgramExitedNonzero);
+  std::string outFN = executeProgram(OutputFile, "", "", SafeInterpreter);
   return outFN;
 }
 
@@ -394,7 +398,7 @@ std::string BugDriver::compileSharedObject(const std::string &BitcodeFile) {
   GCC::FileType FT = SafeInterpreter->OutputCode(BitcodeFile, OutputFile);
 
   std::string SharedObjectFile;
-  if (gcc->MakeSharedObject(OutputFile.toString(), FT,
+  if (gcc->MakeSharedObject(OutputFile.str(), FT,
                             SharedObjectFile, AdditionalLinkerArgs))
     exit(1);
 
@@ -439,16 +443,13 @@ bool BugDriver::createReferenceFile(Module *M, const std::string &Filename) {
 bool BugDriver::diffProgram(const std::string &BitcodeFile,
                             const std::string &SharedObject,
                             bool RemoveBitcode) {
-  bool ProgramExitedNonzero;
-
   // Execute the program, generating an output file...
-  sys::Path Output(executeProgram("", BitcodeFile, SharedObject, 0,
-                                      &ProgramExitedNonzero));
+  sys::Path Output(executeProgram("", BitcodeFile, SharedObject, 0));
 
   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';