diff --git a/include/llvm-c/lto.h b/include/llvm-c/lto.h index 9d0d7263a58..1db077822ae 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 14 +#define LTO_API_VERSION 15 /** * \since prior to LTO_API_VERSION=3 @@ -558,6 +558,18 @@ extern void lto_codegen_set_should_internalize(lto_code_gen_t cg, lto_bool_t ShouldInternalize); +/** + * \brief Set whether to embed uselists in bitcode. + * + * Sets whether \a lto_codegen_write_merged_modules() should embed uselists in + * output bitcode. This should be turned on for all -save-temps output. + * + * \since LTO_API_VERSION=15 + */ +extern void +lto_codegen_set_should_embed_uselists(lto_code_gen_t cg, + lto_bool_t ShouldEmbedUselists); + #ifdef __cplusplus } #endif diff --git a/include/llvm/LTO/LTOCodeGenerator.h b/include/llvm/LTO/LTOCodeGenerator.h index 88156304344..3b4be81b223 100644 --- a/include/llvm/LTO/LTOCodeGenerator.h +++ b/include/llvm/LTO/LTOCodeGenerator.h @@ -80,6 +80,7 @@ struct LTOCodeGenerator { void setOptLevel(unsigned optLevel) { OptLevel = optLevel; } void setShouldInternalize(bool Value) { ShouldInternalize = Value; } + void setShouldEmbedUselists(bool Value) { ShouldEmbedUselists = Value; } void addMustPreserveSymbol(const char *sym) { MustPreserveSymbols[sym] = 1; } @@ -176,6 +177,7 @@ private: void *DiagContext = nullptr; LTOModule *OwnedModule = nullptr; bool ShouldInternalize = true; + bool ShouldEmbedUselists = false; }; } #endif diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp index 6a19849e668..3cf13a0ef2c 100644 --- a/lib/LTO/LTOCodeGenerator.cpp +++ b/lib/LTO/LTOCodeGenerator.cpp @@ -202,8 +202,7 @@ bool LTOCodeGenerator::writeMergedModules(const char *path, } // write bitcode to it - WriteBitcodeToFile(IRLinker.getModule(), Out.os(), - /* ShouldPreserveUseListOrder */ true); + WriteBitcodeToFile(IRLinker.getModule(), Out.os(), ShouldEmbedUselists); Out.os().close(); if (Out.os().has_error()) { diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index e66a7786a14..d6ceebed728 100644 --- a/tools/lto/lto.cpp +++ b/tools/lto/lto.cpp @@ -338,3 +338,8 @@ void lto_codegen_set_should_internalize(lto_code_gen_t cg, bool ShouldInternalize) { unwrap(cg)->setShouldInternalize(ShouldInternalize); } + +void lto_codegen_set_should_embed_uselists(lto_code_gen_t cg, + lto_bool_t ShouldEmbedUselists) { + unwrap(cg)->setShouldEmbedUselists(ShouldEmbedUselists); +}