LLVM: include/llvm/Bitcode/BitcodeReader.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_BITCODE_BITCODEREADER_H
14#define LLVM_BITCODE_BITCODEREADER_H
15
24#include
25#include
26#include
27#include
28#include <system_error>
29#include
30namespace llvm {
31
32class LLVMContext;
34class MemoryBuffer;
36class ModuleSummaryIndex;
39
40
41
42
43
44typedef std::function<std::optionalstd::string(StringRef, StringRef)>
46
48
50
54
58
59
60
61
62
64
65template
67 if (!Val)
69 return std::move(*Val);
70}
71
73 std::optional DataLayout;
74
75
76
77
78
79
80
82
84
88};
89
90 struct BitcodeFileContents;
91
92
98 };
99
100
102
105
106
108
109
111
112
114
117 : Buffer(Buffer), ModuleIdentifier(ModuleIdentifier),
118 IdentificationBit(IdentificationBit), ModuleBit(ModuleBit) {}
119
120
123
125 getModuleImpl(LLVMContext &Context, bool MaterializeAll,
126 bool ShouldLazyLoadMetadata, bool IsImporting,
128
129 public:
132 }
133
135
137
138
139
140
141
145
146
147 Expected<std::unique_ptr>
148 parseModule(LLVMContext &Context, ParserCallbacks Callbacks = {});
149
150
151
152 Expected getLTOInfo();
153
154
155 Expected<std::unique_ptr> getSummary();
156
157
158
160 readSummary(ModuleSummaryIndex &CombinedIndex, StringRef ModulePath,
162 };
163
167 };
168
169
170
171
172
173
175
176
179
180
181
182
183
186 bool ShouldLazyLoadMetadata = false,
187 bool IsImporting = false,
189
190
191
192
193
195 std::unique_ptr &&Buffer, LLVMContext &Context,
196 bool ShouldLazyLoadMetadata = false, bool IsImporting = false,
197 ParserCallbacks Callbacks = {});
198
199
200
201
203
204
205
207
208
209
210
212
213
214 Expected<std::unique_ptr>
215 parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context,
216 ParserCallbacks Callbacks = {});
217
218
219 Expected getBitcodeLTOInfo(MemoryBufferRef Buffer);
220
221
222 Expected<std::unique_ptr>
224
225
227 ModuleSummaryIndex &CombinedIndex);
228
229
230
231
232
233 Expected<std::unique_ptr>
235 bool IgnoreEmptyThinLTOIndexFile = false);
236
237
238
240 const unsigned char *BufEnd) {
241
242
243 return BufPtr != BufEnd &&
244 BufPtr[0] == 0xDE &&
245 BufPtr[1] == 0xC0 &&
246 BufPtr[2] == 0x17 &&
247 BufPtr[3] == 0x0B;
248 }
249
250
251
253 const unsigned char *BufEnd) {
254
255
256 return BufPtr != BufEnd &&
257 BufPtr[0] == 'B' &&
258 BufPtr[1] == 'C' &&
259 BufPtr[2] == 0xc0 &&
260 BufPtr[3] == 0xde;
261 }
262
263
264
265 inline bool isBitcode(const unsigned char *BufPtr,
266 const unsigned char *BufEnd) {
269 }
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
288 const unsigned char *&BufEnd,
289 bool VerifyBufferSize) {
290
291 if (unsigned(BufEnd - BufPtr) < BWH_SizeField + 4)
292 return true;
293
297
298
299 if (VerifyBufferSize && BitcodeOffsetEnd > uint64_t(BufEnd-BufPtr))
300 return true;
302 BufEnd = BufPtr+Size;
303 return false;
304 }
305
306 APInt readWideAPInt(ArrayRef<uint64_t> Vals, unsigned TypeBits);
307
312 }
313
314}
315
316namespace std {
317
318template <> struct is_error_code_enum<llvm::BitcodeError> : std::true_type {};
319
320}
321
322#endif
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Provides ErrorOr smart pointer.
Machine Check Debug Module
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
Represents a module in a bitcode file.
StringRef getModuleIdentifier() const
Expected< std::unique_ptr< ModuleSummaryIndex > > getSummary()
Parse the specified bitcode buffer, returning the module summary index.
Expected< BitcodeLTOInfo > getLTOInfo()
Returns information about the module to be used for LTO: whether to compile with ThinLTO,...
StringRef getBuffer() const
Error readSummary(ModuleSummaryIndex &CombinedIndex, StringRef ModulePath, std::function< bool(GlobalValue::GUID)> IsPrevailing=nullptr)
Parse the specified bitcode buffer and merge its module summary index into CombinedIndex.
Expected< std::unique_ptr< Module > > parseModule(LLVMContext &Context, ParserCallbacks Callbacks={})
Read the entire bitcode module and return it.
StringRef getStrtab() const
friend Expected< BitcodeFileContents > getBitcodeFileContents(MemoryBufferRef Buffer)
Returns the contents of a bitcode file.
Expected< std::unique_ptr< Module > > getLazyModule(LLVMContext &Context, bool ShouldLazyLoadMetadata, bool IsImporting, ParserCallbacks Callbacks={})
Read the bitcode module and prepare for lazy deserialization of function bodies.
A parsed version of the target data layout string in and methods for querying it.
Represents either an error or a value T.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
This is an important class for using LLVM in a threaded context.
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
uint32_t read32le(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
const std::error_category & BitcodeErrorCategory()
Expected< std::unique_ptr< Module > > parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context, ParserCallbacks Callbacks={})
Read the specified bitcode file, returning the module.
std::error_code make_error_code(BitcodeError E)
std::function< Type *(unsigned)> GetTypeByIDTy
Expected< bool > isBitcodeContainingObjCCategory(MemoryBufferRef Buffer)
Return true if Buffer contains a bitcode file with ObjC code (category or class) in it.
std::function< unsigned(unsigned, unsigned)> GetContainedTypeIDTy
Expected< std::string > getBitcodeTargetTriple(MemoryBufferRef Buffer)
Read the header of the specified bitcode buffer and extract just the triple information.
Expected< BitcodeFileContents > getBitcodeFileContents(MemoryBufferRef Buffer)
Returns the contents of a bitcode file.
ErrorOr< T > expectedToErrorOrAndEmitErrors(LLVMContext &Ctx, Expected< T > Val)
bool isRawBitcode(const unsigned char *BufPtr, const unsigned char *BufEnd)
isRawBitcode - Return true if the given bytes are the magic bytes for raw LLVM IR bitcode (without a ...
Expected< std::unique_ptr< ModuleSummaryIndex > > getModuleSummaryIndex(MemoryBufferRef Buffer)
Parse the specified bitcode buffer, returning the module summary index.
Expected< std::string > getBitcodeProducerString(MemoryBufferRef Buffer)
Read the header of the specified bitcode buffer and extract just the producer string information.
Expected< std::unique_ptr< Module > > getLazyBitcodeModule(MemoryBufferRef Buffer, LLVMContext &Context, bool ShouldLazyLoadMetadata=false, bool IsImporting=false, ParserCallbacks Callbacks={})
Read the header of the specified bitcode buffer and prepare for lazy deserialization of function bodi...
std::function< void(Metadata **, unsigned, GetTypeByIDTy, GetContainedTypeIDTy)> MDTypeCallbackTy
Expected< std::vector< BitcodeModule > > getBitcodeModuleList(MemoryBufferRef Buffer)
Returns a list of modules in the specified bitcode buffer.
Expected< BitcodeLTOInfo > getBitcodeLTOInfo(MemoryBufferRef Buffer)
Returns LTO information for the specified bitcode file.
bool SkipBitcodeWrapperHeader(const unsigned char *&BufPtr, const unsigned char *&BufEnd, bool VerifyBufferSize)
SkipBitcodeWrapperHeader - Some systems wrap bc files with a special header for padding or other reas...
bool isBitcodeWrapper(const unsigned char *BufPtr, const unsigned char *BufEnd)
isBitcodeWrapper - Return true if the given bytes are the magic bytes for an LLVM IR bitcode wrapper.
APInt readWideAPInt(ArrayRef< uint64_t > Vals, unsigned TypeBits)
std::function< void(Value *, unsigned, GetTypeByIDTy, GetContainedTypeIDTy)> ValueTypeCallbackTy
std::function< std::optional< std::string >(StringRef, StringRef)> DataLayoutCallbackFuncTy
bool isBitcode(const unsigned char *BufPtr, const unsigned char *BufEnd)
isBitcode - Return true if the given bytes are the magic bytes for LLVM IR bitcode,...
Error readModuleSummaryIndex(MemoryBufferRef Buffer, ModuleSummaryIndex &CombinedIndex)
Parse the specified bitcode buffer and merge the index into CombinedIndex.
Expected< std::unique_ptr< ModuleSummaryIndex > > getModuleSummaryIndexForFile(StringRef Path, bool IgnoreEmptyThinLTOIndexFile=false)
Parse the module summary index out of an IR file and return the module summary index object if found,...
Expected< std::unique_ptr< Module > > getOwningLazyBitcodeModule(std::unique_ptr< MemoryBuffer > &&Buffer, LLVMContext &Context, bool ShouldLazyLoadMetadata=false, bool IsImporting=false, ParserCallbacks Callbacks={})
Like getLazyBitcodeModule, except that the module takes ownership of the memory buffer if successful.
std::error_code errorToErrorCodeAndEmitErrors(LLVMContext &Ctx, Error Err)
Implement std::hash so that hash_code can be used in STL containers.
StringRef StrtabForSymtab
std::vector< BitcodeModule > Mods
Basic information extracted from a bitcode module to be used for LTO.
std::optional< ValueTypeCallbackTy > ValueType
The ValueType callback is called for every function definition or declaration and allows accessing th...
std::optional< DataLayoutCallbackFuncTy > DataLayout
ParserCallbacks(DataLayoutCallbackFuncTy DataLayout)
std::optional< MDTypeCallbackTy > MDType
The MDType callback is called for every value in metadata.
ParserCallbacks()=default