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

25#include

26#include

27#include

28#include

29#include <system_error>

30#include

31namespace llvm {

32

40

41

42

43

44

45typedef std::function<std::optionalstd::string(StringRef, StringRef)>

47

49

51

55

59

60

61

62

63

66

67template

69 if (!Val)

71 return std::move(*Val);

72}

73

75 std::optional DataLayout;

76

77

78

79

80

81

82

83 std::optional ValueType;

84

85 std::optional MDType;

86

90};

91

92 struct BitcodeFileContents;

93

94

101

102

103 class BitcodeModule {

104

107

108

110

111

113

114

116

119 : Buffer(Buffer), ModuleIdentifier(ModuleIdentifier),

120 IdentificationBit(IdentificationBit), ModuleBit(ModuleBit) {}

121

122

125

127 getModuleImpl(LLVMContext &Context, bool MaterializeAll,

128 bool ShouldLazyLoadMetadata, bool IsImporting,

130

131 public:

133 return StringRef((const char *)Buffer.begin(), Buffer.size());

134 }

135

137

139

140

141

142

143

147

148

149 LLVM_ABI Expected<std::unique_ptr>

150 parseModule(LLVMContext &Context, ParserCallbacks Callbacks = {});

151

152

153

155

156

158

159

160

162 readSummary(ModuleSummaryIndex &CombinedIndex, StringRef ModulePath,

164 };

165

167 std::vector Mods;

169 };

170

171

172

173

174

175

178

179

182

183

184

185

186

189 bool ShouldLazyLoadMetadata = false,

190 bool IsImporting = false,

192

193

194

195

196

198 std::unique_ptr &&Buffer, LLVMContext &Context,

199 bool ShouldLazyLoadMetadata = false, bool IsImporting = false,

200 ParserCallbacks Callbacks = {});

201

202

203

204

206

207

208

211

212

213

214

217

218

222

223

225

226

229

230

233

234

235

236

237

240 bool IgnoreEmptyThinLTOIndexFile = false);

241

242

243

245 const unsigned char *BufEnd) {

246

247

248 return BufPtr != BufEnd &&

249 BufPtr[0] == 0xDE &&

250 BufPtr[1] == 0xC0 &&

251 BufPtr[2] == 0x17 &&

252 BufPtr[3] == 0x0B;

253 }

254

255

256

258 const unsigned char *BufEnd) {

259

260

261 return BufPtr != BufEnd &&

262 BufPtr[0] == 'B' &&

263 BufPtr[1] == 'C' &&

264 BufPtr[2] == 0xc0 &&

265 BufPtr[3] == 0xde;

266 }

267

268

269

270 inline bool isBitcode(const unsigned char *BufPtr,

271 const unsigned char *BufEnd) {

274 }

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

293 const unsigned char *&BufEnd,

294 bool VerifyBufferSize) {

295

296 if (unsigned(BufEnd - BufPtr) < BWH_SizeField + 4)

297 return true;

298

302

303

304 if (VerifyBufferSize && BitcodeOffsetEnd > uint64_t(BufEnd-BufPtr))

305 return true;

307 BufEnd = BufPtr+Size;

308 return false;

309 }

310

312

318

319}

320

321namespace std {

322

323template <> struct is_error_code_enum<llvm::BitcodeError> : std::true_type {};

324

325}

326

327#endif

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

Provides ErrorOr smart pointer.

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

LLVM_ABI friend Expected< BitcodeFileContents > getBitcodeFileContents(MemoryBufferRef Buffer)

Returns the contents of a bitcode file.

StringRef getModuleIdentifier() const

Definition BitcodeReader.h:138

LLVM_ABI Expected< std::unique_ptr< ModuleSummaryIndex > > getSummary()

Parse the specified bitcode buffer, returning the module summary index.

LLVM_ABI Expected< BitcodeLTOInfo > getLTOInfo()

Returns information about the module to be used for LTO: whether to compile with ThinLTO,...

StringRef getBuffer() const

Definition BitcodeReader.h:132

LLVM_ABI 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.

LLVM_ABI Expected< std::unique_ptr< Module > > parseModule(LLVMContext &Context, ParserCallbacks Callbacks={})

