diff options
author | Mircea Trofin <mtrofin@google.com> | 2020-09-08 17:18:04 -0700 |
---|---|---|
committer | Mircea Trofin <mtrofin@google.com> | 2020-09-10 10:25:00 -0700 |
commit | e543708e5ea7af0ec3ef11d6fe932db507472aa1 (patch) | |
tree | a1c76853fbc2f72dd9da2430a853a7616c629316 /llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | |
parent | ab1de1fcfb0c53bc768deb8f8bacefad7d378b7b (diff) | |
download | llvm-e543708e5ea7af0ec3ef11d6fe932db507472aa1.zip llvm-e543708e5ea7af0ec3ef11d6fe932db507472aa1.tar.gz llvm-e543708e5ea7af0ec3ef11d6fe932db507472aa1.tar.bz2 |
[NFC][ThinLTO] Let llvm::EmbedBitcodeInModule handle serialization.
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.
Differential Revision: https://reviews.llvm.org/D87339
Diffstat (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index eaea026..28384bc 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4829,11 +4829,10 @@ void llvm::EmbedBitcodeInModule(llvm::Module &M, llvm::MemoryBufferRef Buf, std::string Data; ArrayRef<uint8_t> ModuleData; Triple T(M.getTargetTriple()); - // Create a constant that contains the bitcode. - // In case of embedding a marker, ignore the input Buf and use the empty - // ArrayRef. It is also legal to create a bitcode marker even Buf is empty. + if (EmbedBitcode) { - if (!isBitcode((const unsigned char *)Buf.getBufferStart(), + if (Buf.getBufferSize() == 0 || + !isBitcode((const unsigned char *)Buf.getBufferStart(), (const unsigned char *)Buf.getBufferEnd())) { // If the input is LLVM Assembly, bitcode is produced by serializing // the module. Use-lists order need to be preserved in this case. |