1 //===-- llvm/Bitcode/BitcodeWriter.h - Bitcode writers ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This header defines interfaces to write LLVM bitcode files/streams.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_BITCODE_BITCODEWRITER_H
15 #define LLVM_BITCODE_BITCODEWRITER_H
17 #include "llvm/IR/ModuleSummaryIndex.h"
18 #include "llvm/MC/StringTableBuilder.h"
22 class BitstreamWriter;
27 SmallVectorImpl<char> &Buffer;
28 std::unique_ptr<BitstreamWriter> Stream;
30 StringTableBuilder StrtabBuilder{StringTableBuilder::RAW};
31 bool WroteStrtab = false;
33 void writeBlob(unsigned Block, unsigned Record, StringRef Blob);
36 /// Create a BitcodeWriter that writes to Buffer.
37 BitcodeWriter(SmallVectorImpl<char> &Buffer);
41 /// Write the bitcode file's string table. This must be called exactly once
42 /// after all modules have been written.
45 /// Copy the string table for another module into this bitcode file. This
46 /// should be called after copying the module itself into the bitcode file.
47 void copyStrtab(StringRef Strtab);
49 /// Write the specified module to the buffer specified at construction time.
51 /// If \c ShouldPreserveUseListOrder, encode the use-list order for each \a
52 /// Value in \c M. These will be reconstructed exactly when \a M is
55 /// If \c Index is supplied, the bitcode will contain the summary index
56 /// (currently for use in ThinLTO optimization).
58 /// \p GenerateHash enables hashing the Module and including the hash in the
59 /// bitcode (currently for use in ThinLTO incremental build).
61 /// If \p ModHash is non-null, when GenerateHash is true, the resulting
62 /// hash is written into ModHash. When GenerateHash is false, that value
63 /// is used as the hash instead of computing from the generated bitcode.
64 /// Can be used to produce the same module hash for a minimized bitcode
65 /// used just for the thin link as in the regular full bitcode that will
66 /// be used in the backend.
67 void writeModule(const Module *M, bool ShouldPreserveUseListOrder = false,
68 const ModuleSummaryIndex *Index = nullptr,
69 bool GenerateHash = false, ModuleHash *ModHash = nullptr);
72 /// \brief Write the specified module to the specified raw output stream.
74 /// For streams where it matters, the given stream should be in "binary"
77 /// If \c ShouldPreserveUseListOrder, encode the use-list order for each \a
78 /// Value in \c M. These will be reconstructed exactly when \a M is
81 /// If \c Index is supplied, the bitcode will contain the summary index
82 /// (currently for use in ThinLTO optimization).
84 /// \p GenerateHash enables hashing the Module and including the hash in the
85 /// bitcode (currently for use in ThinLTO incremental build).
87 /// If \p ModHash is non-null, when GenerateHash is true, the resulting
88 /// hash is written into ModHash. When GenerateHash is false, that value
89 /// is used as the hash instead of computing from the generated bitcode.
90 /// Can be used to produce the same module hash for a minimized bitcode
91 /// used just for the thin link as in the regular full bitcode that will
92 /// be used in the backend.
93 void WriteBitcodeToFile(const Module *M, raw_ostream &Out,
94 bool ShouldPreserveUseListOrder = false,
95 const ModuleSummaryIndex *Index = nullptr,
96 bool GenerateHash = false,
97 ModuleHash *ModHash = nullptr);
99 /// Write the specified module summary index to the given raw output stream,
100 /// where it will be written in a new bitcode block. This is used when
101 /// writing the combined index file for ThinLTO. When writing a subset of the
102 /// index for a distributed backend, provide the \p ModuleToSummariesForIndex
104 void WriteIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out,
105 const std::map<std::string, GVSummaryMapTy>
106 *ModuleToSummariesForIndex = nullptr);
107 } // End llvm namespace