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
This commit is contained in:
Nick Kledzik 2008-07-08 21:14:10 +00:00
parent 71e8685633
commit 920ae9863b
3 changed files with 27 additions and 17 deletions

View File

@ -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()));
}
}

View File

@ -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

View File

@ -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)
{