LLVM  14.0.0git
BitCodes.h
Go to the documentation of this file.
1 //===- BitCodes.h - Enum values for the bitstream format --------*- 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 bitstream enum values.
10 //
11 // The enum values defined in this file should be considered permanent. If
12 // new features are added, they should have values added at the end of the
13 // respective lists.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_BITSTREAM_BITCODES_H
18 #define LLVM_BITSTREAM_BITCODES_H
19 
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringExtras.h"
22 #include "llvm/Support/DataTypes.h"
24 #include <cassert>
25 
26 namespace llvm {
27 /// Offsets of the 32-bit fields of bitstream wrapper header.
28 enum BitstreamWrapperHeader : unsigned {
29  BWH_MagicField = 0 * 4,
31  BWH_OffsetField = 2 * 4,
32  BWH_SizeField = 3 * 4,
35 };
36 
37 namespace bitc {
39  BlockIDWidth = 8, // We use VBR-8 for block IDs.
40  CodeLenWidth = 4, // Codelen are VBR-4.
41  BlockSizeWidth = 32 // BlockSize up to 2^32 32-bit words = 16GB per block.
42  };
43 
44  // The standard abbrev namespace always has a way to exit a block, enter a
45  // nested block, define abbrevs, and define an unabbreviated record.
47  END_BLOCK = 0, // Must be zero to guarantee termination for broken bitcode.
49 
50  /// DEFINE_ABBREV - Defines an abbrev for the current block. It consists
51  /// of a vbr5 for # operand infos. Each operand info is emitted with a
52  /// single bit to indicate if it is a literal encoding. If so, the value is
53  /// emitted with a vbr8. If not, the encoding is emitted as 3 bits followed
54  /// by the info value as a vbr5 if needed.
56 
57  // UNABBREV_RECORDs are emitted with a vbr6 for the record code, followed by
58  // a vbr6 for the # operands, followed by vbr6's for each operand.
60 
61  // This is not a code, this is a marker for the first abbrev assignment.
63  };
64 
65  /// StandardBlockIDs - All bitcode files can optionally include a BLOCKINFO
66  /// block, which contains metadata about other blocks in the file.
68  /// BLOCKINFO_BLOCK is used to define metadata about blocks, for example,
69  /// standard abbrevs that should be available to all blocks of a specified
70  /// ID.
72 
73  // Block IDs 1-7 are reserved for future expansion.
75  };
76 
77  /// BlockInfoCodes - The blockinfo block contains metadata about user-defined
78  /// blocks.
80  // DEFINE_ABBREV has magic semantics here, applying to the current SETBID'd
81  // block, instead of the BlockInfo block.
82 
83  BLOCKINFO_CODE_SETBID = 1, // SETBID: [blockid#]
84  BLOCKINFO_CODE_BLOCKNAME = 2, // BLOCKNAME: [name]
85  BLOCKINFO_CODE_SETRECORDNAME = 3 // BLOCKINFO_CODE_SETRECORDNAME:
86  // [id, name]
87  };
88 
89 } // End bitc namespace
90 
91 /// BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
92 /// This is actually a union of two different things:
93 /// 1. It could be a literal integer value ("the operand is always 17").
94 /// 2. It could be an encoding specification ("this operand encoded like so").
95 ///
97  uint64_t Val; // A literal value or data for an encoding.
98  bool IsLiteral : 1; // Indicate whether this is a literal value or not.
99  unsigned Enc : 3; // The encoding to use.
100 public:
101  enum Encoding {
102  Fixed = 1, // A fixed width field, Val specifies number of bits.
103  VBR = 2, // A VBR field where Val specifies the width of each chunk.
104  Array = 3, // A sequence of fields, next field species elt encoding.
105  Char6 = 4, // A 6-bit fixed field which maps to [a-zA-Z0-9._].
106  Blob = 5 // 32-bit aligned array of 8-bit characters.
107  };
108 
109  explicit BitCodeAbbrevOp(uint64_t V) : Val(V), IsLiteral(true) {}
111  : Val(Data), IsLiteral(false), Enc(E) {}
112 
113  bool isLiteral() const { return IsLiteral; }
114  bool isEncoding() const { return !IsLiteral; }
115 
116  // Accessors for literals.
117  uint64_t getLiteralValue() const { assert(isLiteral()); return Val; }
118 
119  // Accessors for encoding info.
120  Encoding getEncoding() const { assert(isEncoding()); return (Encoding)Enc; }
123  return Val;
124  }
125 
126  bool hasEncodingData() const { return hasEncodingData(getEncoding()); }
127  static bool hasEncodingData(Encoding E) {
128  switch (E) {
129  case Fixed:
130  case VBR:
131  return true;
132  case Array:
133  case Char6:
134  case Blob:
135  return false;
136  }
137  report_fatal_error("Invalid encoding");
138  }
139 
140  /// isChar6 - Return true if this character is legal in the Char6 encoding.
141  static bool isChar6(char C) { return isAlnum(C) || C == '.' || C == '_'; }
142  static unsigned EncodeChar6(char C) {
143  if (C >= 'a' && C <= 'z') return C-'a';
144  if (C >= 'A' && C <= 'Z') return C-'A'+26;
145  if (C >= '0' && C <= '9') return C-'0'+26+26;
146  if (C == '.') return 62;
147  if (C == '_') return 63;
148  llvm_unreachable("Not a value Char6 character!");
149  }
150 
151  static char DecodeChar6(unsigned V) {
152  assert((V & ~63) == 0 && "Not a Char6 encoded character!");
153  return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._"
154  [V];
155  }
156 
157 };
158 
159 /// BitCodeAbbrev - This class represents an abbreviation record. An
160 /// abbreviation allows a complex record that has redundancy to be stored in a
161 /// specialized format instead of the fully-general, fully-vbr, format.
164 
165 public:
166  BitCodeAbbrev() = default;
167 
168  explicit BitCodeAbbrev(std::initializer_list<BitCodeAbbrevOp> OperandList)
169  : OperandList(OperandList) {}
170 
171  unsigned getNumOperandInfos() const {
172  return static_cast<unsigned>(OperandList.size());
173  }
174  const BitCodeAbbrevOp &getOperandInfo(unsigned N) const {
175  return OperandList[N];
176  }
177 
178  void Add(const BitCodeAbbrevOp &OpInfo) {
179  OperandList.push_back(OpInfo);
180  }
181 };
182 } // End llvm namespace
183 
184 #endif
llvm::BitCodeAbbrev::getNumOperandInfos
unsigned getNumOperandInfos() const
Definition: BitCodes.h:171
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::BitCodeAbbrev::Add
void Add(const BitCodeAbbrevOp &OpInfo)
Definition: BitCodes.h:178
llvm::BitCodeAbbrevOp::isChar6
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
Definition: BitCodes.h:141
llvm::BitCodeAbbrevOp::Fixed
@ Fixed
Definition: BitCodes.h:102
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::BitCodeAbbrevOp::hasEncodingData
static bool hasEncodingData(Encoding E)
Definition: BitCodes.h:127
ErrorHandling.h
llvm::bitc::DEFINE_ABBREV
@ DEFINE_ABBREV
DEFINE_ABBREV - Defines an abbrev for the current block.
Definition: BitCodes.h:55
llvm::bitc::BLOCKINFO_BLOCK_ID
@ BLOCKINFO_BLOCK_ID
BLOCKINFO_BLOCK is used to define metadata about blocks, for example, standard abbrevs that should be...
Definition: BitCodes.h:71
llvm::bitc::StandardBlockIDs
StandardBlockIDs
StandardBlockIDs - All bitcode files can optionally include a BLOCKINFO block, which contains metadat...
Definition: BitCodes.h:67
llvm::bitc::BlockIDWidth
@ BlockIDWidth
Definition: BitCodes.h:39
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::BitCodeAbbrevOp::BitCodeAbbrevOp
BitCodeAbbrevOp(Encoding E, uint64_t Data=0)
Definition: BitCodes.h:110
llvm::bitc::ENTER_SUBBLOCK
@ ENTER_SUBBLOCK
Definition: BitCodes.h:48
llvm::BitCodeAbbrevOp::hasEncodingData
bool hasEncodingData() const
Definition: BitCodes.h:126
llvm::BitCodeAbbrevOp::Char6
@ Char6
Definition: BitCodes.h:105
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::BWH_CPUTypeField
@ BWH_CPUTypeField
Definition: BitCodes.h:33
llvm::BitCodeAbbrev::BitCodeAbbrev
BitCodeAbbrev(std::initializer_list< BitCodeAbbrevOp > OperandList)
Definition: BitCodes.h:168
llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME
@ BLOCKINFO_CODE_SETRECORDNAME
Definition: BitCodes.h:85
llvm::bitc::END_BLOCK
@ END_BLOCK
Definition: BitCodes.h:47
llvm::BWH_OffsetField
@ BWH_OffsetField
Definition: BitCodes.h:31
false
Definition: StackSlotColoring.cpp:142
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
llvm::BWH_MagicField
@ BWH_MagicField
Definition: BitCodes.h:29
llvm::bitc::FIRST_APPLICATION_BLOCKID
@ FIRST_APPLICATION_BLOCKID
Definition: BitCodes.h:74
llvm::BitCodeAbbrevOp::Blob
@ Blob
Definition: BitCodes.h:106
llvm::BWH_HeaderSize
@ BWH_HeaderSize
Definition: BitCodes.h:34
llvm::BitCodeAbbrevOp::getEncoding
Encoding getEncoding() const
Definition: BitCodes.h:120
llvm::BitCodeAbbrevOp::Encoding
Encoding
Definition: BitCodes.h:101
llvm::BWH_SizeField
@ BWH_SizeField
Definition: BitCodes.h:32
llvm::bitc::StandardWidths
StandardWidths
Definition: BitCodes.h:38
llvm::BitCodeAbbrevOp::isEncoding
bool isEncoding() const
Definition: BitCodes.h:114
llvm::BitCodeAbbrevOp::BitCodeAbbrevOp
BitCodeAbbrevOp(uint64_t V)
Definition: BitCodes.h:109
uint64_t
llvm::bitc::BlockSizeWidth
@ BlockSizeWidth
Definition: BitCodes.h:41
StringExtras.h
llvm::bitc::BlockInfoCodes
BlockInfoCodes
BlockInfoCodes - The blockinfo block contains metadata about user-defined blocks.
Definition: BitCodes.h:79
llvm::BitCodeAbbrevOp::VBR
@ VBR
Definition: BitCodes.h:103
llvm::BitCodeAbbrevOp::Array
@ Array
Definition: BitCodes.h:104
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::BitCodeAbbrevOp::getEncodingData
uint64_t getEncodingData() const
Definition: BitCodes.h:121
llvm::bitc::BLOCKINFO_CODE_SETBID
@ BLOCKINFO_CODE_SETBID
Definition: BitCodes.h:83
llvm::bitc::BLOCKINFO_CODE_BLOCKNAME
@ BLOCKINFO_CODE_BLOCKNAME
Definition: BitCodes.h:84
llvm::BitCodeAbbrev::getOperandInfo
const BitCodeAbbrevOp & getOperandInfo(unsigned N) const
Definition: BitCodes.h:174
llvm::BitCodeAbbrev::BitCodeAbbrev
BitCodeAbbrev()=default
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::bitc::FixedAbbrevIDs
FixedAbbrevIDs
Definition: BitCodes.h:46
llvm::bitc::UNABBREV_RECORD
@ UNABBREV_RECORD
Definition: BitCodes.h:59
llvm::BitCodeAbbrevOp::getLiteralValue
uint64_t getLiteralValue() const
Definition: BitCodes.h:117
llvm::bitc::FIRST_APPLICATION_ABBREV
@ FIRST_APPLICATION_ABBREV
Definition: BitCodes.h:62
llvm::BitCodeAbbrevOp
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
Definition: BitCodes.h:96
llvm::BitCodeAbbrevOp::isLiteral
bool isLiteral() const
Definition: BitCodes.h:113
llvm::BitCodeAbbrev
BitCodeAbbrev - This class represents an abbreviation record.
Definition: BitCodes.h:162
SmallVector.h
N
#define N
DataTypes.h
llvm::bitc::CodeLenWidth
@ CodeLenWidth
Definition: BitCodes.h:40
llvm::BWH_VersionField
@ BWH_VersionField
Definition: BitCodes.h:30
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1815
llvm::BitCodeAbbrevOp::EncodeChar6
static unsigned EncodeChar6(char C)
Definition: BitCodes.h:142
llvm::BitCodeAbbrevOp::DecodeChar6
static char DecodeChar6(unsigned V)
Definition: BitCodes.h:151
llvm::BitstreamWrapperHeader
BitstreamWrapperHeader
Offsets of the 32-bit fields of bitstream wrapper header.
Definition: BitCodes.h:28