[llvm] Unittests and usability for BitstreamWriter incremental flushing (PR #92983)
Mircea Trofin via llvm-commits
llvm-commits at lists.llvm.org
Fri May 24 12:32:52 PDT 2024
================
@@ -5055,13 +5055,13 @@ void llvm::WriteBitcodeToFile(const Module &M, raw_ostream &Out,
Triple TT(M.getTargetTriple());
if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
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();
-
+ {
----------------
mtrofin wrote:
The problem is line 5070. The buffer should be cleared after being written. That is an alternative. Another one would be to expose a Flush and call it before line 5065.
Ideally we would use a common stream abstraction for both buffer and raw_fd_stream, but IIUC the bitstream writer is pretty chatty and the indirection caused by an abstraction would hurt performance. Templating would hurt reuse - all the users would now have to make a choice or go template, too.
My preference would be to mark very clearly the transitions of ownership: the BitcodeWriter would take ownership of the inputs (so std::move both of them); then if the user wants them back, would call something like `auto [Buffer, FS] = BitcodeWriter::closeAndReclaim(std::move(Writer))` - so Writer would be consumed. This would, however, also impact maybe some the current BitstreamWriter derived classes.
https://github.com/llvm/llvm-project/pull/92983
More information about the llvm-commits
mailing list