LLVM  16.0.0git
TypeIndex.cpp
Go to the documentation of this file.
1 //===-- TypeIndex.cpp - CodeView type index ---------------------*- 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 
10 
13 
14 using namespace llvm;
15 using namespace llvm::codeview;
16 
17 namespace {
18 struct SimpleTypeEntry {
21 };
22 
23 /// The names here all end in "*". If the simple type is a pointer type, we
24 /// return the whole name. Otherwise we lop off the last character in our
25 /// StringRef.
26 static const SimpleTypeEntry SimpleTypeNames[] = {
27  {"void*", SimpleTypeKind::Void},
28  {"<not translated>*", SimpleTypeKind::NotTranslated},
29  {"HRESULT*", SimpleTypeKind::HResult},
30  {"signed char*", SimpleTypeKind::SignedCharacter},
31  {"unsigned char*", SimpleTypeKind::UnsignedCharacter},
33  {"wchar_t*", SimpleTypeKind::WideCharacter},
34  {"char16_t*", SimpleTypeKind::Character16},
35  {"char32_t*", SimpleTypeKind::Character32},
36  {"char8_t*", SimpleTypeKind::Character8},
37  {"__int8*", SimpleTypeKind::SByte},
38  {"unsigned __int8*", SimpleTypeKind::Byte},
39  {"short*", SimpleTypeKind::Int16Short},
40  {"unsigned short*", SimpleTypeKind::UInt16Short},
41  {"__int16*", SimpleTypeKind::Int16},
42  {"unsigned __int16*", SimpleTypeKind::UInt16},
43  {"long*", SimpleTypeKind::Int32Long},
44  {"unsigned long*", SimpleTypeKind::UInt32Long},
45  {"int*", SimpleTypeKind::Int32},
46  {"unsigned*", SimpleTypeKind::UInt32},
47  {"__int64*", SimpleTypeKind::Int64Quad},
48  {"unsigned __int64*", SimpleTypeKind::UInt64Quad},
49  {"__int64*", SimpleTypeKind::Int64},
50  {"unsigned __int64*", SimpleTypeKind::UInt64},
51  {"__int128*", SimpleTypeKind::Int128},
52  {"unsigned __int128*", SimpleTypeKind::UInt128},
53  {"__half*", SimpleTypeKind::Float16},
54  {"float*", SimpleTypeKind::Float32},
56  {"__float48*", SimpleTypeKind::Float48},
57  {"double*", SimpleTypeKind::Float64},
58  {"long double*", SimpleTypeKind::Float80},
59  {"__float128*", SimpleTypeKind::Float128},
60  {"_Complex float*", SimpleTypeKind::Complex32},
61  {"_Complex double*", SimpleTypeKind::Complex64},
62  {"_Complex long double*", SimpleTypeKind::Complex80},
63  {"_Complex __float128*", SimpleTypeKind::Complex128},
64  {"bool*", SimpleTypeKind::Boolean8},
65  {"__bool16*", SimpleTypeKind::Boolean16},
66  {"__bool32*", SimpleTypeKind::Boolean32},
67  {"__bool64*", SimpleTypeKind::Boolean64},
68 };
69 } // namespace
70 
72  assert(TI.isNoneType() || TI.isSimple());
73 
74  if (TI.isNoneType())
75  return "<no type>";
76 
77  if (TI == TypeIndex::NullptrT())
78  return "std::nullptr_t";
79 
80  // This is a simple type.
81  for (const auto &SimpleTypeName : SimpleTypeNames) {
82  if (SimpleTypeName.Kind == TI.getSimpleKind()) {
84  return SimpleTypeName.Name.drop_back(1);
85  // Otherwise, this is a pointer type. We gloss over the distinction
86  // between near, far, 64, 32, etc, and just give a pointer type.
87  return SimpleTypeName.Name;
88  }
89  }
90  return "<unknown simple type>";
91 }
92 
94  TypeIndex TI, TypeCollection &Types) {
96  if (!TI.isNoneType()) {
97  if (TI.isSimple())
99  else
100  TypeName = Types.getTypeName(TI);
101  }
102 
103  if (!TypeName.empty())
104  Printer.printHex(FieldName, TypeName, TI.getIndex());
105  else
106  Printer.printHex(FieldName, TI.getIndex());
107 }
llvm::codeview::SimpleTypeKind::Byte
@ Byte
llvm::codeview::TypeIndex::isNoneType
bool isNoneType() const
Definition: TypeIndex.h:116
llvm::codeview::SimpleTypeKind::Complex128
@ Complex128
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::codeview::SimpleTypeKind::Int32
@ Int32
llvm::codeview::SimpleTypeKind::Int64Quad
@ Int64Quad
llvm::codeview::SimpleTypeKind::UInt64Quad
@ UInt64Quad
llvm::codeview::SimpleTypeKind
SimpleTypeKind
Definition: TypeIndex.h:26
llvm::codeview::SimpleTypeKind::Complex64
@ Complex64
llvm::codeview::SimpleTypeKind::Float32PartialPrecision
@ Float32PartialPrecision
llvm::codeview::SimpleTypeKind::Complex80
@ Complex80
llvm::codeview::SimpleTypeKind::Float80
@ Float80
llvm::codeview::SimpleTypeKind::NarrowCharacter
@ NarrowCharacter
llvm::codeview::SimpleTypeKind::Boolean8
@ Boolean8
llvm::codeview::SimpleTypeMode::Direct
@ Direct
llvm::codeview::printTypeIndex
void printTypeIndex(ScopedPrinter &Printer, StringRef FieldName, TypeIndex TI, TypeCollection &Types)
Definition: TypeIndex.cpp:93
llvm::codeview::SimpleTypeKind::Boolean32
@ Boolean32
llvm::codeview::TypeIndex::NullptrT
static TypeIndex NullptrT()
Definition: TypeIndex.h:157
llvm::codeview::SimpleTypeKind::Boolean16
@ Boolean16
llvm::codeview::SimpleTypeKind::Int16Short
@ Int16Short
llvm::codeview::SimpleTypeKind::Int128
@ Int128
llvm::codeview::TypeCollection
Definition: TypeCollection.h:18
llvm::codeview::SimpleTypeKind::Complex32
@ Complex32
llvm::codeview::SimpleTypeKind::UInt32Long
@ UInt32Long
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::codeview::SimpleTypeKind::Character8
@ Character8
llvm::codeview::TypeIndex::getSimpleKind
SimpleTypeKind getSimpleKind() const
Definition: TypeIndex.h:136
llvm::codeview::SimpleTypeKind::UInt16Short
@ UInt16Short
llvm::codeview::SimpleTypeKind::Float128
@ Float128
llvm::codeview::SimpleTypeKind::Float64
@ Float64
llvm::codeview::SimpleTypeKind::Void
@ Void
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::codeview::SimpleTypeKind::Boolean64
@ Boolean64
llvm::codeview::SimpleTypeKind::Int16
@ Int16
llvm::codeview::TypeIndex::simpleTypeName
static StringRef simpleTypeName(TypeIndex TI)
Definition: TypeIndex.cpp:71
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Printer
Memory true print Memory SSA Printer
Definition: MemorySSA.cpp:80
llvm::codeview::TypeIndex::getSimpleMode
SimpleTypeMode getSimpleMode() const
Definition: TypeIndex.h:141
llvm::codeview::SimpleTypeKind::Int32Long
@ Int32Long
llvm::codeview::SimpleTypeKind::Float16
@ Float16
llvm::codeview::SimpleTypeKind::Float32
@ Float32
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::AMDGPU::HSAMD::Kernel::Arg::Key::TypeName
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
Definition: AMDGPUMetadata.h:175
TypeCollection.h
llvm::ScopedPrinter
Definition: ScopedPrinter.h:100
llvm::codeview::SimpleTypeKind::Character32
@ Character32
llvm::codeview::SimpleTypeKind::SByte
@ SByte
llvm::codeview::TypeIndex::getIndex
uint32_t getIndex() const
Definition: TypeIndex.h:111
TypeIndex.h
llvm::codeview::SimpleTypeKind::WideCharacter
@ WideCharacter
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::codeview::SimpleTypeKind::UInt16
@ UInt16
llvm::codeview::SimpleTypeKind::UnsignedCharacter
@ UnsignedCharacter
llvm::codeview::TypeIndex::isSimple
bool isSimple() const
Definition: TypeIndex.h:113
llvm::codeview::SimpleTypeKind::Float48
@ Float48
llvm::codeview::SimpleTypeKind::Int64
@ Int64
llvm::codeview::SimpleTypeKind::UInt32
@ UInt32
llvm::codeview::SimpleTypeKind::HResult
@ HResult
llvm::codeview::TypeIndex
A 32-bit type reference.
Definition: TypeIndex.h:96
llvm::codeview::SimpleTypeKind::UInt128
@ UInt128
llvm::codeview::SimpleTypeKind::NotTranslated
@ NotTranslated
llvm::codeview::SimpleTypeKind::Character16
@ Character16
llvm::codeview::SimpleTypeKind::SignedCharacter
@ SignedCharacter
llvm::codeview::SimpleTypeKind::UInt64
@ UInt64
ScopedPrinter.h