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

Mircea Trofin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 8 17:32:13 PDT 2020


mtrofin created this revision.
mtrofin added reviewers: tejohnson, zapster.
Herald added subscribers: llvm-commits, dexonsmith, steven_wu, hiraditya, inglorion.
Herald added a project: LLVM.
mtrofin requested review of this revision.

llvm::EmbedBitcodeInModule handles serializing the passed-in module, if
the provided MemoryBufferRef is invalid. This is already the path taken
in one of the uses of the API - clang::EmbedBitcode, when called from
BackendConsumer::HandleTranslationUnit - so might as well do the same
here and reduce (by very little) code duplication.

The only difference this patch introduces is that the serialization happens
with ShouldPreserveUseListOrder set to true.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87339

Files:
  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);
 }
 


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


More information about the llvm-commits mailing list