diff options
author | Manman Ren <manman.ren@gmail.com> | 2015-02-03 18:39:15 +0000 |
---|---|---|
committer | Manman Ren <manman.ren@gmail.com> | 2015-02-03 18:39:15 +0000 |
commit | 8121e1db917e2a65bfaa2f4fc59415b25f5221df (patch) | |
tree | 1a71eb558daf7fd542a12614c2d508fdbf4a843b /llvm/lib/LTO/LTOCodeGenerator.cpp | |
parent | 9148e1721c08c955138746716f19d62c3657badf (diff) | |
download | bcm5719-llvm-8121e1db917e2a65bfaa2f4fc59415b25f5221df.tar.gz bcm5719-llvm-8121e1db917e2a65bfaa2f4fc59415b25f5221df.zip |
[LTO API] split lto_codegen_compile to lto_codegen_optimize and
lto_codegen_compile_optimized. Also add lto_api_version.
Before this commit, we can only dump the optimized bitcode after running
lto_codegen_compile, but it includes some impacts of running codegen passes,
one example is StackProtector pass. We will get assertion failure when running
llc on the optimized bitcode, because StackProtector is effectively run twice.
After splitting lto_codegen_compile, the linker can choose to dump the bitcode
before running lto_codegen_compile_optimized.
lto_api_version is added so ld64 can check for runtime-availability of the new
API.
rdar://19565500
llvm-svn: 228000
Diffstat (limited to 'llvm/lib/LTO/LTOCodeGenerator.cpp')
-rw-r--r-- | llvm/lib/LTO/LTOCodeGenerator.cpp | 79 |
1 files changed, 53 insertions, 26 deletions
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp index 27b87764065..f37d0a9fa44 100644 --- a/llvm/lib/LTO/LTOCodeGenerator.cpp +++ b/llvm/lib/LTO/LTOCodeGenerator.cpp @@ -202,12 +202,8 @@ bool LTOCodeGenerator::writeMergedModules(const char *path, return true; } -bool LTOCodeGenerator::compile_to_file(const char** name, - bool disableOpt, - bool disableInline, - bool disableGVNLoadPRE, - bool disableVectorization, - std::string& errMsg) { +bool LTOCodeGenerator::compileOptimizedToFile(const char **name, + std::string &errMsg) { // make unique temp .o file to put generated object file SmallString<128> Filename; int FD; @@ -221,9 +217,7 @@ bool LTOCodeGenerator::compile_to_file(const char** name, // generate object file tool_output_file objFile(Filename.c_str(), FD); - bool genResult = - generateObjectFile(objFile.os(), disableOpt, disableInline, - disableGVNLoadPRE, disableVectorization, errMsg); + bool genResult = compileOptimized(objFile.os(), errMsg); objFile.os().close(); if (objFile.os().has_error()) { objFile.os().clear_error(); @@ -242,15 +236,10 @@ bool LTOCodeGenerator::compile_to_file(const char** name, return true; } -const void* LTOCodeGenerator::compile(size_t* length, - bool disableOpt, - bool disableInline, - bool disableGVNLoadPRE, - bool disableVectorization, - std::string& errMsg) { +const void *LTOCodeGenerator::compileOptimized(size_t *length, + std::string &errMsg) { const char *name; - if (!compile_to_file(&name, disableOpt, disableInline, disableGVNLoadPRE, - disableVectorization, errMsg)) + if (!compileOptimizedToFile(&name, errMsg)) return nullptr; // read .o file into memory buffer @@ -273,6 +262,33 @@ const void* LTOCodeGenerator::compile(size_t* length, return NativeObjectFile->getBufferStart(); } + +bool LTOCodeGenerator::compile_to_file(const char **name, + bool disableOpt, + bool disableInline, + bool disableGVNLoadPRE, + bool disableVectorization, + std::string &errMsg) { + if (!optimize(disableOpt, disableInline, disableGVNLoadPRE, + disableVectorization, errMsg)) + return false; + + return compileOptimizedToFile(name, errMsg); +} + +const void* LTOCodeGenerator::compile(size_t *length, + bool disableOpt, + bool disableInline, + bool disableGVNLoadPRE, + bool disableVectorization, + std::string &errMsg) { + if (!optimize(disableOpt, disableInline, disableGVNLoadPRE, + disableVectorization, errMsg)) + return nullptr; + + return compileOptimized(length, errMsg); +} + bool LTOCodeGenerator::determineTarget(std::string &errMsg) { if (TargetMach) return true; @@ -469,12 +485,11 @@ void LTOCodeGenerator::applyScopeRestrictions() { } /// Optimize merged modules using various IPO passes -bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, - bool DisableOpt, - bool DisableInline, - bool DisableGVNLoadPRE, - bool DisableVectorization, - std::string &errMsg) { +bool LTOCodeGenerator::optimize(bool DisableOpt, + bool DisableInline, + bool DisableGVNLoadPRE, + bool DisableVectorization, + std::string &errMsg) { if (!this->determineTarget(errMsg)) return false; @@ -508,6 +523,21 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, PMB.populateLTOPassManager(passes); + // Run our queue of passes all at once now, efficiently. + passes.run(*mergedModule); + + return true; +} + +bool LTOCodeGenerator::compileOptimized(raw_ostream &out, std::string &errMsg) { + if (!this->determineTarget(errMsg)) + return false; + + Module *mergedModule = IRLinker.getModule(); + + // Mark which symbols can not be internalized + this->applyScopeRestrictions(); + PassManager codeGenPasses; codeGenPasses.add(new DataLayoutPass()); @@ -524,9 +554,6 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, return false; } - // Run our queue of passes all at once now, efficiently. - passes.run(*mergedModule); - // Run the code generator, and write assembly file codeGenPasses.run(*mergedModule); |