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