summaryrefslogtreecommitdiff
path: root/tools/bugpoint
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-10-23 17:51:42 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-10-23 17:51:42 +0000
commit1d5ae1026e831016fc29fd927877c86af904481f (patch)
tree2cdfd12620fcfa5d9e4a0389f85368e8e36f63f9 /tools/bugpoint
parente6d1592492a3a379186bfb02bd0f4eda0669c0d5 (diff)
Notes
Diffstat (limited to 'tools/bugpoint')
-rw-r--r--tools/bugpoint/BugDriver.h7
-rw-r--r--tools/bugpoint/ExtractFunction.cpp3
-rw-r--r--tools/bugpoint/OptimizerDriver.cpp12
-rw-r--r--tools/bugpoint/ToolRunner.cpp16
-rw-r--r--tools/bugpoint/bugpoint.cpp46
5 files changed, 51 insertions, 33 deletions
diff --git a/tools/bugpoint/BugDriver.h b/tools/bugpoint/BugDriver.h
index 75f166b21b2c..fe5201eb2e6c 100644
--- a/tools/bugpoint/BugDriver.h
+++ b/tools/bugpoint/BugDriver.h
@@ -217,8 +217,7 @@ public:
/// returning the transformed module on success, or a null pointer on failure.
std::unique_ptr<Module> runPassesOn(Module *M,
const std::vector<std::string> &Passes,
- unsigned NumExtraArgs = 0,
- const char *const *ExtraArgs = nullptr);
+ ArrayRef<std::string> ExtraArgs = {});
/// runPasses - Run the specified passes on Program, outputting a bitcode
/// file and writting the filename into OutputFile if successful. If the
@@ -231,8 +230,8 @@ public:
///
bool runPasses(Module &Program, const std::vector<std::string> &PassesToRun,
std::string &OutputFilename, bool DeleteOutput = false,
- bool Quiet = false, unsigned NumExtraArgs = 0,
- const char *const *ExtraArgs = nullptr) const;
+ bool Quiet = false,
+ ArrayRef<std::string> ExtraArgs = {}) const;
/// runPasses - Just like the method above, but this just returns true or
/// false indicating whether or not the optimizer crashed on the specified
diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp
index 105702de3f1d..d9047acd30e1 100644
--- a/tools/bugpoint/ExtractFunction.cpp
+++ b/tools/bugpoint/ExtractFunction.cpp
@@ -407,11 +407,10 @@ BugDriver::extractMappedBlocksFromModule(const std::vector<BasicBlock *> &BBs,
std::string uniqueFN = "--extract-blocks-file=";
uniqueFN += Temp->TmpName;
- const char *ExtraArg = uniqueFN.c_str();
std::vector<std::string> PI;
PI.push_back("extract-blocks");
- std::unique_ptr<Module> Ret = runPassesOn(M, PI, 1, &ExtraArg);
+ std::unique_ptr<Module> Ret = runPassesOn(M, PI, {uniqueFN});
if (!Ret) {
outs() << "*** Basic Block extraction failed, please report a bug!\n";
diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp
index 562de7952388..64af81fcc8a1 100644
--- a/tools/bugpoint/OptimizerDriver.cpp
+++ b/tools/bugpoint/OptimizerDriver.cpp
@@ -79,7 +79,7 @@ bool BugDriver::writeProgramToFile(int FD, const Module &M) const {
bool BugDriver::writeProgramToFile(const std::string &Filename,
const Module &M) const {
std::error_code EC;
- ToolOutputFile Out(Filename, EC, sys::fs::F_None);
+ ToolOutputFile Out(Filename, EC, sys::fs::OF_None);
if (!EC)
return writeProgramToFileAux(Out, M);
return true;
@@ -130,8 +130,7 @@ static cl::list<std::string> OptArgs("opt-args", cl::Positional,
bool BugDriver::runPasses(Module &Program,
const std::vector<std::string> &Passes,
std::string &OutputFilename, bool DeleteOutput,
- bool Quiet, unsigned NumExtraArgs,
- const char *const *ExtraArgs) const {
+ bool Quiet, ArrayRef<std::string> ExtraArgs) const {
// setup the output file name
outs().flush();
SmallString<128> UniqueFilename;
@@ -223,8 +222,7 @@ bool BugDriver::runPasses(Module &Program,
I != E; ++I)
Args.push_back(I->c_str());
Args.push_back(Temp->TmpName.c_str());
- for (unsigned i = 0; i < NumExtraArgs; ++i)
- Args.push_back(*ExtraArgs);
+ Args.append(ExtraArgs.begin(), ExtraArgs.end());
LLVM_DEBUG(errs() << "\nAbout to run:\t";
for (unsigned i = 0, e = Args.size() - 1; i != e; ++i) errs()
@@ -268,10 +266,10 @@ bool BugDriver::runPasses(Module &Program,
std::unique_ptr<Module>
BugDriver::runPassesOn(Module *M, const std::vector<std::string> &Passes,
- unsigned NumExtraArgs, const char *const *ExtraArgs) {
+ ArrayRef<std::string> ExtraArgs) {
std::string BitcodeResult;
if (runPasses(*M, Passes, BitcodeResult, false /*delete*/, true /*quiet*/,
- NumExtraArgs, ExtraArgs)) {
+ ExtraArgs)) {
return nullptr;
}
diff --git a/tools/bugpoint/ToolRunner.cpp b/tools/bugpoint/ToolRunner.cpp
index da4244345e3b..19b2ea2c0181 100644
--- a/tools/bugpoint/ToolRunner.cpp
+++ b/tools/bugpoint/ToolRunner.cpp
@@ -170,7 +170,7 @@ Expected<int> LLI::ExecuteProgram(const std::string &Bitcode,
const std::vector<std::string> &SharedLibs,
unsigned Timeout, unsigned MemoryLimit) {
std::vector<StringRef> LLIArgs;
- LLIArgs.push_back(LLIPath.c_str());
+ LLIArgs.push_back(LLIPath);
LLIArgs.push_back("-force-interpreter=true");
for (std::vector<std::string>::const_iterator i = SharedLibs.begin(),
@@ -266,15 +266,15 @@ Error CustomCompiler::compileProgram(const std::string &Bitcode,
unsigned Timeout, unsigned MemoryLimit) {
std::vector<StringRef> ProgramArgs;
- ProgramArgs.push_back(CompilerCommand.c_str());
+ ProgramArgs.push_back(CompilerCommand);
- for (std::size_t i = 0; i < CompilerArgs.size(); ++i)
- ProgramArgs.push_back(CompilerArgs.at(i).c_str());
+ for (const auto &Arg : CompilerArgs)
+ ProgramArgs.push_back(Arg);
ProgramArgs.push_back(Bitcode);
// Add optional parameters to the running program from Argv
- for (unsigned i = 0, e = CompilerArgs.size(); i != e; ++i)
- ProgramArgs.push_back(CompilerArgs[i].c_str());
+ for (const auto &Arg : CompilerArgs)
+ ProgramArgs.push_back(Arg);
if (RunProgramWithTimeout(CompilerCommand, ProgramArgs, "", "", "", Timeout,
MemoryLimit))
@@ -559,7 +559,7 @@ Expected<int> JIT::ExecuteProgram(const std::string &Bitcode,
unsigned Timeout, unsigned MemoryLimit) {
// Construct a vector of parameters, incorporating those from the command-line
std::vector<StringRef> JITArgs;
- JITArgs.push_back(LLIPath.c_str());
+ JITArgs.push_back(LLIPath);
JITArgs.push_back("-force-interpreter=false");
// Add any extra LLI args.
@@ -570,7 +570,7 @@ Expected<int> JIT::ExecuteProgram(const std::string &Bitcode,
JITArgs.push_back("-load");
JITArgs.push_back(SharedLibs[i]);
}
- JITArgs.push_back(Bitcode.c_str());
+ JITArgs.push_back(Bitcode);
// Add optional parameters to the running program from Argv
for (unsigned i = 0, e = Args.size(); i != e; ++i)
JITArgs.push_back(Args[i]);
diff --git a/tools/bugpoint/bugpoint.cpp b/tools/bugpoint/bugpoint.cpp
index 2d5322a351ad..c7644e75ae4b 100644
--- a/tools/bugpoint/bugpoint.cpp
+++ b/tools/bugpoint/bugpoint.cpp
@@ -81,6 +81,10 @@ static cl::opt<bool> OptLevelOs(
"Like -O2 with extra optimizations for size. Similar to clang -Os"));
static cl::opt<bool>
+OptLevelOz("Oz",
+ cl::desc("Like -Os but reduces code size further. Similar to clang -Oz"));
+
+static cl::opt<bool>
OptLevelO3("O3", cl::desc("Optimization level 3. Identical to 'opt -O3'"));
static cl::opt<std::string>
@@ -109,6 +113,26 @@ public:
};
}
+// This routine adds optimization passes based on selected optimization level,
+// OptLevel.
+//
+// OptLevel - Optimization Level
+static void AddOptimizationPasses(legacy::FunctionPassManager &FPM,
+ unsigned OptLevel,
+ unsigned SizeLevel) {
+ PassManagerBuilder Builder;
+ Builder.OptLevel = OptLevel;
+ Builder.SizeLevel = SizeLevel;
+
+ if (OptLevel > 1)
+ Builder.Inliner = createFunctionInliningPass(OptLevel, SizeLevel, false);
+ else
+ Builder.Inliner = createAlwaysInlinerLegacyPass();
+
+ Builder.populateFunctionPassManager(FPM);
+ Builder.populateModulePassManager(FPM);
+}
+
#ifdef LINK_POLLY_INTO_TOOLS
namespace polly {
void initializePollyPasses(llvm::PassRegistry &Registry);
@@ -189,18 +213,16 @@ int main(int argc, char **argv) {
Builder.populateLTOPassManager(PM);
}
- if (OptLevelO1 || OptLevelO2 || OptLevelO3) {
- PassManagerBuilder Builder;
- if (OptLevelO1)
- Builder.Inliner = createAlwaysInlinerLegacyPass();
- else if (OptLevelOs || OptLevelO2)
- Builder.Inliner = createFunctionInliningPass(
- 2, OptLevelOs ? 1 : 0, false);
- else
- Builder.Inliner = createFunctionInliningPass(275);
- Builder.populateFunctionPassManager(PM);
- Builder.populateModulePassManager(PM);
- }
+ if (OptLevelO1)
+ AddOptimizationPasses(PM, 1, 0);
+ else if (OptLevelO2)
+ AddOptimizationPasses(PM, 2, 0);
+ else if (OptLevelO3)
+ AddOptimizationPasses(PM, 3, 0);
+ else if (OptLevelOs)
+ AddOptimizationPasses(PM, 2, 1);
+ else if (OptLevelOz)
+ AddOptimizationPasses(PM, 2, 2);
for (const PassInfo *PI : PassList)
D.addPass(PI->getPassArgument());