llvm-readobj: remove some dead code
[oota-llvm.git] / tools / bugpoint / OptimizerDriver.cpp
index 43f2d3318ae7c331d971f13120843029e343861d..b2722e6d0e7d5fd1a83fa98ab69769b4ecf04b8e 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #include "BugDriver.h"
-#include "llvm/Analysis/Verifier.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/Verifier.h"
 #include "llvm/PassManager.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
@@ -36,6 +36,8 @@
 
 using namespace llvm;
 
+#define DEBUG_TYPE "bugpoint"
+
 namespace llvm {
   extern cl::opt<std::string> OutputPrefix;
 }
@@ -44,6 +46,9 @@ namespace {
   // ChildOutput - This option captures the name of the child output file that
   // is set up by the parent bugpoint process
   cl::opt<std::string> ChildOutput("child-output", cl::ReallyHidden);
+  cl::opt<std::string> OptCmd("opt-command", cl::init(""),
+                              cl::desc("Path to opt. (default: search path "
+                                       "for 'opt'.)"));
 }
 
 /// writeProgramToFile - This writes the current "Program" to the named bitcode
@@ -68,7 +73,7 @@ bool BugDriver::writeProgramToFile(const std::string &Filename, int FD,
 bool BugDriver::writeProgramToFile(const std::string &Filename,
                                    const Module *M) const {
   std::string ErrInfo;
-  tool_output_file Out(Filename.c_str(), ErrInfo, raw_fd_ostream::F_Binary);
+  tool_output_file Out(Filename.c_str(), ErrInfo, sys::fs::F_None);
   if (ErrInfo.empty())
     return writeProgramToFileAux(Out, M);
   return true;
@@ -124,8 +129,8 @@ bool BugDriver::runPasses(Module *Program,
   // setup the output file name
   outs().flush();
   SmallString<128> UniqueFilename;
-  error_code EC =
-      sys::fs::unique_file(OutputPrefix + "-output-%%%%%%%.bc", UniqueFilename);
+  error_code EC = sys::fs::createUniqueFile(
+      OutputPrefix + "-output-%%%%%%%.bc", UniqueFilename);
   if (EC) {
     errs() << getToolName() << ": Error making unique filename: "
            << EC.message() << "\n";
@@ -136,8 +141,8 @@ bool BugDriver::runPasses(Module *Program,
   // set up the input file name
   SmallString<128> InputFilename;
   int InputFD;
-  EC = sys::fs::unique_file(OutputPrefix + "-input-%%%%%%%.bc", InputFD,
-                            InputFilename);
+  EC = sys::fs::createUniqueFile(OutputPrefix + "-input-%%%%%%%.bc", InputFD,
+                                 InputFilename);
   if (EC) {
     errs() << getToolName() << ": Error making unique filename: "
            << EC.message() << "\n";
@@ -154,7 +159,7 @@ bool BugDriver::runPasses(Module *Program,
     return 1;
   }
 
-  std::string tool = sys::FindProgramByName("opt");
+  std::string tool = OptCmd.empty()? sys::FindProgramByName("opt") : OptCmd;
   if (tool.empty()) {
     errs() << "Cannot find `opt' in PATH!\n";
     return 1;
@@ -191,7 +196,7 @@ bool BugDriver::runPasses(Module *Program,
   Args.push_back(InputFilename.c_str());
   for (unsigned i = 0; i < NumExtraArgs; ++i)
     Args.push_back(*ExtraArgs);
-  Args.push_back(0);
+  Args.push_back(nullptr);
 
   DEBUG(errs() << "\nAbout to run:\t";
         for (unsigned i = 0, e = Args.size()-1; i != e; ++i)
@@ -207,12 +212,12 @@ bool BugDriver::runPasses(Module *Program,
 
   // Redirect stdout and stderr to nowhere if SilencePasses is given
   StringRef Nowhere;
-  const StringRef *Redirects[3] = {0, &Nowhere, &Nowhere};
+  const StringRef *Redirects[3] = {nullptr, &Nowhere, &Nowhere};
 
   std::string ErrMsg;
-  int result = sys::ExecuteAndWait(Prog, Args.data(), 0,
-                                   (SilencePasses ? Redirects : 0), Timeout,
-                                   MemoryLimit, &ErrMsg);
+  int result = sys::ExecuteAndWait(Prog, Args.data(), nullptr,
+                                   (SilencePasses ? Redirects : nullptr),
+                                   Timeout, MemoryLimit, &ErrMsg);
 
   // If we are supposed to delete the bitcode file or if the passes crashed,
   // remove it now.  This may fail if the file was never created, but that's ok.
@@ -259,11 +264,11 @@ Module *BugDriver::runPassesOn(Module *M,
       EmitProgressBitcode(M, "pass-error",  false);
       exit(debugOptimizerCrash());
     }
-    return 0;
+    return nullptr;
   }
 
   Module *Ret = ParseInputFile(BitcodeResult, Context);
-  if (Ret == 0) {
+  if (!Ret) {
     errs() << getToolName() << ": Error reading bitcode file '"
            << BitcodeResult << "'!\n";
     exit(1);