LLVM 22.0.0git
LVType.h
Go to the documentation of this file.
1//===-- LVType.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// This file defines the LVType class, which is used to describe a debug
10// information type.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVTYPE_H
15#define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVTYPE_H
16
19
20namespace llvm {
21namespace logicalview {
22
23enum class LVTypeKind {
24 IsBase,
25 IsConst,
44 IsModifier, // CodeView - LF_MODIFIER
46};
47using LVTypeKindSelection = std::set<LVTypeKind>;
48using LVTypeDispatch = std::map<LVTypeKind, LVTypeGetFunction>;
49using LVTypeRequest = std::vector<LVTypeGetFunction>;
50
51// Class to represent a DWARF Type.
52class LLVM_ABI LVType : public LVElement {
53 enum class Property { IsSubrangeCount, LastEntry };
54
55 // Typed bitvector with kinds and properties for this type.
57 LVProperties<Property> Properties;
58 static LVTypeDispatch Dispatch;
59
60 // Size in bits of a symbol of this type.
61 uint32_t BitSize = 0;
62
63 // Find the current type in the given 'Targets'.
64 LVType *findIn(const LVTypes *Targets) const;
65
66public:
67 LVType() : LVElement(LVSubclassID::LV_TYPE) { setIsType(); }
68 LVType(const LVType &) = delete;
69 LVType &operator=(const LVType &) = delete;
70 virtual ~LVType() = default;
71
72 static bool classof(const LVElement *Element) {
73 return Element->getSubclassID() == LVSubclassID::LV_TYPE;
74 }
75
76 KIND(LVTypeKind, IsBase);
77 KIND(LVTypeKind, IsConst);
78 KIND(LVTypeKind, IsEnumerator);
79 KIND(LVTypeKind, IsImport);
80 KIND_1(LVTypeKind, IsImportDeclaration, IsImport);
81 KIND_1(LVTypeKind, IsImportModule, IsImport);
82 KIND(LVTypeKind, IsPointer);
83 KIND(LVTypeKind, IsPointerMember);
84 KIND(LVTypeKind, IsReference);
85 KIND(LVTypeKind, IsRestrict);
86 KIND(LVTypeKind, IsRvalueReference);
87 KIND(LVTypeKind, IsSubrange);
88 KIND(LVTypeKind, IsTemplateParam);
89 KIND_1(LVTypeKind, IsTemplateTemplateParam, IsTemplateParam);
90 KIND_1(LVTypeKind, IsTemplateTypeParam, IsTemplateParam);
91 KIND_1(LVTypeKind, IsTemplateValueParam, IsTemplateParam);
92 KIND(LVTypeKind, IsTypedef);
93 KIND(LVTypeKind, IsUnaligned);
94 KIND(LVTypeKind, IsUnspecified);
95 KIND(LVTypeKind, IsVolatile);
96 KIND(LVTypeKind, IsModifier);
97
98 PROPERTY(Property, IsSubrangeCount);
99
100 const char *kind() const override;
101
102 // Follow a chain of references given by DW_AT_abstract_origin and/or
103 // DW_AT_specification and update the type name.
104 StringRef resolveReferencesChain();
105
106 bool isBase() const override { return getIsBase(); }
107 bool isTemplateParam() const override { return getIsTemplateParam(); }
108
109 // Encode the specific template argument.
110 virtual void encodeTemplateArgument(std::string &Name) const {}
111
112 // Return the underlying type for a type definition.
113 virtual LVElement *getUnderlyingType() { return nullptr; }
114 virtual void setUnderlyingType(LVElement *Element) {}
115
116 // Return the size in bits of an entity of this type.
117 uint32_t getBitSize() const override { return BitSize; }
118 void setBitSize(uint32_t Size) override { BitSize = Size; }
119
120 void resolveName() override;
121 void resolveReferences() override;
122
123 static LVTypeDispatch &getDispatch() { return Dispatch; }
124
125 static bool parametersMatch(const LVTypes *References,
126 const LVTypes *Targets);
127
128 static void getParameters(const LVTypes *Types, LVTypes *TypesParam,
129 LVScopes *ScopesParam);
130
131 // Iterate through the 'References' set and check that all its elements
132 // are present in the 'Targets' set. For a missing element, mark its
133 // parents as missing.
134 static void markMissingParents(const LVTypes *References,
135 const LVTypes *Targets);
136
137 // Returns true if current type is logically equal to the given 'Type'.
138 virtual bool equals(const LVType *Type) const;
139
140 // Returns true if the given 'References' are logically equal to the
141 // given 'Targets'.
142 static bool equals(const LVTypes *References, const LVTypes *Targets);
143
144 // Report the current type as missing or added during comparison.
145 void report(LVComparePass Pass) override;
146
147 void print(raw_ostream &OS, bool Full = true) const override;
148 void printExtra(raw_ostream &OS, bool Full = true) const override;
149};
150
151// Class to represent DW_TAG_typedef_type.
152class LLVM_ABI LVTypeDefinition final : public LVType {
153public:
155 setIsTypedef();
156 setIncludeInPrint();
157 }
160 ~LVTypeDefinition() = default;
161
162 // Return the underlying type for a type definition.
163 LVElement *getUnderlyingType() override;
164 void setUnderlyingType(LVElement *Element) override { setType(Element); }
165
166 void resolveExtra() override;
167
168 // Returns true if current type is logically equal to the given 'Type'.
169 bool equals(const LVType *Type) const override;
170
171 void printExtra(raw_ostream &OS, bool Full = true) const override;
172};
173
174// Class to represent a DW_TAG_enumerator.
175class LLVM_ABI LVTypeEnumerator final : public LVType {
176 // Index in the String pool representing any initial value.
177 size_t ValueIndex = 0;
178
179public:
181 setIsEnumerator();
182 setIncludeInPrint();
183 }
186 ~LVTypeEnumerator() = default;
187
188 // Process the values for a DW_TAG_enumerator.
189 StringRef getValue() const override {
190 return getStringPool().getString(ValueIndex);
191 }
192 void setValue(StringRef Value) override {
193 ValueIndex = getStringPool().getIndex(Value);
194 }
195 size_t getValueIndex() const override { return ValueIndex; }
196
197 // Returns true if current type is logically equal to the given 'Type'.
198 bool equals(const LVType *Type) const override;
199
200 void printExtra(raw_ostream &OS, bool Full = true) const override;
201};
202
203// Class to represent DW_TAG_imported_module / DW_TAG_imported_declaration.
204class LLVM_ABI LVTypeImport final : public LVType {
205public:
206 LVTypeImport() : LVType() { setIncludeInPrint(); }
207 LVTypeImport(const LVTypeImport &) = delete;
209 ~LVTypeImport() = default;
210
211 // Returns true if current type is logically equal to the given 'Type'.
212 bool equals(const LVType *Type) const override;
213
214 void printExtra(raw_ostream &OS, bool Full = true) const override;
215};
216
217// Class to represent a DWARF Template parameter holder (type or param).
218class LLVM_ABI LVTypeParam final : public LVType {
219 // Index in the String pool representing any initial value.
220 size_t ValueIndex = 0;
221
222public:
223 LVTypeParam();
224 LVTypeParam(const LVTypeParam &) = delete;
226 ~LVTypeParam() = default;
227
228 // Template parameter value.
229 StringRef getValue() const override {
230 return getStringPool().getString(ValueIndex);
231 }
232 void setValue(StringRef Value) override {
233 ValueIndex = getStringPool().getIndex(Value);
234 }
235 size_t getValueIndex() const override { return ValueIndex; }
236
237 // Encode the specific template argument.
238 void encodeTemplateArgument(std::string &Name) const override;
239
240 // Returns true if current type is logically equal to the given 'Type'.
241 bool equals(const LVType *Type) const override;
242
243 void printExtra(raw_ostream &OS, bool Full = true) const override;
244};
245
246// Class to represent a DW_TAG_subrange_type.
247class LLVM_ABI LVTypeSubrange final : public LVType {
248 // Values describing the subrange bounds.
249 int64_t LowerBound = 0; // DW_AT_lower_bound or DW_AT_count value.
250 int64_t UpperBound = 0; // DW_AT_upper_bound value.
251
252public:
254 setIsSubrange();
255 setIncludeInPrint();
256 }
259 ~LVTypeSubrange() = default;
260
261 int64_t getCount() const override {
262 return getIsSubrangeCount() ? LowerBound : 0;
263 }
264 void setCount(int64_t Value) override {
265 LowerBound = Value;
266 setIsSubrangeCount();
267 }
268
269 int64_t getLowerBound() const override { return LowerBound; }
270 void setLowerBound(int64_t Value) override { LowerBound = Value; }
271
272 int64_t getUpperBound() const override { return UpperBound; }
273 void setUpperBound(int64_t Value) override { UpperBound = Value; }
274
275 std::pair<unsigned, unsigned> getBounds() const override {
276 return {LowerBound, UpperBound};
277 }
278 void setBounds(unsigned Lower, unsigned Upper) override {
279 LowerBound = Lower;
280 UpperBound = Upper;
281 }
282
283 void resolveExtra() override;
284
285 // Returns true if current type is logically equal to the given 'Type'.
286 bool equals(const LVType *Type) const override;
287
288 void printExtra(raw_ostream &OS, bool Full = true) const override;
289};
290
291} // end namespace logicalview
292} // end namespace llvm
293
294#endif // LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVTYPE_H
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
#define LLVM_ABI
Definition: Compiler.h:213
std::string Name
uint64_t Size
raw_pwrite_stream & OS
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:99
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:75
LVSubclassID getSubclassID() const
Definition: LVElement.h:148
StringRef getString(size_t Index) const
Definition: LVStringPool.h:70
size_t getIndex(StringRef Key)
Definition: LVStringPool.h:58
void setUnderlyingType(LVElement *Element) override
Definition: LVType.h:164
LVTypeDefinition & operator=(const LVTypeDefinition &)=delete
LVTypeDefinition(const LVTypeDefinition &)=delete
size_t getValueIndex() const override
Definition: LVType.h:195
void setValue(StringRef Value) override
Definition: LVType.h:192
LVTypeEnumerator(const LVTypeEnumerator &)=delete
StringRef getValue() const override
Definition: LVType.h:189
LVTypeEnumerator & operator=(const LVTypeEnumerator &)=delete
LVTypeImport(const LVTypeImport &)=delete
LVTypeImport & operator=(const LVTypeImport &)=delete
LVTypeParam(const LVTypeParam &)=delete
size_t getValueIndex() const override
Definition: LVType.h:235
void setValue(StringRef Value) override
Definition: LVType.h:232
LVTypeParam & operator=(const LVTypeParam &)=delete
StringRef getValue() const override
Definition: LVType.h:229
LVTypeSubrange & operator=(const LVTypeSubrange &)=delete
LVTypeSubrange(const LVTypeSubrange &)=delete
void setLowerBound(int64_t Value) override
Definition: LVType.h:270
void setUpperBound(int64_t Value) override
Definition: LVType.h:273
void setBounds(unsigned Lower, unsigned Upper) override
Definition: LVType.h:278
std::pair< unsigned, unsigned > getBounds() const override
Definition: LVType.h:275
int64_t getUpperBound() const override
Definition: LVType.h:272
void setCount(int64_t Value) override
Definition: LVType.h:264
int64_t getCount() const override
Definition: LVType.h:261
int64_t getLowerBound() const override
Definition: LVType.h:269
KIND(LVTypeKind, IsRvalueReference)
KIND(LVTypeKind, IsTemplateParam)
KIND_1(LVTypeKind, IsImportModule, IsImport)
KIND(LVTypeKind, IsEnumerator)
virtual ~LVType()=default
KIND(LVTypeKind, IsBase)
KIND(LVTypeKind, IsUnspecified)
KIND(LVTypeKind, IsRestrict)
KIND(LVTypeKind, IsConst)
LVType(const LVType &)=delete
void setBitSize(uint32_t Size) override
Definition: LVType.h:118
KIND(LVTypeKind, IsTypedef)
KIND(LVTypeKind, IsReference)
static LVTypeDispatch & getDispatch()
Definition: LVType.h:123
KIND(LVTypeKind, IsPointer)
KIND_1(LVTypeKind, IsImportDeclaration, IsImport)
PROPERTY(Property, IsSubrangeCount)
KIND(LVTypeKind, IsVolatile)
LVType & operator=(const LVType &)=delete
uint32_t getBitSize() const override
Definition: LVType.h:117
bool isBase() const override
Definition: LVType.h:106
KIND(LVTypeKind, IsModifier)
KIND(LVTypeKind, IsImport)
virtual void encodeTemplateArgument(std::string &Name) const
Definition: LVType.h:110
virtual void setUnderlyingType(LVElement *Element)
Definition: LVType.h:114
KIND_1(LVTypeKind, IsTemplateTemplateParam, IsTemplateParam)
virtual LVElement * getUnderlyingType()
Definition: LVType.h:113
KIND(LVTypeKind, IsPointerMember)
KIND(LVTypeKind, IsUnaligned)
bool isTemplateParam() const override
Definition: LVType.h:107
static bool classof(const LVElement *Element)
Definition: LVType.h:72
KIND(LVTypeKind, IsSubrange)
KIND_1(LVTypeKind, IsTemplateValueParam, IsTemplateParam)
KIND_1(LVTypeKind, IsTemplateTypeParam, IsTemplateParam)
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
LLVM_ABI LVStringPool & getStringPool()
Definition: LVSupport.cpp:25
std::set< LVTypeKind > LVTypeKindSelection
Definition: LVType.h:47
std::map< LVTypeKind, LVTypeGetFunction > LVTypeDispatch
Definition: LVType.h:48
std::vector< LVTypeGetFunction > LVTypeRequest
Definition: LVType.h:49
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18