diff options
author | Nick Kledzik <kledzik@apple.com> | 2008-07-08 21:14:10 +0000 |
---|---|---|
committer | Nick Kledzik <kledzik@apple.com> | 2008-07-08 21:14:10 +0000 |
commit | 920ae9863b51ce1e33a1bf702e672e0483c04cd8 (patch) | |
tree | 6f084860ab58fbc4f521a22089811f3d62f53977 /tools/lto | |
parent | 71e8685633e7938ee752004cceedccbd0d850527 (diff) | |
download | external_llvm-920ae9863b51ce1e33a1bf702e672e0483c04cd8.zip external_llvm-920ae9863b51ce1e33a1bf702e672e0483c04cd8.tar.gz external_llvm-920ae9863b51ce1e33a1bf702e672e0483c04cd8.tar.bz2 |
fix dangling pointer and argv off by one errors. Add support for --disable-inlining
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53249 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/lto')
-rw-r--r-- | tools/lto/LTOCodeGenerator.cpp | 34 | ||||
-rw-r--r-- | tools/lto/LTOCodeGenerator.h | 6 | ||||
-rw-r--r-- | tools/lto/lto.cpp | 4 |
3 files changed, 27 insertions, 17 deletions
diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index a07247e..e60dc17 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<bool> 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<const char *> 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 24a2ba3..d3a2b6b 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<std::string, 4> _codegenOptions; + std::vector<const char*> _codegenOptions; }; #endif // LTO_CODE_GENERATOR_H diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index b674f31..227823f 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) { |