LLVM 22.0.0git
TypeIndex.h
Go to the documentation of this file.
1//===- TypeIndex.h ----------------------------------------------*- 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#ifndef LLVM_DEBUGINFO_CODEVIEW_TYPEINDEX_H
10#define LLVM_DEBUGINFO_CODEVIEW_TYPEINDEX_H
11
14#include "llvm/Support/Endian.h"
15#include <cassert>
16#include <cinttypes>
17
18namespace llvm {
19
20class ScopedPrinter;
21class StringRef;
22
23namespace codeview {
24
25class TypeCollection;
26
28 None = 0x0000, // uncharacterized type (no type)
29 Void = 0x0003, // void
30 NotTranslated = 0x0007, // type not translated by cvpack
31 HResult = 0x0008, // OLE/COM HRESULT
32
33 SignedCharacter = 0x0010, // 8 bit signed
34 UnsignedCharacter = 0x0020, // 8 bit unsigned
35 NarrowCharacter = 0x0070, // really a char
36 WideCharacter = 0x0071, // wide char
37 Character16 = 0x007a, // char16_t
38 Character32 = 0x007b, // char32_t
39 Character8 = 0x007c, // char8_t
40
41 SByte = 0x0068, // 8 bit signed int
42 Byte = 0x0069, // 8 bit unsigned int
43 Int16Short = 0x0011, // 16 bit signed
44 UInt16Short = 0x0021, // 16 bit unsigned
45 Int16 = 0x0072, // 16 bit signed int
46 UInt16 = 0x0073, // 16 bit unsigned int
47 Int32Long = 0x0012, // 32 bit signed
48 UInt32Long = 0x0022, // 32 bit unsigned
49 Int32 = 0x0074, // 32 bit signed int
50 UInt32 = 0x0075, // 32 bit unsigned int
51 Int64Quad = 0x0013, // 64 bit signed
52 UInt64Quad = 0x0023, // 64 bit unsigned
53 Int64 = 0x0076, // 64 bit signed int
54 UInt64 = 0x0077, // 64 bit unsigned int
55 Int128Oct = 0x0014, // 128 bit signed int
56 UInt128Oct = 0x0024, // 128 bit unsigned int
57 Int128 = 0x0078, // 128 bit signed int
58 UInt128 = 0x0079, // 128 bit unsigned int
59
60 Float16 = 0x0046, // 16 bit real
61 Float32 = 0x0040, // 32 bit real
62 Float32PartialPrecision = 0x0045, // 32 bit PP real
63 Float48 = 0x0044, // 48 bit real
64 Float64 = 0x0041, // 64 bit real
65 Float80 = 0x0042, // 80 bit real
66 Float128 = 0x0043, // 128 bit real
67
68 Complex16 = 0x0056, // 16 bit complex
69 Complex32 = 0x0050, // 32 bit complex
70 Complex32PartialPrecision = 0x0055, // 32 bit PP complex
71 Complex48 = 0x0054, // 48 bit complex
72 Complex64 = 0x0051, // 64 bit complex
73 Complex80 = 0x0052, // 80 bit complex
74 Complex128 = 0x0053, // 128 bit complex
75
76 Boolean8 = 0x0030, // 8 bit boolean
77 Boolean16 = 0x0031, // 16 bit boolean
78 Boolean32 = 0x0032, // 32 bit boolean
79 Boolean64 = 0x0033, // 64 bit boolean
80 Boolean128 = 0x0034, // 128 bit boolean
81};
82
84 Direct = 0x00000000, // Not a pointer
85 NearPointer = 0x00000100, // Near pointer
86 FarPointer = 0x00000200, // Far pointer
87 HugePointer = 0x00000300, // Huge pointer
88 NearPointer32 = 0x00000400, // 32 bit near pointer
89 FarPointer32 = 0x00000500, // 32 bit far pointer
90 NearPointer64 = 0x00000600, // 64 bit near pointer
91 NearPointer128 = 0x00000700 // 128 bit near pointer
92};
93
94/// A 32-bit type reference. Types are indexed by their order of appearance in
95/// .debug$T plus 0x1000. Type indices less than 0x1000 are "simple" types,
96/// composed of a SimpleTypeMode byte followed by a SimpleTypeKind byte.
97class TypeIndex {
98public:
99 static const uint32_t FirstNonSimpleIndex = 0x1000;
100 static const uint32_t SimpleKindMask = 0x000000ff;
101 static const uint32_t SimpleModeMask = 0x00000700;
102 static const uint32_t DecoratedItemIdMask = 0x80000000;
103
104public:
105 TypeIndex() : Index(static_cast<uint32_t>(SimpleTypeKind::None)) {}
106 explicit TypeIndex(uint32_t Index) : Index(Index) {}
108 : Index(static_cast<uint32_t>(Kind)) {}
110 : Index(static_cast<uint32_t>(Kind) | static_cast<uint32_t>(Mode)) {}
111
112 uint32_t getIndex() const { return Index; }
113 void setIndex(uint32_t I) { Index = I; }
114 bool isSimple() const { return Index < FirstNonSimpleIndex; }
115 bool isDecoratedItemId() const { return !!(Index & DecoratedItemIdMask); }
116
117 bool isNoneType() const { return *this == None(); }
118
120 assert(!isSimple());
122 }
123
125 return TypeIndex(Index + FirstNonSimpleIndex);
126 }
127
128 static TypeIndex fromDecoratedArrayIndex(bool IsItem, uint32_t Index) {
129 return TypeIndex((Index + FirstNonSimpleIndex) |
130 (IsItem ? DecoratedItemIdMask : 0));
131 }
132
134 return TypeIndex(Index & ~DecoratedItemIdMask);
135 }
136
138 assert(isSimple());
139 return static_cast<SimpleTypeKind>(Index & SimpleKindMask);
140 }
141
143 assert(isSimple());
144 return static_cast<SimpleTypeMode>(Index & SimpleModeMask);
145 }
146
148
153 }
156 }
157
159 // std::nullptr_t uses the pointer mode that doesn't indicate bit-width,
160 // presumably because std::nullptr_t is intended to be compatible with any
161 // pointer type.
163 }
164
167 }
170 }
173 }
176 }
179 }
182 }
188 }
194 }
195
198
199 TypeIndex &operator+=(unsigned N) {
200 Index += N;
201 return *this;
202 }
203
205 Index += 1;
206 return *this;
207 }
208
210 TypeIndex Copy = *this;
211 operator++();
212 return Copy;
213 }
214
215 TypeIndex &operator-=(unsigned N) {
216 assert(Index >= N);
217 Index -= N;
218 return *this;
219 }
220
222 Index -= 1;
223 return *this;
224 }
225
227 TypeIndex Copy = *this;
228 operator--();
229 return Copy;
230 }
231
232 friend inline bool operator==(const TypeIndex &A, const TypeIndex &B) {
233 return A.getIndex() == B.getIndex();
234 }
235
236 friend inline bool operator!=(const TypeIndex &A, const TypeIndex &B) {
237 return A.getIndex() != B.getIndex();
238 }
239
240 friend inline bool operator<(const TypeIndex &A, const TypeIndex &B) {
241 return A.getIndex() < B.getIndex();
242 }
243
244 friend inline bool operator<=(const TypeIndex &A, const TypeIndex &B) {
245 return A.getIndex() <= B.getIndex();
246 }
247
248 friend inline bool operator>(const TypeIndex &A, const TypeIndex &B) {
249 return A.getIndex() > B.getIndex();
250 }
251
252 friend inline bool operator>=(const TypeIndex &A, const TypeIndex &B) {
253 return A.getIndex() >= B.getIndex();
254 }
255
256 friend inline TypeIndex operator+(const TypeIndex &A, uint32_t N) {
257 TypeIndex Result(A);
258 Result += N;
259 return Result;
260 }
261
262 friend inline TypeIndex operator-(const TypeIndex &A, uint32_t N) {
263 assert(A.getIndex() >= N);
264 TypeIndex Result(A);
265 Result -= N;
266 return Result;
267 }
268
269 friend inline uint32_t operator-(const TypeIndex &A, const TypeIndex &B) {
270 assert(A >= B);
271 return A.toArrayIndex() - B.toArrayIndex();
272 }
273
275
276private:
278};
279
280// Used for pseudo-indexing an array of type records. An array of such records
281// sorted by TypeIndex can allow log(N) lookups even though such a type record
282// stream does not provide random access.
286};
287
289 TypeIndex TI, TypeCollection &Types);
290}
291
292template <> struct DenseMapInfo<codeview::TypeIndex> {
295 }
298 }
299 static unsigned getHashValue(const codeview::TypeIndex &TI) {
301 }
302 static bool isEqual(const codeview::TypeIndex &LHS,
303 const codeview::TypeIndex &RHS) {
304 return LHS == RHS;
305 }
306};
307
308} // namespace llvm
309
310#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_ABI
Definition: Compiler.h:213
dxil pretty DXIL Metadata Pretty Printer
This file defines DenseMapInfo traits for DenseMap.
#define I(x, y, z)
Definition: MD5.cpp:58
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
Value * RHS
Value * LHS
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
A 32-bit type reference.
Definition: TypeIndex.h:97
static TypeIndex VoidPointer32()
Definition: TypeIndex.h:151
static TypeIndex UInt64Quad()
Definition: TypeIndex.h:192
TypeIndex & operator--()
Definition: TypeIndex.h:221
bool isDecoratedItemId() const
Definition: TypeIndex.h:115
static TypeIndex UInt32()
Definition: TypeIndex.h:184
static TypeIndex fromArrayIndex(uint32_t Index)
Definition: TypeIndex.h:124
static TypeIndex Int16Short()
Definition: TypeIndex.h:177
static TypeIndex WideCharacter()
Definition: TypeIndex.h:174
SimpleTypeKind getSimpleKind() const
Definition: TypeIndex.h:137
static TypeIndex Float64()
Definition: TypeIndex.h:197
static const uint32_t SimpleKindMask
Definition: TypeIndex.h:100
static TypeIndex None()
Definition: TypeIndex.h:149
TypeIndex & operator-=(unsigned N)
Definition: TypeIndex.h:215
void setIndex(uint32_t I)
Definition: TypeIndex.h:113
static TypeIndex Int32Long()
Definition: TypeIndex.h:185
static TypeIndex UInt16Short()
Definition: TypeIndex.h:180
friend bool operator!=(const TypeIndex &A, const TypeIndex &B)
Definition: TypeIndex.h:236
TypeIndex operator++(int)
Definition: TypeIndex.h:209
uint32_t toArrayIndex() const
Definition: TypeIndex.h:119
friend uint32_t operator-(const TypeIndex &A, const TypeIndex &B)
Definition: TypeIndex.h:269
SimpleTypeMode getSimpleMode() const
Definition: TypeIndex.h:142
static TypeIndex fromDecoratedArrayIndex(bool IsItem, uint32_t Index)
Definition: TypeIndex.h:128
static const uint32_t FirstNonSimpleIndex
Definition: TypeIndex.h:99
static TypeIndex UnsignedCharacter()
Definition: TypeIndex.h:168
static LLVM_ABI StringRef simpleTypeName(TypeIndex TI)
Definition: TypeIndex.cpp:71
friend TypeIndex operator+(const TypeIndex &A, uint32_t N)
Definition: TypeIndex.h:256
static const uint32_t DecoratedItemIdMask
Definition: TypeIndex.h:102
static TypeIndex Int64()
Definition: TypeIndex.h:189
TypeIndex(SimpleTypeKind Kind, SimpleTypeMode Mode)
Definition: TypeIndex.h:109
static TypeIndex SignedCharacter()
Definition: TypeIndex.h:165
static TypeIndex Int64Quad()
Definition: TypeIndex.h:191
static TypeIndex UInt32Long()
Definition: TypeIndex.h:186
friend bool operator>(const TypeIndex &A, const TypeIndex &B)
Definition: TypeIndex.h:248
static TypeIndex Void()
Definition: TypeIndex.h:150
static TypeIndex VoidPointer64()
Definition: TypeIndex.h:154
static const uint32_t SimpleModeMask
Definition: TypeIndex.h:101
TypeIndex removeDecoration()
Definition: TypeIndex.h:133
uint32_t getIndex() const
Definition: TypeIndex.h:112
TypeIndex & operator+=(unsigned N)
Definition: TypeIndex.h:199
TypeIndex & operator++()
Definition: TypeIndex.h:204
static TypeIndex NarrowCharacter()
Definition: TypeIndex.h:171
friend bool operator<=(const TypeIndex &A, const TypeIndex &B)
Definition: TypeIndex.h:244
friend bool operator<(const TypeIndex &A, const TypeIndex &B)
Definition: TypeIndex.h:240
TypeIndex operator--(int)
Definition: TypeIndex.h:226
bool isNoneType() const
Definition: TypeIndex.h:117
static TypeIndex UInt64()
Definition: TypeIndex.h:190
static TypeIndex NullptrT()
Definition: TypeIndex.h:158
TypeIndex(uint32_t Index)
Definition: TypeIndex.h:106
friend bool operator>=(const TypeIndex &A, const TypeIndex &B)
Definition: TypeIndex.h:252
friend bool operator==(const TypeIndex &A, const TypeIndex &B)
Definition: TypeIndex.h:232
TypeIndex(SimpleTypeKind Kind)
Definition: TypeIndex.h:107
static TypeIndex Int32()
Definition: TypeIndex.h:183
friend TypeIndex operator-(const TypeIndex &A, uint32_t N)
Definition: TypeIndex.h:262
TypeIndex makeDirect() const
Definition: TypeIndex.h:147
static TypeIndex Float32()
Definition: TypeIndex.h:196
LLVM_ABI void printTypeIndex(ScopedPrinter &Printer, StringRef FieldName, TypeIndex TI, TypeCollection &Types)
Definition: TypeIndex.cpp:93
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
#define N
static bool isEqual(const codeview::TypeIndex &LHS, const codeview::TypeIndex &RHS)
Definition: TypeIndex.h:302
static unsigned getHashValue(const codeview::TypeIndex &TI)
Definition: TypeIndex.h:299
static codeview::TypeIndex getTombstoneKey()
Definition: TypeIndex.h:296
static codeview::TypeIndex getEmptyKey()
Definition: TypeIndex.h:293
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: DenseMapInfo.h:54
support::ulittle32_t Offset
Definition: TypeIndex.h:285