Add a hook to turn on the internalize pass through the LTO interface.
authorBill Wendling <isanbard@gmail.com>
Mon, 9 Apr 2012 05:26:48 +0000 (05:26 +0000)
committerBill Wendling <isanbard@gmail.com>
Mon, 9 Apr 2012 05:26:48 +0000 (05:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154306 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm-c/lto.h
tools/lto/LTOCodeGenerator.cpp
tools/lto/LTOCodeGenerator.h
tools/lto/lto.cpp
tools/lto/lto.exports

index f822b475249e25164c994edb8389dd0452bfbbc9..c0f4c6b30c8c1d7297480123f73d17345826539c 100644 (file)
@@ -250,6 +250,12 @@ extern void
 lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args,
                                int nargs);
 
+/**
+ * Enables the internalize pass during LTO optimizations.
+ */
+extern void
+lto_codegen_whole_program_optimization(lto_code_gen_t cg);
+
 /**
  * Adds to a list of all global symbols that must exist in the final
  * generated code.  If a function is not listed, it might be
@@ -258,7 +264,6 @@ lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args,
 extern void
 lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol);
 
-
 /**
  * Writes a new object file at the specified path that contains the
  * merged contents of all modules added so far.
@@ -267,7 +272,6 @@ lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol);
 extern bool
 lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path);
 
-
 /**
  * Generates code for all added modules into one native object file.
  * On success returns a pointer to a generated mach-o/ELF buffer and
index 0e61c2fb2a5685e86944a36778237ad82bab6e21..7620bcb1c1802a179d849e465b7b8954a18c3946 100644 (file)
@@ -67,7 +67,7 @@ LTOCodeGenerator::LTOCodeGenerator()
   : _context(getGlobalContext()),
     _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL),
     _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false),
-    _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
+    _runInternalizePass(false), _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
     _nativeObjectFile(NULL) {
   InitializeAllTargets();
   InitializeAllTargetMCs();
@@ -366,7 +366,8 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
   // Add an appropriate TargetData instance for this module...
   passes.add(new TargetData(*_target->getTargetData()));
 
-  PassManagerBuilder().populateLTOPassManager(passes, /*Internalize=*/ false,
+  PassManagerBuilder().populateLTOPassManager(passes,
+                                              _runInternalizePass,
                                               !DisableInline,
                                               DisableGVNLoadPRE);
 
index 3081b7dad1d18c7e819a9984c7e0be17962cf384..bac3e6efe909257bd02b64d341e9945654336430 100644 (file)
@@ -54,6 +54,8 @@ struct LTOCodeGenerator {
   const void *compile(size_t *length, std::string &errMsg);
   void setCodeGenDebugOptions(const char *opts);
 
+  void enableInternalizePass() { _runInternalizePass = true; }
+
 private:
   bool generateObjectFile(llvm::raw_ostream &out, std::string &errMsg);
   void applyScopeRestrictions();
@@ -70,6 +72,7 @@ private:
   llvm::TargetMachine*        _target;
   bool                        _emitDwarfDebugInfo;
   bool                        _scopeRestrictionsDone;
+  bool                        _runInternalizePass;
   lto_codegen_model           _codeModel;
   StringSet                   _mustPreserveSymbols;
   StringSet                   _asmUndefinedRefs;
index a7e633d14b9dc264957bc471273bda004a0a6e6f..e523eb390187ea8290f0493feff88388484fc0f3 100644 (file)
@@ -183,6 +183,12 @@ void lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg,
   cg->addMustPreserveSymbol(symbol);
 }
 
+/// lto_codegen_whole_program_optimization - Enable the internalize pass during
+/// LTO optimizations.
+void lto_codegen_whole_program_optimization(lto_code_gen_t cg) {
+  cg->enableInternalizePass();
+}
+
 /// lto_codegen_write_merged_modules - Writes a new file at the specified path
 /// that contains the merged contents of all modules added so far. Returns true
 /// on error (check lto_get_error_message() for details).
index b900bfb594b1e5cd14f4ce47c2c62c6d77b8382b..1726388c0ae0e166b98d20f7b2b9a25704089e4c 100644 (file)
@@ -27,6 +27,7 @@ lto_codegen_set_assembler_args
 lto_codegen_set_assembler_path
 lto_codegen_set_cpu
 lto_codegen_compile_to_file
+lto_codegen_whole_program_optimization
 LLVMCreateDisasm
 LLVMDisasmDispose
 LLVMDisasmInstruction