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