[llvm] Unittests and usability for BitstreamWriter incremental flushing (PR #92983)
Mircea Trofin via llvm-commits
llvm-commits at lists.llvm.org
Wed May 29 14:18:59 PDT 2024
================
@@ -5047,27 +5050,28 @@ void llvm::WriteBitcodeToFile(const Module &M, raw_ostream &Out,
bool ShouldPreserveUseListOrder,
const ModuleSummaryIndex *Index,
bool GenerateHash, ModuleHash *ModHash) {
- SmallVector<char, 0> Buffer;
- Buffer.reserve(256*1024);
-
- // If this is darwin or another generic macho target, reserve space for the
- // header.
+ auto Write = [&](BitcodeWriter &Writer) {
+ Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
+ ModHash);
+ Writer.writeSymtab();
+ Writer.writeStrtab();
+ };
Triple TT(M.getTargetTriple());
- if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
+ if (TT.isOSDarwin() || TT.isOSBinFormatMachO()) {
+ // If this is darwin or another generic macho target, reserve space for the
+ // header. Note that the header is computed *after* the output is known, so
+ // we currently expliclty use a buffer, write to it, and then subsequently
+ // flush to Out.
+ SmallVector<char, 256 * 1024> Buffer;
Buffer.insert(Buffer.begin(), BWH_HeaderSize, 0);
-
- BitcodeWriter Writer(Buffer, dyn_cast<raw_fd_stream>(&Out));
- Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
- ModHash);
- Writer.writeSymtab();
- Writer.writeStrtab();
-
- if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
+ BitcodeWriter Writer(Buffer);
+ Write(Writer);
emitDarwinBCHeaderAndTrailer(Buffer, TT);
----------------
mtrofin wrote:
it won't be - that's the thing, in this case, we use our own Buffer which won't get flushed - there's nowhere to flush (insofar as the bitcode writer is concerned). See the comment above the declaration of `Buffer`, too.
https://github.com/llvm/llvm-project/pull/92983
More information about the llvm-commits
mailing list