]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/Bitcode/BitcodeWriter.h
Merge llvm, clang, lld and lldb trunk r300890, and update build glue.
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / Bitcode / BitcodeWriter.h
1 //===-- llvm/Bitcode/BitcodeWriter.h - Bitcode writers ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This header defines interfaces to write LLVM bitcode files/streams.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_BITCODE_BITCODEWRITER_H
15 #define LLVM_BITCODE_BITCODEWRITER_H
16
17 #include "llvm/IR/ModuleSummaryIndex.h"
18 #include "llvm/MC/StringTableBuilder.h"
19 #include <string>
20
21 namespace llvm {
22   class BitstreamWriter;
23   class Module;
24   class raw_ostream;
25
26   class BitcodeWriter {
27     SmallVectorImpl<char> &Buffer;
28     std::unique_ptr<BitstreamWriter> Stream;
29
30     StringTableBuilder StrtabBuilder{StringTableBuilder::RAW};
31     bool WroteStrtab = false;
32
33     void writeBlob(unsigned Block, unsigned Record, StringRef Blob);
34
35    public:
36     /// Create a BitcodeWriter that writes to Buffer.
37     BitcodeWriter(SmallVectorImpl<char> &Buffer);
38
39     ~BitcodeWriter();
40
41     /// Write the bitcode file's string table. This must be called exactly once
42     /// after all modules have been written.
43     void writeStrtab();
44
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);
48
49     /// Write the specified module to the buffer specified at construction time.
50     ///
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
53     /// deserialized.
54     ///
55     /// If \c Index is supplied, the bitcode will contain the summary index
56     /// (currently for use in ThinLTO optimization).
57     ///
58     /// \p GenerateHash enables hashing the Module and including the hash in the
59     /// bitcode (currently for use in ThinLTO incremental build).
60     ///
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);
70   };
71
72   /// \brief Write the specified module to the specified raw output stream.
73   ///
74   /// For streams where it matters, the given stream should be in "binary"
75   /// mode.
76   ///
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
79   /// deserialized.
80   ///
81   /// If \c Index is supplied, the bitcode will contain the summary index
82   /// (currently for use in ThinLTO optimization).
83   ///
84   /// \p GenerateHash enables hashing the Module and including the hash in the
85   /// bitcode (currently for use in ThinLTO incremental build).
86   ///
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);
98
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
103   /// map.
104   void WriteIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out,
105                         const std::map<std::string, GVSummaryMapTy>
106                             *ModuleToSummariesForIndex = nullptr);
107 } // End llvm namespace
108
109 #endif