LLVM  14.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 
12 #include "llvm/ADT/DenseMapInfo.h"
13 #include "llvm/Support/Endian.h"
14 #include <cassert>
15 #include <cinttypes>
16 #include <functional>
17 
18 namespace llvm {
19 
20 class ScopedPrinter;
21 class StringRef;
22 
23 namespace codeview {
24 
25 class TypeCollection;
26 
27 enum class SimpleTypeKind : uint32_t {
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 
40  SByte = 0x0068, // 8 bit signed int
41  Byte = 0x0069, // 8 bit unsigned int
42  Int16Short = 0x0011, // 16 bit signed
43  UInt16Short = 0x0021, // 16 bit unsigned
44  Int16 = 0x0072, // 16 bit signed int
45  UInt16 = 0x0073, // 16 bit unsigned int
46  Int32Long = 0x0012, // 32 bit signed
47  UInt32Long = 0x0022, // 32 bit unsigned
48  Int32 = 0x0074, // 32 bit signed int
49  UInt32 = 0x0075, // 32 bit unsigned int
50  Int64Quad = 0x0013, // 64 bit signed
51  UInt64Quad = 0x0023, // 64 bit unsigned
52  Int64 = 0x0076, // 64 bit signed int
53  UInt64 = 0x0077, // 64 bit unsigned int
54  Int128Oct = 0x0014, // 128 bit signed int
55  UInt128Oct = 0x0024, // 128 bit unsigned int
56  Int128 = 0x0078, // 128 bit signed int
57  UInt128 = 0x0079, // 128 bit unsigned int
58 
59  Float16 = 0x0046, // 16 bit real
60  Float32 = 0x0040, // 32 bit real
61  Float32PartialPrecision = 0x0045, // 32 bit PP real
62  Float48 = 0x0044, // 48 bit real
63  Float64 = 0x0041, // 64 bit real
64  Float80 = 0x0042, // 80 bit real
65  Float128 = 0x0043, // 128 bit real
66 
67  Complex16 = 0x0056, // 16 bit complex
68  Complex32 = 0x0050, // 32 bit complex
69  Complex32PartialPrecision = 0x0055, // 32 bit PP complex
70  Complex48 = 0x0054, // 48 bit complex
71  Complex64 = 0x0051, // 64 bit complex
72  Complex80 = 0x0052, // 80 bit complex
73  Complex128 = 0x0053, // 128 bit complex
74 
75  Boolean8 = 0x0030, // 8 bit boolean
76  Boolean16 = 0x0031, // 16 bit boolean
77  Boolean32 = 0x0032, // 32 bit boolean
78  Boolean64 = 0x0033, // 64 bit boolean
79  Boolean128 = 0x0034, // 128 bit boolean
80 };
81 
82 enum class SimpleTypeMode : uint32_t {
83  Direct = 0x00000000, // Not a pointer
84  NearPointer = 0x00000100, // Near pointer
85  FarPointer = 0x00000200, // Far pointer
86  HugePointer = 0x00000300, // Huge pointer
87  NearPointer32 = 0x00000400, // 32 bit near pointer
88  FarPointer32 = 0x00000500, // 32 bit far pointer
89  NearPointer64 = 0x00000600, // 64 bit near pointer
90  NearPointer128 = 0x00000700 // 128 bit near pointer
91 };
92 
93 /// A 32-bit type reference. Types are indexed by their order of appearance in
94 /// .debug$T plus 0x1000. Type indices less than 0x1000 are "simple" types,
95 /// composed of a SimpleTypeMode byte followed by a SimpleTypeKind byte.
96 class TypeIndex {
97 public:
98  static const uint32_t FirstNonSimpleIndex = 0x1000;
99  static const uint32_t SimpleKindMask = 0x000000ff;
100  static const uint32_t SimpleModeMask = 0x00000700;
101  static const uint32_t DecoratedItemIdMask = 0x80000000;
102 
103 public:
104  TypeIndex() : Index(static_cast<uint32_t>(SimpleTypeKind::None)) {}
105  explicit TypeIndex(uint32_t Index) : Index(Index) {}
107  : Index(static_cast<uint32_t>(Kind)) {}
109  : Index(static_cast<uint32_t>(Kind) | static_cast<uint32_t>(Mode)) {}
110 
111  uint32_t getIndex() const { return Index; }
112  void setIndex(uint32_t I) { Index = I; }
113  bool isSimple() const { return Index < FirstNonSimpleIndex; }
114  bool isDecoratedItemId() const { return !!(Index & DecoratedItemIdMask); }
115 
116  bool isNoneType() const { return *this == None(); }
117 
119  assert(!isSimple());
121  }
122 
124  return TypeIndex(Index + FirstNonSimpleIndex);
125  }
126 
127  static TypeIndex fromDecoratedArrayIndex(bool IsItem, uint32_t Index) {
128  return TypeIndex((Index + FirstNonSimpleIndex) |
129  (IsItem ? DecoratedItemIdMask : 0));
130  }
131 
133  return TypeIndex(Index & ~DecoratedItemIdMask);
134  }
135 
137  assert(isSimple());
138  return static_cast<SimpleTypeKind>(Index & SimpleKindMask);
139  }
140 
142  assert(isSimple());
143  return static_cast<SimpleTypeMode>(Index & SimpleModeMask);
144  }
145 
147 
152  }
155  }
156 
157  static TypeIndex NullptrT() {
158  // std::nullptr_t uses the pointer mode that doesn't indicate bit-width,
159  // presumably because std::nullptr_t is intended to be compatible with any
160  // pointer type.
162  }
163 
166  }
169  }
172  }
175  }
178  }
181  }
187  }
193  }
194 
197 
198  TypeIndex &operator+=(unsigned N) {
199  Index += N;
200  return *this;
201  }
202 
204  Index += 1;
205  return *this;
206  }
207 
209  TypeIndex Copy = *this;
210  operator++();
211  return Copy;
212  }
213 
214  TypeIndex &operator-=(unsigned N) {
215  assert(Index >= N);
216  Index -= N;
217  return *this;
218  }
219 
221  Index -= 1;
222  return *this;
223  }
224 
226  TypeIndex Copy = *this;
227  operator--();
228  return Copy;
229  }
230 
231  friend inline bool operator==(const TypeIndex &A, const TypeIndex &B) {
232  return A.getIndex() == B.getIndex();
233  }
234 
235  friend inline bool operator!=(const TypeIndex &A, const TypeIndex &B) {
236  return A.getIndex() != B.getIndex();
237  }
238 
239  friend inline bool operator<(const TypeIndex &A, const TypeIndex &B) {
240  return A.getIndex() < B.getIndex();
241  }
242 
243  friend inline bool operator<=(const TypeIndex &A, const TypeIndex &B) {
244  return A.getIndex() <= B.getIndex();
245  }
246 
247  friend inline bool operator>(const TypeIndex &A, const TypeIndex &B) {
248  return A.getIndex() > B.getIndex();
249  }
250 
251  friend inline bool operator>=(const TypeIndex &A, const TypeIndex &B) {
252  return A.getIndex() >= B.getIndex();
253  }
254 
255  friend inline TypeIndex operator+(const TypeIndex &A, uint32_t N) {
256  TypeIndex Result(A);
257  Result += N;
258  return Result;
259  }
260 
261  friend inline TypeIndex operator-(const TypeIndex &A, uint32_t N) {
262  assert(A.getIndex() >= N);
263  TypeIndex Result(A);
264  Result -= N;
265  return Result;
266  }
267 
268  friend inline uint32_t operator-(const TypeIndex &A, const TypeIndex &B) {
269  assert(A >= B);
270  return A.toArrayIndex() - B.toArrayIndex();
271  }
272 
274 
275 private:
276  support::ulittle32_t Index;
277 };
278 
279 // Used for pseudo-indexing an array of type records. An array of such records
280 // sorted by TypeIndex can allow log(N) lookups even though such a type record
281 // stream does not provide random access.
285 };
286 
288  TypeCollection &Types);
289 }
290 
291 template <> struct DenseMapInfo<codeview::TypeIndex> {
294  }
297  }
298  static unsigned getHashValue(const codeview::TypeIndex &TI) {
300  }
301  static bool isEqual(const codeview::TypeIndex &LHS,
302  const codeview::TypeIndex &RHS) {
303  return LHS == RHS;
304  }
305 };
306 
307 } // namespace llvm
308 
309 #endif
llvm::codeview::SimpleTypeKind::Byte
@ Byte
llvm::codeview::TypeIndex::isNoneType
bool isNoneType() const
Definition: TypeIndex.h:116
llvm::codeview::SimpleTypeMode::NearPointer32
@ NearPointer32
llvm::codeview::SimpleTypeKind::Complex128
@ Complex128
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:22
llvm::codeview::TypeIndex::SimpleModeMask
static const uint32_t SimpleModeMask
Definition: TypeIndex.h:100
llvm::codeview::SimpleTypeKind::Int32
@ Int32
llvm::codeview::TypeIndex::SignedCharacter
static TypeIndex SignedCharacter()
Definition: TypeIndex.h:164
llvm::codeview::SimpleTypeKind::Complex48
@ Complex48
llvm::support::detail::packed_endian_specific_integral
Definition: Endian.h:206
llvm::codeview::TypeIndex::setIndex
void setIndex(uint32_t I)
Definition: TypeIndex.h:112
llvm::codeview::TypeIndex::FirstNonSimpleIndex
static const uint32_t FirstNonSimpleIndex
Definition: TypeIndex.h:98
llvm::codeview::TypeIndex::operator-=
TypeIndex & operator-=(unsigned N)
Definition: TypeIndex.h:214
llvm::codeview::TypeIndex::operator+=
TypeIndex & operator+=(unsigned N)
Definition: TypeIndex.h:198
llvm::codeview::SimpleTypeKind::Int64Quad
@ Int64Quad
llvm::codeview::TypeIndex::fromArrayIndex
static TypeIndex fromArrayIndex(uint32_t Index)
Definition: TypeIndex.h:123
llvm::codeview::SimpleTypeKind::UInt64Quad
@ UInt64Quad
llvm::codeview::TypeIndex::TypeIndex
TypeIndex(SimpleTypeKind Kind, SimpleTypeMode Mode)
Definition: TypeIndex.h:108
llvm::codeview::SimpleTypeKind
SimpleTypeKind
Definition: TypeIndex.h:27
llvm::codeview::SimpleTypeKind::Complex64
@ Complex64
llvm::codeview::SimpleTypeKind::Float32PartialPrecision
@ Float32PartialPrecision
llvm::codeview::SimpleTypeKind::Complex80
@ Complex80
llvm::codeview::TypeIndex::DecoratedItemIdMask
static const uint32_t DecoratedItemIdMask
Definition: TypeIndex.h:101
llvm::codeview::SimpleTypeKind::Float80
@ Float80
RHS
Value * RHS
Definition: X86PartialReduction.cpp:74
llvm::codeview::SimpleTypeKind::NarrowCharacter
@ NarrowCharacter
llvm::codeview::TypeIndex::Int16Short
static TypeIndex Int16Short()
Definition: TypeIndex.h:176
llvm::codeview::SimpleTypeKind::Boolean8
@ Boolean8
llvm::codeview::TypeIndex::None
static TypeIndex None()
Definition: TypeIndex.h:148
llvm::codeview::SimpleTypeKind::None
@ None
llvm::codeview::TypeIndex::Int32Long
static TypeIndex Int32Long()
Definition: TypeIndex.h:184
llvm::codeview::SimpleTypeMode::NearPointer
@ NearPointer
llvm::DenseMapInfo< codeview::TypeIndex >::isEqual
static bool isEqual(const codeview::TypeIndex &LHS, const codeview::TypeIndex &RHS)
Definition: TypeIndex.h:301
llvm::codeview::SimpleTypeKind::Boolean128
@ Boolean128
llvm::codeview::TypeIndex::UnsignedCharacter
static TypeIndex UnsignedCharacter()
Definition: TypeIndex.h:167
llvm::codeview::SimpleTypeMode::Direct
@ Direct
llvm::DenseMapInfo< codeview::TypeIndex >::getHashValue
static unsigned getHashValue(const codeview::TypeIndex &TI)
Definition: TypeIndex.h:298
llvm::DenseMapInfo< codeview::TypeIndex >::getEmptyKey
static codeview::TypeIndex getEmptyKey()
Definition: TypeIndex.h:292
Printer
print alias Alias Set Printer
Definition: AliasSetTracker.cpp:762
LHS
Value * LHS
Definition: X86PartialReduction.cpp:73
llvm::codeview::printTypeIndex
void printTypeIndex(ScopedPrinter &Printer, StringRef FieldName, TypeIndex TI, TypeCollection &Types)
Definition: TypeIndex.cpp:92
llvm::codeview::TypeIndex::operator-
friend uint32_t operator-(const TypeIndex &A, const TypeIndex &B)
Definition: TypeIndex.h:268
llvm::codeview::TypeIndex::UInt32
static TypeIndex UInt32()
Definition: TypeIndex.h:183
llvm::DenseMapInfo
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: APInt.h:34
llvm::codeview::SimpleTypeKind::Boolean32
@ Boolean32
llvm::codeview::TypeIndex::UInt16Short
static TypeIndex UInt16Short()
Definition: TypeIndex.h:179
llvm::codeview::TypeIndex::NullptrT
static TypeIndex NullptrT()
Definition: TypeIndex.h:157
llvm::codeview::SimpleTypeKind::Boolean16
@ Boolean16
llvm::codeview::SimpleTypeKind::Int16Short
@ Int16Short
llvm::codeview::TypeIndex::makeDirect
TypeIndex makeDirect() const
Definition: TypeIndex.h:146
llvm::codeview::TypeIndex::operator>=
friend bool operator>=(const TypeIndex &A, const TypeIndex &B)
Definition: TypeIndex.h:251
llvm::codeview::SimpleTypeKind::Int128
@ Int128
llvm::codeview::TypeCollection
Definition: TypeCollection.h:18
llvm::codeview::TypeIndex::Void
static TypeIndex Void()
Definition: TypeIndex.h:149
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::codeview::SimpleTypeKind::Complex32
@ Complex32
llvm::codeview::SimpleTypeKind::UInt32Long
@ UInt32Long
llvm::codeview::TypeIndex::Int64
static TypeIndex Int64()
Definition: TypeIndex.h:188
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::codeview::TypeIndex::removeDecoration
TypeIndex removeDecoration()
Definition: TypeIndex.h:132
llvm::DenseMapInfo< codeview::TypeIndex >::getTombstoneKey
static codeview::TypeIndex getTombstoneKey()
Definition: TypeIndex.h:295
llvm::codeview::TypeIndexOffset::Offset
support::ulittle32_t Offset
Definition: TypeIndex.h:284
llvm::codeview::TypeIndex::UInt64Quad
static TypeIndex UInt64Quad()
Definition: TypeIndex.h:191
llvm::codeview::TypeIndex::getSimpleKind
SimpleTypeKind getSimpleKind() const
Definition: TypeIndex.h:136
llvm::codeview::SimpleTypeKind::UInt16Short
@ UInt16Short
llvm::codeview::TypeIndex::operator!=
friend bool operator!=(const TypeIndex &A, const TypeIndex &B)
Definition: TypeIndex.h:235
llvm::codeview::TypeIndex::operator==
friend bool operator==(const TypeIndex &A, const TypeIndex &B)
Definition: TypeIndex.h:231
llvm::codeview::TypeIndex::NarrowCharacter
static TypeIndex NarrowCharacter()
Definition: TypeIndex.h:170
llvm::codeview::SimpleTypeKind::Float128
@ Float128
llvm::codeview::TypeIndex::Float32
static TypeIndex Float32()
Definition: TypeIndex.h:195
llvm::codeview::TypeIndex::operator++
TypeIndex operator++(int)
Definition: TypeIndex.h:208
llvm::codeview::FrameCookieKind::Copy
@ Copy
llvm::codeview::TypeIndex::UInt32Long
static TypeIndex UInt32Long()
Definition: TypeIndex.h:185
llvm::codeview::SimpleTypeKind::Float64
@ Float64
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::codeview::SimpleTypeMode
SimpleTypeMode
Definition: TypeIndex.h:82
llvm::codeview::SimpleTypeKind::Void
@ Void
llvm::codeview::SimpleTypeMode::HugePointer
@ HugePointer
llvm::codeview::TypeIndex::operator--
TypeIndex & operator--()
Definition: TypeIndex.h:220
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::codeview::SimpleTypeKind::Int128Oct
@ Int128Oct
llvm::codeview::TypeIndex::TypeIndex
TypeIndex(SimpleTypeKind Kind)
Definition: TypeIndex.h:106
llvm::codeview::TypeIndex::SimpleKindMask
static const uint32_t SimpleKindMask
Definition: TypeIndex.h:99
Mode
SI Whole Quad Mode
Definition: SIWholeQuadMode.cpp:262
llvm::codeview::TypeIndex::isDecoratedItemId
bool isDecoratedItemId() const
Definition: TypeIndex.h:114
llvm::codeview::SimpleTypeKind::Boolean64
@ Boolean64
llvm::codeview::TypeIndex::operator<
friend bool operator<(const TypeIndex &A, const TypeIndex &B)
Definition: TypeIndex.h:239
llvm::codeview::TypeIndexOffset::Type
TypeIndex Type
Definition: TypeIndex.h:283
llvm::codeview::SimpleTypeKind::Int16
@ Int16
llvm::codeview::TypeIndex::Int32
static TypeIndex Int32()
Definition: TypeIndex.h:182
llvm::codeview::TypeIndex::simpleTypeName
static StringRef simpleTypeName(TypeIndex TI)
Definition: TypeIndex.cpp:70
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::codeview::TypeIndex::toArrayIndex
uint32_t toArrayIndex() const
Definition: TypeIndex.h:118
uint32_t
llvm::codeview::TypeIndex::getSimpleMode
SimpleTypeMode getSimpleMode() const
Definition: TypeIndex.h:141
llvm::codeview::SimpleTypeKind::Int32Long
@ Int32Long
llvm::codeview::SimpleTypeKind::Complex32PartialPrecision
@ Complex32PartialPrecision
llvm::codeview::SimpleTypeMode::FarPointer
@ FarPointer
llvm::codeview::SimpleTypeKind::Float16
@ Float16
llvm::codeview::TypeIndex::operator--
TypeIndex operator--(int)
Definition: TypeIndex.h:225
llvm::codeview::SimpleTypeKind::Float32
@ Float32
llvm::codeview::TypeIndex::operator+
friend TypeIndex operator+(const TypeIndex &A, uint32_t N)
Definition: TypeIndex.h:255
llvm::codeview::SimpleTypeMode::NearPointer64
@ NearPointer64
llvm::codeview::TypeIndex::operator++
TypeIndex & operator++()
Definition: TypeIndex.h:203
llvm::codeview::TypeIndex::VoidPointer32
static TypeIndex VoidPointer32()
Definition: TypeIndex.h:150
llvm::codeview::TypeIndex::operator>
friend bool operator>(const TypeIndex &A, const TypeIndex &B)
Definition: TypeIndex.h:247
llvm::codeview::TypeIndex::TypeIndex
TypeIndex(uint32_t Index)
Definition: TypeIndex.h:105
llvm::codeview::SimpleTypeKind::UInt128Oct
@ UInt128Oct
llvm::ScopedPrinter
Definition: ScopedPrinter.h:101
llvm::codeview::SimpleTypeKind::Character32
@ Character32
llvm::codeview::TypeIndex::Int64Quad
static TypeIndex Int64Quad()
Definition: TypeIndex.h:190
llvm::codeview::SimpleTypeKind::SByte
@ SByte
llvm::codeview::TypeIndex::getIndex
uint32_t getIndex() const
Definition: TypeIndex.h:111
llvm::codeview::SimpleTypeKind::WideCharacter
@ WideCharacter
llvm::codeview::SimpleTypeKind::UInt16
@ UInt16
llvm::codeview::SimpleTypeKind::UnsignedCharacter
@ UnsignedCharacter
llvm::codeview::TypeIndex::isSimple
bool isSimple() const
Definition: TypeIndex.h:113
llvm::codeview::SimpleTypeKind::Complex16
@ Complex16
llvm::codeview::TypeIndex::TypeIndex
TypeIndex()
Definition: TypeIndex.h:104
llvm::codeview::SimpleTypeKind::Float48
@ Float48
N
#define N
llvm::codeview::SimpleTypeKind::Int64
@ Int64
llvm::codeview::TypeIndex::VoidPointer64
static TypeIndex VoidPointer64()
Definition: TypeIndex.h:153
llvm::codeview::SimpleTypeKind::UInt32
@ UInt32
llvm::codeview::SimpleTypeKind::HResult
@ HResult
llvm::codeview::TypeIndex::Float64
static TypeIndex Float64()
Definition: TypeIndex.h:196
llvm::codeview::SimpleTypeMode::FarPointer32
@ FarPointer32
DenseMapInfo.h
llvm::codeview::TypeIndex
A 32-bit type reference.
Definition: TypeIndex.h:96
llvm::codeview::SimpleTypeKind::UInt128
@ UInt128
llvm::codeview::SimpleTypeKind::NotTranslated
@ NotTranslated
llvm::codeview::TypeIndex::operator<=
friend bool operator<=(const TypeIndex &A, const TypeIndex &B)
Definition: TypeIndex.h:243
llvm::codeview::TypeIndexOffset
Definition: TypeIndex.h:282
llvm::codeview::TypeIndex::UInt64
static TypeIndex UInt64()
Definition: TypeIndex.h:189
llvm::codeview::SimpleTypeKind::Character16
@ Character16
Endian.h
llvm::codeview::TypeIndex::fromDecoratedArrayIndex
static TypeIndex fromDecoratedArrayIndex(bool IsItem, uint32_t Index)
Definition: TypeIndex.h:127
llvm::codeview::SimpleTypeKind::SignedCharacter
@ SignedCharacter
llvm::codeview::SimpleTypeMode::NearPointer128
@ NearPointer128
llvm::codeview::SimpleTypeKind::UInt64
@ UInt64
llvm::codeview::TypeIndex::operator-
friend TypeIndex operator-(const TypeIndex &A, uint32_t N)
Definition: TypeIndex.h:261
llvm::codeview::TypeIndex::WideCharacter
static TypeIndex WideCharacter()
Definition: TypeIndex.h:173