Read the entire bitcode module and return it.

StringRef getStrtab() const

Definition BitcodeReader.h:136

LLVM_ABI 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.

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.

This interface provides simple read-only access to a block of memory, and provides simple methods for...

Class to hold module path string table and global value map, and encapsulate methods for operating on...

A Module instance is used to store all the information related to an LLVM module.

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.

LLVM_ABI const std::error_category & BitcodeErrorCategory()

LLVM_ABI 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)

Definition BitcodeReader.h:315

std::function< Type *(unsigned)> GetTypeByIDTy

Definition BitcodeReader.h:48

LLVM_ABI 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

Definition BitcodeReader.h:50

LLVM_ABI Expected< std::string > getBitcodeTargetTriple(MemoryBufferRef Buffer)

Read the header of the specified bitcode buffer and extract just the triple information.

LLVM_ABI Expected< BitcodeFileContents > getBitcodeFileContents(MemoryBufferRef Buffer)

Returns the contents of a bitcode file.

ErrorOr< T > expectedToErrorOrAndEmitErrors(LLVMContext &Ctx, Expected< T > Val)

Definition BitcodeReader.h:68

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 ...

Definition BitcodeReader.h:257

LLVM_ABI Expected< std::unique_ptr< ModuleSummaryIndex > > getModuleSummaryIndex(MemoryBufferRef Buffer)

Parse the specified bitcode buffer, returning the module summary index.

LLVM_ABI Expected< std::string > getBitcodeProducerString(MemoryBufferRef Buffer)

Read the header of the specified bitcode buffer and extract just the producer string information.

LLVM_ABI 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

Definition BitcodeReader.h:58

LLVM_ABI Expected< std::vector< BitcodeModule > > getBitcodeModuleList(MemoryBufferRef Buffer)

Returns a list of modules in the specified bitcode buffer.

LLVM_ABI 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...

Definition BitcodeReader.h:292

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.

Definition BitcodeReader.h:244

LLVM_ABI APInt readWideAPInt(ArrayRef< uint64_t > Vals, unsigned TypeBits)

std::function< void(Value *, unsigned, GetTypeByIDTy, GetContainedTypeIDTy)> ValueTypeCallbackTy

Definition BitcodeReader.h:54

std::function< std::optional< std::string >(StringRef, StringRef)> DataLayoutCallbackFuncTy

Definition BitcodeReader.h:46

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,...

Definition BitcodeReader.h:270

LLVM_ABI Error readModuleSummaryIndex(MemoryBufferRef Buffer, ModuleSummaryIndex &CombinedIndex)

Parse the specified bitcode buffer and merge the index into CombinedIndex.

LLVM_ABI 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,...

LLVM_ABI 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.

LLVM_ABI std::error_code errorToErrorCodeAndEmitErrors(LLVMContext &Ctx, Error Err)

BitcodeError

Definition BitcodeReader.h:314

@ CorruptedBitcode

Definition BitcodeReader.h:314

Implement std::hash so that hash_code can be used in STL containers.

Definition BitcodeReader.h:166

StringRef StrtabForSymtab

Definition BitcodeReader.h:168

StringRef Symtab

Definition BitcodeReader.h:168

std::vector< BitcodeModule > Mods

Definition BitcodeReader.h:167

Basic information extracted from a bitcode module to be used for LTO.

Definition BitcodeReader.h:95

bool UnifiedLTO

Definition BitcodeReader.h:99

bool IsThinLTO

Definition BitcodeReader.h:96

bool EnableSplitLTOUnit

Definition BitcodeReader.h:98

bool HasSummary

Definition BitcodeReader.h:97

Definition BitcodeReader.h:74

std::optional< ValueTypeCallbackTy > ValueType

The ValueType callback is called for every function definition or declaration and allows accessing th...

Definition BitcodeReader.h:83

std::optional< DataLayoutCallbackFuncTy > DataLayout

Definition BitcodeReader.h:75

ParserCallbacks(DataLayoutCallbackFuncTy DataLayout)

Definition BitcodeReader.h:88

std::optional< MDTypeCallbackTy > MDType

The MDType callback is called for every value in metadata.

Definition BitcodeReader.h:85

ParserCallbacks()=default