Flush bitcode incrementally for LTO output
authorJianzhou Zhao <jianzhouzh@google.com>
Sat, 12 Sep 2020 19:35:17 +0000 (19:35 +0000)
committerJianzhou Zhao <jianzhouzh@google.com>
Thu, 17 Sep 2020 03:32:31 +0000 (03:32 +0000)
commit11201315d5881a135faa5aa87f415ce03f99eb96
tree7d2e982303df86e2ae2a47bbffb0fb5a4090f5c3
parent0dd4d70ec20cebb951bd2e0e6525b056fb8dc86c
Flush bitcode incrementally for LTO output

Bitcode writer does not flush buffer until the end by default. This is
fine to small bitcode files. When -flto,--plugin-opt=emit-llvm,-gmlt are
used, the final bitcode file is large, for example, >8G. Keeping all
data in memory consumes a lot of memory.

This change allows bitcode writer flush data to disk early when buffered
data size is above some threshold. This is only enabled when lld emits
LLVM bitcode.

One issue to address is backpatching bitcode: subblock length, function
body indexes, meta data indexes need to backfill. If buffer can be
flushed partially, we introduced raw_fd_stream that supports
read/seek/write, and enables backpatching bitcode flushed in disk.

Reviewed-by: tejohnson, MaskRay
Differential Revision: https://reviews.llvm.org/D86905
lld/ELF/LTO.cpp
llvm/include/llvm/Bitcode/BitcodeWriter.h
llvm/include/llvm/Bitstream/BitstreamWriter.h
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp