LLVM  16.0.0git
BitstreamReader.h
Go to the documentation of this file.
1 //===- BitstreamReader.h - Low-level bitstream reader interface -*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This header defines the BitstreamReader class. This class can be used to
10 // read an arbitrary bitstream, regardless of its contents.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_BITSTREAM_BITSTREAMREADER_H
15 #define LLVM_BITSTREAM_BITSTREAMREADER_H
16 
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/Support/Endian.h"
21 #include "llvm/Support/Error.h"
23 #include <algorithm>
24 #include <cassert>
25 #include <climits>
26 #include <cstddef>
27 #include <cstdint>
28 #include <memory>
29 #include <string>
30 #include <utility>
31 #include <vector>
32 
33 namespace llvm {
34 
35 /// This class maintains the abbreviations read from a block info block.
37 public:
38  /// This contains information emitted to BLOCKINFO_BLOCK blocks. These
39  /// describe abbreviations that all blocks of the specified ID inherit.
40  struct BlockInfo {
41  unsigned BlockID = 0;
42  std::vector<std::shared_ptr<BitCodeAbbrev>> Abbrevs;
43  std::string Name;
44  std::vector<std::pair<unsigned, std::string>> RecordNames;
45  };
46 
47 private:
48  std::vector<BlockInfo> BlockInfoRecords;
49 
50 public:
51  /// If there is block info for the specified ID, return it, otherwise return
52  /// null.
53  const BlockInfo *getBlockInfo(unsigned BlockID) const {
54  // Common case, the most recent entry matches BlockID.
55  if (!BlockInfoRecords.empty() && BlockInfoRecords.back().BlockID == BlockID)
56  return &BlockInfoRecords.back();
57 
58  for (const BlockInfo &BI : BlockInfoRecords)
59  if (BI.BlockID == BlockID)
60  return &BI;
61  return nullptr;
62  }
63 
64  BlockInfo &getOrCreateBlockInfo(unsigned BlockID) {
65  if (const BlockInfo *BI = getBlockInfo(BlockID))
66  return *const_cast<BlockInfo*>(BI);
67 
68  // Otherwise, add a new record.
69  BlockInfoRecords.emplace_back();
70  BlockInfoRecords.back().BlockID = BlockID;
71  return BlockInfoRecords.back();
72  }
73 };
74 
75 /// This represents a position within a bitstream. There may be multiple
76 /// independent cursors reading within one bitstream, each maintaining their
77 /// own local state.
79  ArrayRef<uint8_t> BitcodeBytes;
80  size_t NextChar = 0;
81 
82 public:
83  /// This is the current data we have pulled from the stream but have not
84  /// returned to the client. This is specifically and intentionally defined to
85  /// follow the word size of the host machine for efficiency. We use word_t in
86  /// places that are aware of this to make it perfectly explicit what is going
87  /// on.
88  using word_t = size_t;
89 
90 private:
91  word_t CurWord = 0;
92 
93  /// This is the number of bits in CurWord that are valid. This is always from
94  /// [0...bits_of(size_t)-1] inclusive.
95  unsigned BitsInCurWord = 0;
96 
97 public:
98  SimpleBitstreamCursor() = default;
100  : BitcodeBytes(BitcodeBytes) {}
101  explicit SimpleBitstreamCursor(StringRef BitcodeBytes)
102  : BitcodeBytes(arrayRefFromStringRef(BitcodeBytes)) {}
103  explicit SimpleBitstreamCursor(MemoryBufferRef BitcodeBytes)
104  : SimpleBitstreamCursor(BitcodeBytes.getBuffer()) {}
105 
106  bool canSkipToPos(size_t pos) const {
107  // pos can be skipped to if it is a valid address or one byte past the end.
108  return pos <= BitcodeBytes.size();
109  }
110 
111  bool AtEndOfStream() {
112  return BitsInCurWord == 0 && BitcodeBytes.size() <= NextChar;
113  }
114 
115  /// Return the bit # of the bit we are reading.
117  return NextChar*CHAR_BIT - BitsInCurWord;
118  }
119 
120  // Return the byte # of the current bit.
121  uint64_t getCurrentByteNo() const { return GetCurrentBitNo() / 8; }
122 
123  ArrayRef<uint8_t> getBitcodeBytes() const { return BitcodeBytes; }
124 
125  /// Reset the stream to the specified bit number.
127  size_t ByteNo = size_t(BitNo/8) & ~(sizeof(word_t)-1);
128  unsigned WordBitNo = unsigned(BitNo & (sizeof(word_t)*8-1));
129  assert(canSkipToPos(ByteNo) && "Invalid location");
130 
131  // Move the cursor to the right word.
132  NextChar = ByteNo;
133  BitsInCurWord = 0;
134 
135  // Skip over any bits that are already consumed.
136  if (WordBitNo) {
137  if (Expected<word_t> Res = Read(WordBitNo))
138  return Error::success();
139  else
140  return Res.takeError();
141  }
142 
143  return Error::success();
144  }
145 
146  /// Get a pointer into the bitstream at the specified byte offset.
147  const uint8_t *getPointerToByte(uint64_t ByteNo, uint64_t NumBytes) {
148  return BitcodeBytes.data() + ByteNo;
149  }
150 
151  /// Get a pointer into the bitstream at the specified bit offset.
152  ///
153  /// The bit offset must be on a byte boundary.
154  const uint8_t *getPointerToBit(uint64_t BitNo, uint64_t NumBytes) {
155  assert(!(BitNo % 8) && "Expected bit on byte boundary");
156  return getPointerToByte(BitNo / 8, NumBytes);
157  }
158 
160  if (NextChar >= BitcodeBytes.size())
161  return createStringError(std::errc::io_error,
162  "Unexpected end of file reading %u of %u bytes",
163  NextChar, BitcodeBytes.size());
164 
165  // Read the next word from the stream.
166  const uint8_t *NextCharPtr = BitcodeBytes.data() + NextChar;
167  unsigned BytesRead;
168  if (BitcodeBytes.size() >= NextChar + sizeof(word_t)) {
169  BytesRead = sizeof(word_t);
170  CurWord =
171  support::endian::read<word_t, support::little, support::unaligned>(
172  NextCharPtr);
173  } else {
174  // Short read.
175  BytesRead = BitcodeBytes.size() - NextChar;
176  CurWord = 0;
177  for (unsigned B = 0; B != BytesRead; ++B)
178  CurWord |= uint64_t(NextCharPtr[B]) << (B * 8);
179  }
180  NextChar += BytesRead;
181  BitsInCurWord = BytesRead * 8;
182  return Error::success();
183  }
184 
185  Expected<word_t> Read(unsigned NumBits) {
186  static const unsigned BitsInWord = sizeof(word_t) * 8;
187 
188  assert(NumBits && NumBits <= BitsInWord &&
189  "Cannot return zero or more than BitsInWord bits!");
190 
191  static const unsigned Mask = sizeof(word_t) > 4 ? 0x3f : 0x1f;
192 
193  // If the field is fully contained by CurWord, return it quickly.
194  if (BitsInCurWord >= NumBits) {
195  word_t R = CurWord & (~word_t(0) >> (BitsInWord - NumBits));
196 
197  // Use a mask to avoid undefined behavior.
198  CurWord >>= (NumBits & Mask);
199 
200  BitsInCurWord -= NumBits;
201  return R;
202  }
203 
204  word_t R = BitsInCurWord ? CurWord : 0;
205  unsigned BitsLeft = NumBits - BitsInCurWord;
206 
207  if (Error fillResult = fillCurWord())
208  return std::move(fillResult);
209 
210  // If we run out of data, abort.
211  if (BitsLeft > BitsInCurWord)
212  return createStringError(std::errc::io_error,
213  "Unexpected end of file reading %u of %u bits",
214  BitsInCurWord, BitsLeft);
215 
216  word_t R2 = CurWord & (~word_t(0) >> (BitsInWord - BitsLeft));
217 
218  // Use a mask to avoid undefined behavior.
219  CurWord >>= (BitsLeft & Mask);
220 
221  BitsInCurWord -= BitsLeft;
222 
223  R |= R2 << (NumBits - BitsLeft);
224 
225  return R;
226  }
227 
228  Expected<uint32_t> ReadVBR(const unsigned NumBits) {
229  Expected<unsigned> MaybeRead = Read(NumBits);
230  if (!MaybeRead)
231  return MaybeRead;
232  uint32_t Piece = MaybeRead.get();
233 
234  assert(NumBits <= 32 && NumBits >= 1 && "Invalid NumBits value");
235  const uint32_t MaskBitOrder = (NumBits - 1);
236  const uint32_t Mask = 1UL << MaskBitOrder;
237 
238  if ((Piece & Mask) == 0)
239  return Piece;
240 
241  uint32_t Result = 0;
242  unsigned NextBit = 0;
243  while (true) {
244  Result |= (Piece & (Mask - 1)) << NextBit;
245 
246  if ((Piece & Mask) == 0)
247  return Result;
248 
249  NextBit += NumBits-1;
250  if (NextBit >= 32)
251  return createStringError(std::errc::illegal_byte_sequence,
252  "Unterminated VBR");
253 
254  MaybeRead = Read(NumBits);
255  if (!MaybeRead)
256  return MaybeRead;
257  Piece = MaybeRead.get();
258  }
259  }
260 
261  // Read a VBR that may have a value up to 64-bits in size. The chunk size of
262  // the VBR must still be <= 32 bits though.
263  Expected<uint64_t> ReadVBR64(const unsigned NumBits) {
264  Expected<uint64_t> MaybeRead = Read(NumBits);
265  if (!MaybeRead)
266  return MaybeRead;
267  uint32_t Piece = MaybeRead.get();
268  assert(NumBits <= 32 && NumBits >= 1 && "Invalid NumBits value");
269  const uint32_t MaskBitOrder = (NumBits - 1);
270  const uint32_t Mask = 1UL << MaskBitOrder;
271 
272  if ((Piece & Mask) == 0)
273  return uint64_t(Piece);
274 
275  uint64_t Result = 0;
276  unsigned NextBit = 0;
277  while (true) {
278  Result |= uint64_t(Piece & (Mask - 1)) << NextBit;
279 
280  if ((Piece & Mask) == 0)
281  return Result;
282 
283  NextBit += NumBits-1;
284  if (NextBit >= 64)
285  return createStringError(std::errc::illegal_byte_sequence,
286  "Unterminated VBR");
287 
288  MaybeRead = Read(NumBits);
289  if (!MaybeRead)
290  return MaybeRead;
291  Piece = MaybeRead.get();
292  }
293  }
294 
296  // If word_t is 64-bits and if we've read less than 32 bits, just dump
297  // the bits we have up to the next 32-bit boundary.
298  if (sizeof(word_t) > 4 &&
299  BitsInCurWord >= 32) {
300  CurWord >>= BitsInCurWord-32;
301  BitsInCurWord = 32;
302  return;
303  }
304 
305  BitsInCurWord = 0;
306  }
307 
308  /// Return the size of the stream in bytes.
309  size_t SizeInBytes() const { return BitcodeBytes.size(); }
310 
311  /// Skip to the end of the file.
312  void skipToEnd() { NextChar = BitcodeBytes.size(); }
313 
314  /// Check whether a reservation of Size elements is plausible.
315  bool isSizePlausible(size_t Size) const {
316  // Don't allow reserving more elements than the number of bits, assuming
317  // at least one bit is needed to encode an element.
318  return Size < BitcodeBytes.size() * 8;
319  }
320 };
321 
322 /// When advancing through a bitstream cursor, each advance can discover a few
323 /// different kinds of entries:
325  enum {
326  Error, // Malformed bitcode was found.
327  EndBlock, // We've reached the end of the current block, (or the end of the
328  // file, which is treated like a series of EndBlock records.
329  SubBlock, // This is the start of a new subblock of a specific ID.
330  Record // This is a record with a specific AbbrevID.
331  } Kind;
332 
333  unsigned ID;
334 
336  BitstreamEntry E; E.Kind = Error; return E;
337  }
338 
340  BitstreamEntry E; E.Kind = EndBlock; return E;
341  }
342 
343  static BitstreamEntry getSubBlock(unsigned ID) {
344  BitstreamEntry E; E.Kind = SubBlock; E.ID = ID; return E;
345  }
346 
347  static BitstreamEntry getRecord(unsigned AbbrevID) {
348  BitstreamEntry E; E.Kind = Record; E.ID = AbbrevID; return E;
349  }
350 };
351 
352 /// This represents a position within a bitcode file, implemented on top of a
353 /// SimpleBitstreamCursor.
354 ///
355 /// Unlike iterators, BitstreamCursors are heavy-weight objects that should not
356 /// be passed by value.
358  // This is the declared size of code values used for the current block, in
359  // bits.
360  unsigned CurCodeSize = 2;
361 
362  /// Abbrevs installed at in this block.
363  std::vector<std::shared_ptr<BitCodeAbbrev>> CurAbbrevs;
364 
365  struct Block {
366  unsigned PrevCodeSize;
367  std::vector<std::shared_ptr<BitCodeAbbrev>> PrevAbbrevs;
368 
369  explicit Block(unsigned PCS) : PrevCodeSize(PCS) {}
370  };
371 
372  /// This tracks the codesize of parent blocks.
373  SmallVector<Block, 8> BlockScope;
374 
375  BitstreamBlockInfo *BlockInfo = nullptr;
376 
377 public:
378  static const size_t MaxChunkSize = 32;
379 
380  BitstreamCursor() = default;
381  explicit BitstreamCursor(ArrayRef<uint8_t> BitcodeBytes)
382  : SimpleBitstreamCursor(BitcodeBytes) {}
383  explicit BitstreamCursor(StringRef BitcodeBytes)
384  : SimpleBitstreamCursor(BitcodeBytes) {}
385  explicit BitstreamCursor(MemoryBufferRef BitcodeBytes)
386  : SimpleBitstreamCursor(BitcodeBytes) {}
387 
401 
402  /// Return the number of bits used to encode an abbrev #.
403  unsigned getAbbrevIDWidth() const { return CurCodeSize; }
404 
405  /// Flags that modify the behavior of advance().
406  enum {
407  /// If this flag is used, the advance() method does not automatically pop
408  /// the block scope when the end of a block is reached.
410 
411  /// If this flag is used, abbrev entries are returned just like normal
412  /// records.
414  };
415 
416  /// Advance the current bitstream, returning the next entry in the stream.
417  Expected<BitstreamEntry> advance(unsigned Flags = 0) {
418  while (true) {
419  if (AtEndOfStream())
420  return BitstreamEntry::getError();
421 
422  Expected<unsigned> MaybeCode = ReadCode();
423  if (!MaybeCode)
424  return MaybeCode.takeError();
425  unsigned Code = MaybeCode.get();
426 
427  if (Code == bitc::END_BLOCK) {
428  // Pop the end of the block unless Flags tells us not to.
429  if (!(Flags & AF_DontPopBlockAtEnd) && ReadBlockEnd())
430  return BitstreamEntry::getError();
432  }
433 
434  if (Code == bitc::ENTER_SUBBLOCK) {
435  if (Expected<unsigned> MaybeSubBlock = ReadSubBlockID())
436  return BitstreamEntry::getSubBlock(MaybeSubBlock.get());
437  else
438  return MaybeSubBlock.takeError();
439  }
440 
441  if (Code == bitc::DEFINE_ABBREV &&
442  !(Flags & AF_DontAutoprocessAbbrevs)) {
443  // We read and accumulate abbrev's, the client can't do anything with
444  // them anyway.
445  if (Error Err = ReadAbbrevRecord())
446  return std::move(Err);
447  continue;
448  }
449 
450  return BitstreamEntry::getRecord(Code);
451  }
452  }
453 
454  /// This is a convenience function for clients that don't expect any
455  /// subblocks. This just skips over them automatically.
457  while (true) {
458  // If we found a normal entry, return it.
459  Expected<BitstreamEntry> MaybeEntry = advance(Flags);
460  if (!MaybeEntry)
461  return MaybeEntry;
462  BitstreamEntry Entry = MaybeEntry.get();
463 
464  if (Entry.Kind != BitstreamEntry::SubBlock)
465  return Entry;
466 
467  // If we found a sub-block, just skip over it and check the next entry.
468  if (Error Err = SkipBlock())
469  return std::move(Err);
470  }
471  }
472 
473  Expected<unsigned> ReadCode() { return Read(CurCodeSize); }
474 
475  // Block header:
476  // [ENTER_SUBBLOCK, blockid, newcodelen, <align4bytes>, blocklen]
477 
478  /// Having read the ENTER_SUBBLOCK code, read the BlockID for the block.
480 
481  /// Having read the ENTER_SUBBLOCK abbrevid and a BlockID, skip over the body
482  /// of this block.
484  // Read and ignore the codelen value.
486  ; // Since we are skipping this block, we don't care what code widths are
487  // used inside of it.
488  else
489  return Res.takeError();
490 
493  if (!MaybeNum)
494  return MaybeNum.takeError();
495  size_t NumFourBytes = MaybeNum.get();
496 
497  // Check that the block wasn't partially defined, and that the offset isn't
498  // bogus.
499  size_t SkipTo = GetCurrentBitNo() + NumFourBytes * 4 * 8;
500  if (AtEndOfStream())
501  return createStringError(std::errc::illegal_byte_sequence,
502  "can't skip block: already at end of stream");
503  if (!canSkipToPos(SkipTo / 8))
504  return createStringError(std::errc::illegal_byte_sequence,
505  "can't skip to bit %zu from %" PRIu64, SkipTo,
506  GetCurrentBitNo());
507 
508  if (Error Res = JumpToBit(SkipTo))
509  return Res;
510 
511  return Error::success();
512  }
513 
514  /// Having read the ENTER_SUBBLOCK abbrevid, and enter the block.
515  Error EnterSubBlock(unsigned BlockID, unsigned *NumWordsP = nullptr);
516 
517  bool ReadBlockEnd() {
518  if (BlockScope.empty()) return true;
519 
520  // Block tail:
521  // [END_BLOCK, <align4bytes>]
523 
524  popBlockScope();
525  return false;
526  }
527 
528 private:
529  void popBlockScope() {
530  CurCodeSize = BlockScope.back().PrevCodeSize;
531 
532  CurAbbrevs = std::move(BlockScope.back().PrevAbbrevs);
533  BlockScope.pop_back();
534  }
535 
536  //===--------------------------------------------------------------------===//
537  // Record Processing
538  //===--------------------------------------------------------------------===//
539 
540 public:
541  /// Return the abbreviation for the specified AbbrevId.
543  unsigned AbbrevNo = AbbrevID - bitc::FIRST_APPLICATION_ABBREV;
544  if (AbbrevNo >= CurAbbrevs.size())
545  return createStringError(
546  std::errc::illegal_byte_sequence, "Invalid abbrev number");
547  return CurAbbrevs[AbbrevNo].get();
548  }
549 
550  /// Read the current record and discard it, returning the code for the record.
551  Expected<unsigned> skipRecord(unsigned AbbrevID);
552 
553  Expected<unsigned> readRecord(unsigned AbbrevID,
555  StringRef *Blob = nullptr);
556 
557  //===--------------------------------------------------------------------===//
558  // Abbrev Processing
559  //===--------------------------------------------------------------------===//
561 
562  /// Read and return a block info block from the bitstream. If an error was
563  /// encountered, return None.
564  ///
565  /// \param ReadBlockInfoNames Whether to read block/record name information in
566  /// the BlockInfo block. Only llvm-bcanalyzer uses this.
568  ReadBlockInfoBlock(bool ReadBlockInfoNames = false);
569 
570  /// Set the block info to be used by this BitstreamCursor to interpret
571  /// abbreviated records.
572  void setBlockInfo(BitstreamBlockInfo *BI) { BlockInfo = BI; }
573 };
574 
575 } // end llvm namespace
576 
577 #endif // LLVM_BITSTREAM_BITSTREAMREADER_H
llvm::SimpleBitstreamCursor::SimpleBitstreamCursor
SimpleBitstreamCursor(ArrayRef< uint8_t > BitcodeBytes)
Definition: BitstreamReader.h:99
llvm::BitstreamCursor::ReadSubBlockID
Expected< unsigned > ReadSubBlockID()
Having read the ENTER_SUBBLOCK code, read the BlockID for the block.
Definition: BitstreamReader.h:479
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::SimpleBitstreamCursor::ReadVBR64
Expected< uint64_t > ReadVBR64(const unsigned NumBits)
Definition: BitstreamReader.h:263
llvm::BitstreamBlockInfo
This class maintains the abbreviations read from a block info block.
Definition: BitstreamReader.h:36
llvm::SmallVector< Block, 8 >
llvm::BitstreamBlockInfo::getBlockInfo
const BlockInfo * getBlockInfo(unsigned BlockID) const
If there is block info for the specified ID, return it, otherwise return null.
Definition: BitstreamReader.h:53
llvm::bitc::DEFINE_ABBREV
@ DEFINE_ABBREV
DEFINE_ABBREV - Defines an abbrev for the current block.
Definition: BitCodeEnums.h:53
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
Error.h
llvm::SimpleBitstreamCursor::getPointerToByte
const uint8_t * getPointerToByte(uint64_t ByteNo, uint64_t NumBytes)
Get a pointer into the bitstream at the specified byte offset.
Definition: BitstreamReader.h:147
llvm::SimpleBitstreamCursor::getPointerToBit
const uint8_t * getPointerToBit(uint64_t BitNo, uint64_t NumBytes)
Get a pointer into the bitstream at the specified bit offset.
Definition: BitstreamReader.h:154
llvm::SimpleBitstreamCursor::JumpToBit
Error JumpToBit(uint64_t BitNo)
Reset the stream to the specified bit number.
Definition: BitstreamReader.h:126
MemoryBufferRef.h
llvm::BitstreamCursor
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
Definition: BitstreamReader.h:357
llvm::BitstreamBlockInfo::BlockInfo::RecordNames
std::vector< std::pair< unsigned, std::string > > RecordNames
Definition: BitstreamReader.h:44
llvm::BitstreamEntry::Error
@ Error
Definition: BitstreamReader.h:326
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::bitc::BlockIDWidth
@ BlockIDWidth
Definition: BitCodeEnums.h:37
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
size_t
llvm::ArrayRef::data
const T * data() const
Definition: ArrayRef.h:161
llvm::BitstreamCursor::ReadCode
Expected< unsigned > ReadCode()
Definition: BitstreamReader.h:473
llvm::BitstreamCursor::AF_DontAutoprocessAbbrevs
@ AF_DontAutoprocessAbbrevs
If this flag is used, abbrev entries are returned just like normal records.
Definition: BitstreamReader.h:413
llvm::bitc::ENTER_SUBBLOCK
@ ENTER_SUBBLOCK
Definition: BitCodeEnums.h:46
llvm::BitmaskEnumDetail::Mask
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:80
llvm::BitstreamCursor::AF_DontPopBlockAtEnd
@ AF_DontPopBlockAtEnd
If this flag is used, the advance() method does not automatically pop the block scope when the end of...
Definition: BitstreamReader.h:409
R2
#define R2(n)
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::BitstreamCursor::setBlockInfo
void setBlockInfo(BitstreamBlockInfo *BI)
Set the block info to be used by this BitstreamCursor to interpret abbreviated records.
Definition: BitstreamReader.h:572
llvm::SimpleBitstreamCursor::getBitcodeBytes
ArrayRef< uint8_t > getBitcodeBytes() const
Definition: BitstreamReader.h:123
llvm::bitc::END_BLOCK
@ END_BLOCK
Definition: BitCodeEnums.h:45
llvm::SimpleBitstreamCursor::AtEndOfStream
bool AtEndOfStream()
Definition: BitstreamReader.h:111
llvm::BitstreamCursor::ReadAbbrevRecord
Error ReadAbbrevRecord()
Definition: BitstreamReader.cpp:362
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::BitstreamCursor::BitstreamCursor
BitstreamCursor(ArrayRef< uint8_t > BitcodeBytes)
Definition: BitstreamReader.h:381
llvm::BitstreamEntry::getSubBlock
static BitstreamEntry getSubBlock(unsigned ID)
Definition: BitstreamReader.h:343
llvm::SimpleBitstreamCursor::fillCurWord
Error fillCurWord()
Definition: BitstreamReader.h:159
llvm::SimpleBitstreamCursor::ReadVBR
Expected< uint32_t > ReadVBR(const unsigned NumBits)
Definition: BitstreamReader.h:228
llvm::BitstreamCursor::EnterSubBlock
Error EnterSubBlock(unsigned BlockID, unsigned *NumWordsP=nullptr)
Having read the ENTER_SUBBLOCK abbrevid, and enter the block.
Definition: BitstreamReader.cpp:25
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
llvm::SimpleBitstreamCursor
This represents a position within a bitstream.
Definition: BitstreamReader.h:78
uint64_t
llvm::bitc::BlockSizeWidth
@ BlockSizeWidth
Definition: BitCodeEnums.h:39
llvm::SimpleBitstreamCursor::getCurrentByteNo
uint64_t getCurrentByteNo() const
Definition: BitstreamReader.h:121
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::BitstreamBlockInfo::getOrCreateBlockInfo
BlockInfo & getOrCreateBlockInfo(unsigned BlockID)
Definition: BitstreamReader.h:64
llvm::BitstreamBlockInfo::BlockInfo
This contains information emitted to BLOCKINFO_BLOCK blocks.
Definition: BitstreamReader.h:40
ArrayRef.h
llvm::BitstreamCursor::advanceSkippingSubblocks
Expected< BitstreamEntry > advanceSkippingSubblocks(unsigned Flags=0)
This is a convenience function for clients that don't expect any subblocks.
Definition: BitstreamReader.h:456
llvm::SimpleBitstreamCursor::Read
Expected< word_t > Read(unsigned NumBits)
Definition: BitstreamReader.h:185
llvm::BitstreamCursor::ReadBlockEnd
bool ReadBlockEnd()
Definition: BitstreamReader.h:517
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::BitstreamCursor::MaxChunkSize
static const size_t MaxChunkSize
Definition: BitstreamReader.h:378
llvm::BitstreamBlockInfo::BlockInfo::Name
std::string Name
Definition: BitstreamReader.h:43
llvm::BitstreamCursor::ReadBlockInfoBlock
Expected< Optional< BitstreamBlockInfo > > ReadBlockInfoBlock(bool ReadBlockInfoNames=false)
Read and return a block info block from the bitstream.
Definition: BitstreamReader.cpp:421
llvm::Record
Definition: Record.h:1543
llvm::SimpleBitstreamCursor::SimpleBitstreamCursor
SimpleBitstreamCursor()=default
llvm::BitstreamEntry::getEndBlock
static BitstreamEntry getEndBlock()
Definition: BitstreamReader.h:339
llvm::BitstreamCursor::readRecord
Expected< unsigned > readRecord(unsigned AbbrevID, SmallVectorImpl< uint64_t > &Vals, StringRef *Blob=nullptr)
Definition: BitstreamReader.cpp:213
llvm::BitstreamBlockInfo::BlockInfo::Abbrevs
std::vector< std::shared_ptr< BitCodeAbbrev > > Abbrevs
Definition: BitstreamReader.h:42
llvm::BitstreamCursor::BitstreamCursor
BitstreamCursor()=default
llvm::BitstreamCursor::getAbbrevIDWidth
unsigned getAbbrevIDWidth() const
Return the number of bits used to encode an abbrev #.
Definition: BitstreamReader.h:403
llvm::ArrayRef< uint8_t >
BitCodes.h
llvm::BitstreamCursor::BitstreamCursor
BitstreamCursor(StringRef BitcodeBytes)
Definition: BitstreamReader.h:383
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::BitstreamCursor::BitstreamCursor
BitstreamCursor(MemoryBufferRef BitcodeBytes)
Definition: BitstreamReader.h:385
llvm::Expected::get
reference get()
Returns a reference to the stored T value.
Definition: Error.h:567
uint32_t
llvm::BitstreamCursor::advance
Expected< BitstreamEntry > advance(unsigned Flags=0)
Advance the current bitstream, returning the next entry in the stream.
Definition: BitstreamReader.h:417
llvm::SimpleBitstreamCursor::SimpleBitstreamCursor
SimpleBitstreamCursor(MemoryBufferRef BitcodeBytes)
Definition: BitstreamReader.h:103
llvm::BitstreamEntry::Kind
enum llvm::BitstreamEntry::@185 Kind
llvm::BitstreamEntry::getError
static BitstreamEntry getError()
Definition: BitstreamReader.h:335
llvm::SimpleBitstreamCursor::SizeInBytes
size_t SizeInBytes() const
Return the size of the stream in bytes.
Definition: BitstreamReader.h:309
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1239
llvm::BitstreamEntry
When advancing through a bitstream cursor, each advance can discover a few different kinds of entries...
Definition: BitstreamReader.h:324
llvm::bitc::FIRST_APPLICATION_ABBREV
@ FIRST_APPLICATION_ABBREV
Definition: BitCodeEnums.h:60
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::BitstreamEntry::getRecord
static BitstreamEntry getRecord(unsigned AbbrevID)
Definition: BitstreamReader.h:347
llvm::BitstreamEntry::ID
unsigned ID
Definition: BitstreamReader.h:333
llvm::BitstreamEntry::Record
@ Record
Definition: BitstreamReader.h:330
llvm::SimpleBitstreamCursor::isSizePlausible
bool isSizePlausible(size_t Size) const
Check whether a reservation of Size elements is plausible.
Definition: BitstreamReader.h:315
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:597
SmallVector.h
llvm::SimpleBitstreamCursor::SkipToFourByteBoundary
void SkipToFourByteBoundary()
Definition: BitstreamReader.h:295
llvm::BitstreamEntry::EndBlock
@ EndBlock
Definition: BitstreamReader.h:327
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:164
llvm::SimpleBitstreamCursor::GetCurrentBitNo
uint64_t GetCurrentBitNo() const
Return the bit # of the bit we are reading.
Definition: BitstreamReader.h:116
llvm::SmallVectorImpl< uint64_t >
llvm::SimpleBitstreamCursor::SimpleBitstreamCursor
SimpleBitstreamCursor(StringRef BitcodeBytes)
Definition: BitstreamReader.h:101
llvm::BitstreamCursor::skipRecord
Expected< unsigned > skipRecord(unsigned AbbrevID)
Read the current record and discard it, returning the code for the record.
Definition: BitstreamReader.cpp:95
llvm::bitc::CodeLenWidth
@ CodeLenWidth
Definition: BitCodeEnums.h:38
Endian.h
llvm::BitstreamEntry::SubBlock
@ SubBlock
Definition: BitstreamReader.h:329
llvm::SimpleBitstreamCursor::canSkipToPos
bool canSkipToPos(size_t pos) const
Definition: BitstreamReader.h:106
llvm::BitstreamCursor::SkipBlock
Error SkipBlock()
Having read the ENTER_SUBBLOCK abbrevid and a BlockID, skip over the body of this block.
Definition: BitstreamReader.h:483
llvm::SimpleBitstreamCursor::skipToEnd
void skipToEnd()
Skip to the end of the file.
Definition: BitstreamReader.h:312
llvm::BitstreamBlockInfo::BlockInfo::BlockID
unsigned BlockID
Definition: BitstreamReader.h:41
llvm::SimpleBitstreamCursor::word_t
size_t word_t
This is the current data we have pulled from the stream but have not returned to the client.
Definition: BitstreamReader.h:88
llvm::BitstreamCursor::getAbbrev
Expected< const BitCodeAbbrev * > getAbbrev(unsigned AbbrevID)
Return the abbreviation for the specified AbbrevId.
Definition: BitstreamReader.h:542