[PATCH] D87339: [NFC][ThinLTO] Let llvm::EmbedBitcodeInModule handle serialization.

Mircea Trofin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 9 10:06:12 PDT 2020


mtrofin updated this revision to Diff 290761.
mtrofin added a comment.

comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87339/new/

https://reviews.llvm.org/D87339

Files:
  llvm/include/llvm/Bitcode/BitcodeWriter.h
  llvm/lib/LTO/LTOBackend.cpp


Index: llvm/lib/LTO/LTOBackend.cpp
===================================================================
--- llvm/lib/LTO/LTOBackend.cpp
+++ llvm/lib/LTO/LTOBackend.cpp
@@ -353,13 +353,7 @@
 static void EmitBitcodeSection(Module &M) {
   if (!EmbedBitcode)
     return;
-  SmallVector<char, 0> Buffer;
-  raw_svector_ostream OS(Buffer);
-  WriteBitcodeToFile(M, OS);
-
-  std::unique_ptr<MemoryBuffer> Buf(
-      new SmallVectorMemoryBuffer(std::move(Buffer)));
-  llvm::EmbedBitcodeInModule(M, Buf->getMemBufferRef(), /*EmbedBitcode*/ true,
+  llvm::EmbedBitcodeInModule(M, llvm::MemoryBufferRef(), /*EmbedBitcode*/ true,
                              /*EmbedMarker*/ false, /*CmdArgs*/ nullptr);
 }
 
Index: llvm/include/llvm/Bitcode/BitcodeWriter.h
===================================================================
--- llvm/include/llvm/Bitcode/BitcodeWriter.h
+++ llvm/include/llvm/Bitcode/BitcodeWriter.h
@@ -153,6 +153,10 @@
                             *ModuleToSummariesForIndex = nullptr);
 
   /// Save a copy of the llvm IR as data in the __LLVM,__bitcode section.
+  /// If available, pass the serialized module via the Buf parameter. If not,
+  /// pass an empty (default-initialized) MemoryBufferRef, and the serialization
+  /// will be handled by this API. The same behavior happens if the provided Buf
+  /// is not valid bitcode.
   void EmbedBitcodeInModule(Module &M, MemoryBufferRef Buf, bool EmbedBitcode,
                             bool EmbedMarker,
                             const std::vector<uint8_t> *CmdArgs);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87339.290761.patch
Type: text/x-patch
Size: 1543 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200909/30ffe99d/attachment.bin>


More information about the llvm-commits mailing list