[llvm] r235943 - LTO: Add API to choose whether to embed uselists

Duncan P. N. Exon Smith dexonsmith at apple.com
Mon Apr 27 16:38:54 PDT 2015


Author: dexonsmith
Date: Mon Apr 27 18:38:54 2015
New Revision: 235943

URL: http://llvm.org/viewvc/llvm-project?rev=235943&view=rev
Log:
LTO: Add API to choose whether to embed uselists

Reverse libLTO's default behaviour for preserving use-list order in
bitcode, and add API for controlling it.  The default setting is now
`false` (don't preserve them), which is consistent with `clang`'s
default behaviour.

Users of libLTO should call `lto_codegen_should_embed_uselists(CG,true)`
prior to calling `lto_codegen_write_merged_modules()` whenever the
output file isn't part of the production workflow in order to reproduce
results with subsequent calls to `llc`.

(I haven't added tests since `llvm-lto` (the test tool for LTO) doesn't
support bitcode output, and even if it did: there isn't actually a good
way to test whether a tool has passed the flag.  If the order is already
"natural" (if the order will already round-trip) then no use-list
directives are emitted at all.  At some point I'll circle back to add
tests to `llvm-as` (etc.) that they actually respect the flag, at which
point I can somehow add a test here as well.)

Modified:
    llvm/trunk/include/llvm-c/lto.h
    llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
    llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
    llvm/trunk/tools/lto/lto.cpp

Modified: llvm/trunk/include/llvm-c/lto.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/lto.h?rev=235943&r1=235942&r2=235943&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/lto.h (original)
+++ llvm/trunk/include/llvm-c/lto.h Mon Apr 27 18:38:54 2015
@@ -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

Modified: llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h?rev=235943&r1=235942&r2=235943&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h (original)
+++ llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h Mon Apr 27 18:38:54 2015
@@ -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

Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=235943&r1=235942&r2=235943&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Mon Apr 27 18:38:54 2015
@@ -202,8 +202,7 @@ bool LTOCodeGenerator::writeMergedModule
   }
 
   // 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()) {

Modified: llvm/trunk/tools/lto/lto.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/lto.cpp?rev=235943&r1=235942&r2=235943&view=diff
==============================================================================
--- llvm/trunk/tools/lto/lto.cpp (original)
+++ llvm/trunk/tools/lto/lto.cpp Mon Apr 27 18:38:54 2015
@@ -338,3 +338,8 @@ void lto_codegen_set_should_internalize(
                                         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);
+}





More information about the llvm-commits mailing list