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