LLVM  3.7.0
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 
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/Support/DataTypes.h"
25 #include <cassert>
26 
27 namespace llvm {
28 namespace bitc {
30  BlockIDWidth = 8, // We use VBR-8 for block IDs.
31  CodeLenWidth = 4, // Codelen are VBR-4.
32  BlockSizeWidth = 32 // BlockSize up to 2^32 32-bit words = 16GB per block.
33  };
34 
35  // The standard abbrev namespace always has a way to exit a block, enter a
36  // nested block, define abbrevs, and define an unabbreviated record.
38  END_BLOCK = 0, // Must be zero to guarantee termination for broken bitcode.
40 
41  /// DEFINE_ABBREV - Defines an abbrev for the current block. It consists
42  /// of a vbr5 for # operand infos. Each operand info is emitted with a
43  /// single bit to indicate if it is a literal encoding. If so, the value is
44  /// emitted with a vbr8. If not, the encoding is emitted as 3 bits followed
45  /// by the info value as a vbr5 if needed.
47 
48  // UNABBREV_RECORDs are emitted with a vbr6 for the record code, followed by
49  // a vbr6 for the # operands, followed by vbr6's for each operand.
51 
52  // This is not a code, this is a marker for the first abbrev assignment.
54  };
55 
56  /// StandardBlockIDs - All bitcode files can optionally include a BLOCKINFO
57  /// block, which contains metadata about other blocks in the file.
59  /// BLOCKINFO_BLOCK is used to define metadata about blocks, for example,
60  /// standard abbrevs that should be available to all blocks of a specified
61  /// ID.
63 
64  // Block IDs 1-7 are reserved for future expansion.
66  };
67 
68  /// BlockInfoCodes - The blockinfo block contains metadata about user-defined
69  /// blocks.
71  // DEFINE_ABBREV has magic semantics here, applying to the current SETBID'd
72  // block, instead of the BlockInfo block.
73 
74  BLOCKINFO_CODE_SETBID = 1, // SETBID: [blockid#]
75  BLOCKINFO_CODE_BLOCKNAME = 2, // BLOCKNAME: [name]
76  BLOCKINFO_CODE_SETRECORDNAME = 3 // BLOCKINFO_CODE_SETRECORDNAME:
77  // [id, name]
78  };
79 
80 } // End bitc namespace
81 
82 /// BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
83 /// This is actually a union of two different things:
84 /// 1. It could be a literal integer value ("the operand is always 17").
85 /// 2. It could be an encoding specification ("this operand encoded like so").
86 ///
88  uint64_t Val; // A literal value or data for an encoding.
89  bool IsLiteral : 1; // Indicate whether this is a literal value or not.
90  unsigned Enc : 3; // The encoding to use.
91 public:
92  enum Encoding {
93  Fixed = 1, // A fixed width field, Val specifies number of bits.
94  VBR = 2, // A VBR field where Val specifies the width of each chunk.
95  Array = 3, // A sequence of fields, next field species elt encoding.
96  Char6 = 4, // A 6-bit fixed field which maps to [a-zA-Z0-9._].
97  Blob = 5 // 32-bit aligned array of 8-bit characters.
98  };
99 
100  explicit BitCodeAbbrevOp(uint64_t V) : Val(V), IsLiteral(true) {}
101  explicit BitCodeAbbrevOp(Encoding E, uint64_t Data = 0)
102  : Val(Data), IsLiteral(false), Enc(E) {}
103 
104  bool isLiteral() const { return IsLiteral; }
105  bool isEncoding() const { return !IsLiteral; }
106 
107  // Accessors for literals.
108  uint64_t getLiteralValue() const { assert(isLiteral()); return Val; }
109 
110  // Accessors for encoding info.
111  Encoding getEncoding() const { assert(isEncoding()); return (Encoding)Enc; }
112  uint64_t getEncodingData() const {
113  assert(isEncoding() && hasEncodingData());
114  return Val;
115  }
116 
117  bool hasEncodingData() const { return hasEncodingData(getEncoding()); }
118  static bool hasEncodingData(Encoding E) {
119  switch (E) {
120  case Fixed:
121  case VBR:
122  return true;
123  case Array:
124  case Char6:
125  case Blob:
126  return false;
127  }
128  report_fatal_error("Invalid encoding");
129  }
130 
131  /// isChar6 - Return true if this character is legal in the Char6 encoding.
132  static bool isChar6(char C) {
133  if (C >= 'a' && C <= 'z') return true;
134  if (C >= 'A' && C <= 'Z') return true;
135  if (C >= '0' && C <= '9') return true;
136  if (C == '.' || C == '_') return true;
137  return false;
138  }
139  static unsigned EncodeChar6(char C) {
140  if (C >= 'a' && C <= 'z') return C-'a';
141  if (C >= 'A' && C <= 'Z') return C-'A'+26;
142  if (C >= '0' && C <= '9') return C-'0'+26+26;
143  if (C == '.') return 62;
144  if (C == '_') return 63;
145  llvm_unreachable("Not a value Char6 character!");
146  }
147 
148  static char DecodeChar6(unsigned V) {
149  assert((V & ~63) == 0 && "Not a Char6 encoded character!");
150  if (V < 26) return V+'a';
151  if (V < 26+26) return V-26+'A';
152  if (V < 26+26+10) return V-26-26+'0';
153  if (V == 62) return '.';
154  if (V == 63) return '_';
155  llvm_unreachable("Not a value Char6 character!");
156  }
157 
158 };
159 
160 template <> struct isPodLike<BitCodeAbbrevOp> { static const bool value=true; };
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.
165 class BitCodeAbbrev : public RefCountedBase<BitCodeAbbrev> {
167  // Only RefCountedBase is allowed to delete.
168  ~BitCodeAbbrev() = default;
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
BLOCKINFO_BLOCK is used to define metadata about blocks, for example, standard abbrevs that should be...
Definition: BitCodes.h:62
bool isEncoding() const
Definition: BitCodes.h:105
BitCodeAbbrev - This class represents an abbreviation record.
Definition: BitCodes.h:165
const BitCodeAbbrevOp & getOperandInfo(unsigned N) const
Definition: BitCodes.h:175
void Add(const BitCodeAbbrevOp &OpInfo)
Definition: BitCodes.h:179
static const bool value
Definition: type_traits.h:46
static unsigned EncodeChar6(char C)
Definition: BitCodes.h:139
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
StandardBlockIDs
StandardBlockIDs - All bitcode files can optionally include a BLOCKINFO block, which contains metadat...
Definition: BitCodes.h:58
StandardWidths
Definition: BitCodes.h:29
#define false
Definition: ConvertUTF.c:65
uint64_t getEncodingData() const
Definition: BitCodes.h:112
RefCountedBase - A generic base class for objects that wish to have their lifetimes managed using ref...
bool isLiteral() const
Definition: BitCodes.h:104
BlockInfoCodes
BlockInfoCodes - The blockinfo block contains metadata about user-defined blocks. ...
Definition: BitCodes.h:70
bool hasEncodingData() const
Definition: BitCodes.h:117
#define true
Definition: ConvertUTF.c:66
BitCodeAbbrevOp(uint64_t V)
Definition: BitCodes.h:100
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
Definition: BitCodes.h:87
uint64_t getLiteralValue() const
Definition: BitCodes.h:108
isPodLike - This is a type trait that is used to determine whether a given type can be copied around ...
Definition: ArrayRef.h:365
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
DEFINE_ABBREV - Defines an abbrev for the current block.
Definition: BitCodes.h:46
FixedAbbrevIDs
Definition: BitCodes.h:37
#define N
static char DecodeChar6(unsigned V)
Definition: BitCodes.h:148
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
Definition: BitCodes.h:132
static bool hasEncodingData(Encoding E)
Definition: BitCodes.h:118
unsigned getNumOperandInfos() const
Definition: BitCodes.h:172
BitCodeAbbrevOp(Encoding E, uint64_t Data=0)
Definition: BitCodes.h:101
Encoding getEncoding() const
Definition: BitCodes.h:111