LLVM 22.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
26#include <cassert>
27
28namespace llvm {
29/// BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
30/// This is actually a union of two different things:
31/// 1. It could be a literal integer value ("the operand is always 17").
32/// 2. It could be an encoding specification ("this operand encoded like so").
33///
35public:
36 enum Encoding {
37 Fixed = 1, // A fixed width field, Val specifies number of bits.
38 VBR = 2, // A VBR field where Val specifies the width of each chunk.
39 Array = 3, // A sequence of fields, next field species elt encoding.
40 Char6 = 4, // A 6-bit fixed field which maps to [a-zA-Z0-9._].
41 Blob = 5 // 32-bit aligned array of 8-bit characters.
42 };
43
44protected:
45 uint64_t Val; // A literal value or data for an encoding.
47 uint64_t IsLiteral : 1; // Indicate whether this is a literal value or not.
49 uint64_t Enc : 3; // The encoding to use.
50
51public:
52 static bool isValidEncoding(uint64_t E) {
53 return E >= 1 && E <= 5;
54 }
55
58 : Val(Data), IsLiteral(false), Enc(E) {}
59
60 bool isLiteral() const { return IsLiteral; }
61 bool isEncoding() const { return !IsLiteral; }
62
63 // Accessors for literals.
65
66 // Accessors for encoding info.
70 return Val;
71 }
72
73 bool hasEncodingData() const { return hasEncodingData(getEncoding()); }
74 static bool hasEncodingData(Encoding E) {
75 switch (E) {
76 case Fixed:
77 case VBR:
78 return true;
79 case Array:
80 case Char6:
81 case Blob:
82 return false;
83 }
84 report_fatal_error("Invalid encoding");
85 }
86
87 /// isChar6 - Return true if this character is legal in the Char6 encoding.
88 static bool isChar6(char C) { return isAlnum(C) || C == '.' || C == '_'; }
89 static unsigned EncodeChar6(char C) {
90 if (C >= 'a' && C <= 'z') return C-'a';
91 if (C >= 'A' && C <= 'Z') return C-'A'+26;
92 if (C >= '0' && C <= '9') return C-'0'+26+26;
93 if (C == '.') return 62;
94 if (C == '_') return 63;
95 llvm_unreachable("Not a value Char6 character!");
96 }
97
98 static char DecodeChar6(unsigned V) {
99 assert((V & ~63) == 0 && "Not a Char6 encoded character!");
100 return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._"
101 [V];
102 }
103
104};
105
106/// BitCodeAbbrev - This class represents an abbreviation record. An
107/// abbreviation allows a complex record that has redundancy to be stored in a
108/// specialized format instead of the fully-general, fully-vbr, format.
111
112public:
113 BitCodeAbbrev() = default;
114
115 explicit BitCodeAbbrev(std::initializer_list<BitCodeAbbrevOp> OperandList)
116 : OperandList(OperandList) {}
117
118 unsigned getNumOperandInfos() const {
119 return static_cast<unsigned>(OperandList.size());
120 }
121 const BitCodeAbbrevOp &getOperandInfo(unsigned N) const {
122 return OperandList[N];
123 }
124
125 void Add(const BitCodeAbbrevOp &OpInfo) {
126 OperandList.push_back(OpInfo);
127 }
128};
129} // namespace llvm
130
131#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_PREFERRED_TYPE(T)
\macro LLVM_PREFERRED_TYPE Adjust type of bit-field in debug info.
Definition: Compiler.h:706
This file defines the SmallVector class.
This file contains some functions that are useful when dealing with strings.
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
Definition: BitCodes.h:34
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
Definition: BitCodes.h:88
uint64_t getLiteralValue() const
Definition: BitCodes.h:64
static bool isValidEncoding(uint64_t E)
Definition: BitCodes.h:52
BitCodeAbbrevOp(uint64_t V)
Definition: BitCodes.h:56
static unsigned EncodeChar6(char C)
Definition: BitCodes.h:89
bool hasEncodingData() const
Definition: BitCodes.h:73
bool isLiteral() const
Definition: BitCodes.h:60
bool isEncoding() const
Definition: BitCodes.h:61
static bool hasEncodingData(Encoding E)
Definition: BitCodes.h:74
BitCodeAbbrevOp(Encoding E, uint64_t Data=0)
Definition: BitCodes.h:57
uint64_t IsLiteral
Definition: BitCodes.h:47
Encoding getEncoding() const
Definition: BitCodes.h:67
static char DecodeChar6(unsigned V)
Definition: BitCodes.h:98
uint64_t getEncodingData() const
Definition: BitCodes.h:68
BitCodeAbbrev - This class represents an abbreviation record.
Definition: BitCodes.h:109
BitCodeAbbrev(std::initializer_list< BitCodeAbbrevOp > OperandList)
Definition: BitCodes.h:115
unsigned getNumOperandInfos() const
Definition: BitCodes.h:118
void Add(const BitCodeAbbrevOp &OpInfo)
Definition: BitCodes.h:125
const BitCodeAbbrevOp & getOperandInfo(unsigned N) const
Definition: BitCodes.h:121
BitCodeAbbrev()=default
size_t size() const
Definition: SmallVector.h:79
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition: Error.cpp:167
#define N