From 44b800f44d61d5377a96f187deb20901b94ea279 Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Fri, 17 Apr 2015 17:10:09 +0000 Subject: [PATCH] [LTO API] add lto_codegen_set_should_internalize. When debugging LTO issues with ld64, we use -save-temps to save the merged optimized bitcode file, then invoke ld64 again on the single bitcode file. The saved bitcode file is already internalized, so we can call lto_codegen_set_should_internalize and skip running internalization again. rdar://20227235 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235211 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm-c/lto.h | 12 +++++++++++- include/llvm/LTO/LTOCodeGenerator.h | 3 +++ lib/LTO/LTOCodeGenerator.cpp | 3 ++- tools/lto/lto.cpp | 5 +++++ tools/lto/lto.exports | 1 + 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/llvm-c/lto.h b/include/llvm-c/lto.h index c6acdaddca5..2f3aac7ed87 100644 --- a/include/llvm-c/lto.h +++ b/include/llvm-c/lto.h @@ -40,7 +40,7 @@ typedef bool lto_bool_t; * @{ */ -#define LTO_API_VERSION 13 +#define LTO_API_VERSION 14 /** * \since prior to LTO_API_VERSION=3 @@ -548,6 +548,16 @@ lto_codegen_debug_options(lto_code_gen_t cg, const char *); extern void lto_initialize_disassembler(void); +/** + * Sets if we should run internalize pass during optimization and code + * generation. + * + * \since prior to LTO_API_VERSION=14 + */ +extern void +lto_codegen_set_should_internalize(lto_code_gen_t cg, + lto_bool_t ShouldInternalize); + #ifdef __cplusplus } #endif diff --git a/include/llvm/LTO/LTOCodeGenerator.h b/include/llvm/LTO/LTOCodeGenerator.h index a4aace41a72..ff3b71a1a0e 100644 --- a/include/llvm/LTO/LTOCodeGenerator.h +++ b/include/llvm/LTO/LTOCodeGenerator.h @@ -79,6 +79,8 @@ struct LTOCodeGenerator { void setAttr(const char *mAttr) { MAttr = mAttr; } void setOptLevel(unsigned optLevel) { OptLevel = optLevel; } + void setShouldInternalize(bool Value) { ShouldInternalize = Value; } + void addMustPreserveSymbol(const char *sym) { MustPreserveSymbols[sym] = 1; } // To pass options to the driver and optimization passes. These options are @@ -174,6 +176,7 @@ private: lto_diagnostic_handler_t DiagHandler; void *DiagContext; LTOModule *OwnedModule; + bool ShouldInternalize; }; } #endif diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp index b4a70119cc2..16718d7ce64 100644 --- a/lib/LTO/LTOCodeGenerator.cpp +++ b/lib/LTO/LTOCodeGenerator.cpp @@ -82,6 +82,7 @@ void LTOCodeGenerator::initialize() { DiagHandler = nullptr; DiagContext = nullptr; OwnedModule = nullptr; + ShouldInternalize = true; initializeLTOPasses(); } @@ -464,7 +465,7 @@ static void accumulateAndSortLibcalls(std::vector &Libcalls, } void LTOCodeGenerator::applyScopeRestrictions() { - if (ScopeRestrictionsDone) + if (ScopeRestrictionsDone || !ShouldInternalize) return; Module *mergedModule = IRLinker.getModule(); diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index cc4169fda99..e66a7786a14 100644 --- a/tools/lto/lto.cpp +++ b/tools/lto/lto.cpp @@ -333,3 +333,8 @@ void lto_codegen_debug_options(lto_code_gen_t cg, const char *opt) { } unsigned int lto_api_version() { return LTO_API_VERSION; } + +void lto_codegen_set_should_internalize(lto_code_gen_t cg, + bool ShouldInternalize) { + unwrap(cg)->setShouldInternalize(ShouldInternalize); +} diff --git a/tools/lto/lto.exports b/tools/lto/lto.exports index 8729050123e..9145a6ff4dd 100644 --- a/tools/lto/lto.exports +++ b/tools/lto/lto.exports @@ -41,6 +41,7 @@ lto_codegen_set_cpu lto_codegen_compile_to_file lto_codegen_optimize lto_codegen_compile_optimized +lto_codegen_set_should_internalize LLVMCreateDisasm LLVMCreateDisasmCPU LLVMDisasmDispose -- 2.34.1