[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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228000 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Manman Ren
2015-02-03 18:39:15 +00:00
parent 42a7bc535e
commit 69e4dd1b12
5 changed files with 128 additions and 30 deletions

View File

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