LLVM 20.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
18
19namespace llvm {
20namespace logicalview {
21
22enum class LVTypeKind {
23 IsBase,
24 IsConst,
43 IsModifier, // CodeView - LF_MODIFIER
45};
46using LVTypeKindSelection = std::set<LVTypeKind>;
47using LVTypeDispatch = std::map<LVTypeKind, LVTypeGetFunction>;
48using LVTypeRequest = std::vector<LVTypeGetFunction>;
49
50// Class to represent a DWARF Type.
51class LVType : public LVElement {
52 enum class Property { IsSubrangeCount, LastEntry };
53
54 // Typed bitvector with kinds and properties for this type.
56 LVProperties<Property> Properties;
57 static LVTypeDispatch Dispatch;
58
59 // Find the current type in the given 'Targets'.
60 LVType *findIn(const LVTypes *Targets) const;
61
62public:
63 LVType() : LVElement(LVSubclassID::LV_TYPE) { setIsType(); }
64 LVType(const LVType &) = delete;
65 LVType &operator=(const LVType &) = delete;
66 virtual ~LVType() = default;
67
68 static bool classof(const LVElement *Element) {
70 }
71
93
94 PROPERTY(Property, IsSubrangeCount);
95
96 const char *kind() const override;
97
98 // Follow a chain of references given by DW_AT_abstract_origin and/or
99 // DW_AT_specification and update the type name.
101
102 bool isBase() const override { return getIsBase(); }
103 bool isTemplateParam() const override { return getIsTemplateParam(); }
104
105 // Encode the specific template argument.
106 virtual void encodeTemplateArgument(std::string &Name) const {}
107
108 // Return the underlying type for a type definition.
109 virtual LVElement *getUnderlyingType() { return nullptr; }
111
112 void resolveName() override;
113 void resolveReferences() override;
114
115 static LVTypeDispatch &getDispatch() { return Dispatch; }
116
117 static bool parametersMatch(const LVTypes *References,
118 const LVTypes *Targets);
119
120 static void getParameters(const LVTypes *Types, LVTypes *TypesParam,
121 LVScopes *ScopesParam);
122
123 // Iterate through the 'References' set and check that all its elements
124 // are present in the 'Targets' set. For a missing element, mark its
125 // parents as missing.
126 static void markMissingParents(const LVTypes *References,
127 const LVTypes *Targets);
128
129 // Returns true if current type is logically equal to the given 'Type'.
130 virtual bool equals(const LVType *Type) const;
131
132 // Returns true if the given 'References' are logically equal to the
133 // given 'Targets'.
134 static bool equals(const LVTypes *References, const LVTypes *Targets);
135
136 // Report the current type as missing or added during comparison.
137 void report(LVComparePass Pass) override;
138
139 void print(raw_ostream &OS, bool Full = true) const override;
140 void printExtra(raw_ostream &OS, bool Full = true) const override;
141
142#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
143 void dump() const override { print(dbgs()); }
144#endif
145};
146
147// Class to represent DW_TAG_typedef_type.
148class LVTypeDefinition final : public LVType {
149public:
151 setIsTypedef();
152 setIncludeInPrint();
153 }
156 ~LVTypeDefinition() = default;
157
158 // Return the underlying type for a type definition.
159 LVElement *getUnderlyingType() override;
161
162 void resolveExtra() override;
163
164 // Returns true if current type is logically equal to the given 'Type'.
165 bool equals(const LVType *Type) const override;
166
167 void printExtra(raw_ostream &OS, bool Full = true) const override;
168};
169
170// Class to represent a DW_TAG_enumerator.
171class LVTypeEnumerator final : public LVType {
172 // Index in the String pool representing any initial value.
173 size_t ValueIndex = 0;
174
175public:
177 setIsEnumerator();
178 setIncludeInPrint();
179 }
182 ~LVTypeEnumerator() = default;
183
184 // Process the values for a DW_TAG_enumerator.
185 StringRef getValue() const override {
186 return getStringPool().getString(ValueIndex);
187 }
188 void setValue(StringRef Value) override {
189 ValueIndex = getStringPool().getIndex(Value);
190 }
191 size_t getValueIndex() const override { return ValueIndex; }
192
193 // Returns true if current type is logically equal to the given 'Type'.
194 bool equals(const LVType *Type) const override;
195
196 void printExtra(raw_ostream &OS, bool Full = true) const override;
197};
198
199// Class to represent DW_TAG_imported_module / DW_TAG_imported_declaration.
200class LVTypeImport final : public LVType {
201public:
202 LVTypeImport() : LVType() { setIncludeInPrint(); }
203 LVTypeImport(const LVTypeImport &) = delete;
205 ~LVTypeImport() = default;
206
207 // Returns true if current type is logically equal to the given 'Type'.
208 bool equals(const LVType *Type) const override;
209
210 void printExtra(raw_ostream &OS, bool Full = true) const override;
211};
212
213// Class to represent a DWARF Template parameter holder (type or param).
214class LVTypeParam final : public LVType {
215 // Index in the String pool representing any initial value.
216 size_t ValueIndex = 0;
217
218public:
219 LVTypeParam();
220 LVTypeParam(const LVTypeParam &) = delete;
222 ~LVTypeParam() = default;
223
224 // Template parameter value.
225 StringRef getValue() const override {
226 return getStringPool().getString(ValueIndex);
227 }
228 void setValue(StringRef Value) override {
229 ValueIndex = getStringPool().getIndex(Value);
230 }
231 size_t getValueIndex() const override { return ValueIndex; }
232
233 // Encode the specific template argument.
234 void encodeTemplateArgument(std::string &Name) const override;
235
236 // Returns true if current type is logically equal to the given 'Type'.
237 bool equals(const LVType *Type) const override;
238
239 void printExtra(raw_ostream &OS, bool Full = true) const override;
240};
241
242// Class to represent a DW_TAG_subrange_type.
243class LVTypeSubrange final : public LVType {
244 // Values describing the subrange bounds.
245 int64_t LowerBound = 0; // DW_AT_lower_bound or DW_AT_count value.
246 int64_t UpperBound = 0; // DW_AT_upper_bound value.
247
248public:
250 setIsSubrange();
251 setIncludeInPrint();
252 }
255 ~LVTypeSubrange() = default;
256
257 int64_t getCount() const override {
258 return getIsSubrangeCount() ? LowerBound : 0;
259 }
260 void setCount(int64_t Value) override {
261 LowerBound = Value;
262 setIsSubrangeCount();
263 }
264
265 int64_t getLowerBound() const override { return LowerBound; }
266 void setLowerBound(int64_t Value) override { LowerBound = Value; }
267
268 int64_t getUpperBound() const override { return UpperBound; }
269 void setUpperBound(int64_t Value) override { UpperBound = Value; }
270
271 std::pair<unsigned, unsigned> getBounds() const override {
272 return {LowerBound, UpperBound};
273 }
274 void setBounds(unsigned Lower, unsigned Upper) override {
275 LowerBound = Lower;
276 UpperBound = Upper;
277 }
278
279 void resolveExtra() override;
280
281 // Returns true if current type is logically equal to the given 'Type'.
282 bool equals(const LVType *Type) const override;
283
284 void printExtra(raw_ostream &OS, bool Full = true) const override;
285};
286
287} // end namespace logicalview
288} // end namespace llvm
289
290#endif // LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVTYPE_H
raw_pwrite_stream & OS
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:94
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
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:74
void setType(LVElement *Element=nullptr)
Definition: LVElement.h:301
LVSubclassID getSubclassID() const
Definition: LVElement.h:140
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:160
bool equals(const LVType *Type) const override
Definition: LVType.cpp:352
LVTypeDefinition & operator=(const LVTypeDefinition &)=delete
LVTypeDefinition(const LVTypeDefinition &)=delete
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition: LVType.cpp:356
LVElement * getUnderlyingType() override
Definition: LVType.cpp:302
size_t getValueIndex() const override
Definition: LVType.h:191
void setValue(StringRef Value) override
Definition: LVType.h:188
LVTypeEnumerator(const LVTypeEnumerator &)=delete
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition: LVType.cpp:369
StringRef getValue() const override
Definition: LVType.h:185
LVTypeEnumerator & operator=(const LVTypeEnumerator &)=delete
bool equals(const LVType *Type) const override
Definition: LVType.cpp:365
LVTypeImport(const LVTypeImport &)=delete
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition: LVType.cpp:381
LVTypeImport & operator=(const LVTypeImport &)=delete
bool equals(const LVType *Type) const override
Definition: LVType.cpp:377
LVTypeParam(const LVTypeParam &)=delete
size_t getValueIndex() const override
Definition: LVType.h:231
void setValue(StringRef Value) override
Definition: LVType.h:228
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition: LVType.cpp:466
void encodeTemplateArgument(std::string &Name) const override
Definition: LVType.cpp:398
bool equals(const LVType *Type) const override
Definition: LVType.cpp:451
LVTypeParam & operator=(const LVTypeParam &)=delete
StringRef getValue() const override
Definition: LVType.h:225
LVTypeSubrange & operator=(const LVTypeSubrange &)=delete
LVTypeSubrange(const LVTypeSubrange &)=delete
void setLowerBound(int64_t Value) override
Definition: LVType.h:266
void setUpperBound(int64_t Value) override
Definition: LVType.h:269
void setBounds(unsigned Lower, unsigned Upper) override
Definition: LVType.h:274
std::pair< unsigned, unsigned > getBounds() const override
Definition: LVType.h:271
int64_t getUpperBound() const override
Definition: LVType.h:268
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition: LVType.cpp:522
void setCount(int64_t Value) override
Definition: LVType.h:260
int64_t getCount() const override
Definition: LVType.h:257
bool equals(const LVType *Type) const override
Definition: LVType.cpp:515
int64_t getLowerBound() const override
Definition: LVType.h:265
void resolveReferences() override
Definition: LVType.cpp:109
KIND(LVTypeKind, IsRvalueReference)
KIND(LVTypeKind, IsTemplateParam)
KIND_1(LVTypeKind, IsImportModule, IsImport)
KIND(LVTypeKind, IsEnumerator)
virtual ~LVType()=default
KIND(LVTypeKind, IsBase)
virtual bool equals(const LVType *Type) const
Definition: LVType.cpp:265
void report(LVComparePass Pass) override
Definition: LVType.cpp:281
KIND(LVTypeKind, IsUnspecified)
KIND(LVTypeKind, IsRestrict)
KIND(LVTypeKind, IsConst)
LVType(const LVType &)=delete
KIND(LVTypeKind, IsTypedef)
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition: LVType.cpp:294
KIND(LVTypeKind, IsReference)
static bool parametersMatch(const LVTypes *References, const LVTypes *Targets)
Definition: LVType.cpp:225
static LVTypeDispatch & getDispatch()
Definition: LVType.h:115
KIND(LVTypeKind, IsPointer)
KIND_1(LVTypeKind, IsImportDeclaration, IsImport)
StringRef resolveReferencesChain()
Definition: LVType.cpp:167
PROPERTY(Property, IsSubrangeCount)
KIND(LVTypeKind, IsVolatile)
LVType & operator=(const LVType &)=delete
void resolveName() override
Definition: LVType.cpp:122
bool isBase() const override
Definition: LVType.h:102
KIND(LVTypeKind, IsModifier)
void dump() const override
Definition: LVType.h:143
KIND(LVTypeKind, IsImport)
virtual void encodeTemplateArgument(std::string &Name) const
Definition: LVType.h:106
const char * kind() const override
Definition: LVType.cpp:48
static void getParameters(const LVTypes *Types, LVTypes *TypesParam, LVScopes *ScopesParam)
Definition: LVType.cpp:245
virtual void setUnderlyingType(LVElement *Element)
Definition: LVType.h:110
KIND_1(LVTypeKind, IsTemplateTemplateParam, IsTemplateParam)
virtual LVElement * getUnderlyingType()
Definition: LVType.h:109
KIND(LVTypeKind, IsPointerMember)
KIND(LVTypeKind, IsUnaligned)
void print(raw_ostream &OS, bool Full=true) const override
Definition: LVType.cpp:285
bool isTemplateParam() const override
Definition: LVType.h:103
static void markMissingParents(const LVTypes *References, const LVTypes *Targets)
Definition: LVType.cpp:173
static bool classof(const LVElement *Element)
Definition: LVType.h:68
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:52
LVStringPool & getStringPool()
Definition: LVSupport.cpp:27
std::set< LVTypeKind > LVTypeKindSelection
Definition: LVType.h:46
std::map< LVTypeKind, LVTypeGetFunction > LVTypeDispatch
Definition: LVType.h:47
std::vector< LVTypeGetFunction > LVTypeRequest
Definition: LVType.h:48
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163