aboutsummaryrefslogtreecommitdiffstats
path: root/tools/bugpoint/OptimizerDriver.cpp
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2014-12-01 14:51:49 -0800
committerStephen Hines <srhines@google.com>2014-12-02 16:08:10 -0800
commit37ed9c199ca639565f6ce88105f9e39e898d82d0 (patch)
tree8fb36d3910e3ee4c4e1b7422f4f017108efc52f5 /tools/bugpoint/OptimizerDriver.cpp
parentd2327b22152ced7bc46dc629fc908959e8a52d03 (diff)
downloadexternal_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.zip
external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.tar.gz
external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.tar.bz2
Update aosp/master LLVM for rebase to r222494.
Change-Id: Ic787f5e0124df789bd26f3f24680f45e678eef2d
Diffstat (limited to 'tools/bugpoint/OptimizerDriver.cpp')
-rw-r--r--tools/bugpoint/OptimizerDriver.cpp50
1 files changed, 30 insertions, 20 deletions
diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp
index d452fd9..f197cc5 100644
--- a/tools/bugpoint/OptimizerDriver.cpp
+++ b/tools/bugpoint/OptimizerDriver.cpp
@@ -66,15 +66,15 @@ static bool writeProgramToFileAux(tool_output_file &Out, const Module *M) {
bool BugDriver::writeProgramToFile(const std::string &Filename, int FD,
const Module *M) const {
- tool_output_file Out(Filename.c_str(), FD);
+ tool_output_file Out(Filename, FD);
return writeProgramToFileAux(Out, M);
}
bool BugDriver::writeProgramToFile(const std::string &Filename,
const Module *M) const {
- std::string ErrInfo;
- tool_output_file Out(Filename.c_str(), ErrInfo, sys::fs::F_None);
- if (ErrInfo.empty())
+ std::error_code EC;
+ tool_output_file Out(Filename, EC, sys::fs::F_None);
+ if (!EC)
return writeProgramToFileAux(Out, M);
return true;
}
@@ -149,7 +149,7 @@ bool BugDriver::runPasses(Module *Program,
return 1;
}
- tool_output_file InFile(InputFilename.c_str(), InputFD);
+ tool_output_file InFile(InputFilename, InputFD);
WriteBitcodeToFile(Program, InFile.os());
InFile.os().close();
@@ -159,12 +159,31 @@ bool BugDriver::runPasses(Module *Program,
return 1;
}
- std::string tool = OptCmd.empty()? sys::FindProgramByName("opt") : OptCmd;
+ std::string tool = OptCmd;
+ if (OptCmd.empty()) {
+ if (ErrorOr<std::string> Path = sys::findProgramByName("opt"))
+ tool = *Path;
+ else
+ errs() << Path.getError().message() << "\n";
+ }
if (tool.empty()) {
errs() << "Cannot find `opt' in PATH!\n";
return 1;
}
+ std::string Prog;
+ if (UseValgrind) {
+ if (ErrorOr<std::string> Path = sys::findProgramByName("valgrind"))
+ Prog = *Path;
+ else
+ errs() << Path.getError().message() << "\n";
+ } else
+ Prog = tool;
+ if (Prog.empty()) {
+ errs() << "Cannot find `valgrind' in PATH!\n";
+ return 1;
+ }
+
// Ok, everything that could go wrong before running opt is done.
InFile.keep();
@@ -204,12 +223,6 @@ bool BugDriver::runPasses(Module *Program,
errs() << "\n";
);
- std::string Prog;
- if (UseValgrind)
- Prog = sys::FindProgramByName("valgrind");
- else
- Prog = tool;
-
// Redirect stdout and stderr to nowhere if SilencePasses is given
StringRef Nowhere;
const StringRef *Redirects[3] = {nullptr, &Nowhere, &Nowhere};
@@ -247,13 +260,10 @@ bool BugDriver::runPasses(Module *Program,
}
-/// runPassesOn - Carefully run the specified set of pass on the specified
-/// module, returning the transformed module on success, or a null pointer on
-/// failure.
-Module *BugDriver::runPassesOn(Module *M,
- const std::vector<std::string> &Passes,
- bool AutoDebugCrashes, unsigned NumExtraArgs,
- const char * const *ExtraArgs) {
+std::unique_ptr<Module>
+BugDriver::runPassesOn(Module *M, const std::vector<std::string> &Passes,
+ bool AutoDebugCrashes, unsigned NumExtraArgs,
+ const char *const *ExtraArgs) {
std::string BitcodeResult;
if (runPasses(M, Passes, BitcodeResult, false/*delete*/, true/*quiet*/,
NumExtraArgs, ExtraArgs)) {
@@ -267,7 +277,7 @@ Module *BugDriver::runPassesOn(Module *M,
return nullptr;
}
- Module *Ret = ParseInputFile(BitcodeResult, Context);
+ std::unique_ptr<Module> Ret = parseInputFile(BitcodeResult, Context);
if (!Ret) {
errs() << getToolName() << ": Error reading bitcode file '"
<< BitcodeResult << "'!\n";