diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index a07247e28e2..e60dc171bba 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -23,6 +23,7 @@ #include "llvm/DerivedTypes.h" #include "llvm/ModuleProvider.h" #include "llvm/Bitcode/ReaderWriter.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/SystemUtils.h" #include "llvm/Support/Mangler.h" #include "llvm/Support/MemoryBuffer.h" @@ -52,6 +53,8 @@ using namespace llvm; +static cl::opt DisableInline("disable-inlining", + cl::desc("Do not run the inliner pass")); const char* LTOCodeGenerator::getVersionString() @@ -334,17 +337,10 @@ bool LTOCodeGenerator::generateAssemblyCode(std::ostream& out, std::string& errM break; } - for (unsigned opt_index = 0, opt_size = _codegenOptions.size(); - opt_index < opt_size; ++opt_index) { - std::vector cgOpts; - std::string &optString = _codegenOptions[opt_index]; - for (std::string Opt = getToken(optString); - !Opt.empty(); Opt = getToken(optString)) - cgOpts.push_back(Opt.c_str()); - - int pseudo_argc = cgOpts.size()-1; - cl::ParseCommandLineOptions(pseudo_argc, (char**)&cgOpts[0]); - } + // if options were requested, set them + if ( !_codegenOptions.empty() ) + cl::ParseCommandLineOptions(_codegenOptions.size(), + (char**)&_codegenOptions[0]); // Instantiate the pass manager to organize the passes. PassManager passes; @@ -375,7 +371,8 @@ bool LTOCodeGenerator::generateAssemblyCode(std::ostream& out, std::string& errM // function pointers. When this happens, we often have to resolve varargs // calls, etc, so let instcombine do this. passes.add(createInstructionCombiningPass()); - passes.add(createFunctionInliningPass()); // Inline small functions + if (!DisableInline) + passes.add(createFunctionInliningPass()); // Inline small functions passes.add(createPruneEHPass()); // Remove dead EH info passes.add(createGlobalDCEPass()); // Remove dead functions @@ -454,4 +451,15 @@ bool LTOCodeGenerator::generateAssemblyCode(std::ostream& out, std::string& errM } - +/// Optimize merged modules using various IPO passes +void LTOCodeGenerator::setCodeGenDebugOptions(const char* options) +{ + std::string ops(options); + for (std::string o = getToken(ops); !o.empty(); o = getToken(ops)) { + // ParseCommandLineOptions() expects argv[0] to be program name. + // Lazily add that. + if ( _codegenOptions.empty() ) + _codegenOptions.push_back("libLTO"); + _codegenOptions.push_back(strdup(o.c_str())); + } +} diff --git a/tools/lto/LTOCodeGenerator.h b/tools/lto/LTOCodeGenerator.h index 24a2ba316e7..d3a2b6b2948 100644 --- a/tools/lto/LTOCodeGenerator.h +++ b/tools/lto/LTOCodeGenerator.h @@ -39,9 +39,7 @@ public: bool writeMergedModules(const char* path, std::string& errMsg); const void* compile(size_t* length, std::string& errMsg); - void setCodeGenDebugOptions(const char *opts) { - _codegenOptions.push_back(std::string(opts)); - } + void setCodeGenDebugOptions(const char *opts); private: bool generateAssemblyCode(std::ostream& out, std::string& errMsg); @@ -59,7 +57,7 @@ private: lto_codegen_model _codeModel; StringSet _mustPreserveSymbols; llvm::MemoryBuffer* _nativeObjectFile; - llvm::SmallVector _codegenOptions; + std::vector _codegenOptions; }; #endif // LTO_CODE_GENERATOR_H diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index b674f3171ef..227823f32f4 100644 --- a/tools/lto/lto.cpp +++ b/tools/lto/lto.cpp @@ -237,6 +237,10 @@ lto_codegen_compile(lto_code_gen_t cg, size_t* length) return cg->compile(length, sLastErrorString); } + +// +// Used to pass extra options to the code generator +// extern void lto_codegen_debug_options(lto_code_gen_t cg, const char * opt) {