[LTO API] add lto_codegen_set_should_internalize.
authorManman Ren <manman.ren@gmail.com>
Fri, 17 Apr 2015 17:10:09 +0000 (17:10 +0000)
committerManman Ren <manman.ren@gmail.com>
Fri, 17 Apr 2015 17:10:09 +0000 (17:10 +0000)
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
include/llvm/LTO/LTOCodeGenerator.h
lib/LTO/LTOCodeGenerator.cpp
tools/lto/lto.cpp
tools/lto/lto.exports

index c6acdaddca535e3a1cae32ddd451a3272a3cccc3..2f3aac7ed878cdf9febca4cd45b118f3c31c5a78 100644 (file)
@@ -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
index a4aace41a72d6052f49070b05964695b5e19916f..ff3b71a1a0e91ffee662739c65c57a3083601c93 100644 (file)
@@ -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
index b4a70119cc2c8d4066dc61f2aef23ec11a909d4b..16718d7ce647b9f88707371e4c27b869e459faec 100644 (file)
@@ -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<StringRef> &Libcalls,
 }
 
 void LTOCodeGenerator::applyScopeRestrictions() {
-  if (ScopeRestrictionsDone)
+  if (ScopeRestrictionsDone || !ShouldInternalize)
     return;
   Module *mergedModule = IRLinker.getModule();
 
index cc4169fda99183e75412f43254587fff40f1a55c..e66a7786a146283c35b5cfde9686a9bce4475534 100644 (file)
@@ -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);
+}
index 8729050123e690183962ec1a0e09c7af3148417d..9145a6ff4dd4602797e4b1fde701803104446475 100644 (file)
@@ -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