LLVM 20.0.0git
LVElement.h
Go to the documentation of this file.
1//===-- LVElement.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 LVElement class, which is used to describe a debug
10// information element.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVELEMENT_H
15#define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVELEMENT_H
16
19#include <map>
20#include <set>
21#include <vector>
22
23namespace llvm {
24namespace logicalview {
25
26// RTTI Subclasses ID.
27enum class LVSubclassID : unsigned char {
30 LV_LINE,
53 LV_TYPE,
60};
61
63using LVElementKindSet = std::set<LVElementKind>;
64using LVElementDispatch = std::map<LVElementKind, LVElementGetFunction>;
65using LVElementRequest = std::vector<LVElementGetFunction>;
66
67class LVElement : public LVObject {
68 enum class Property {
69 IsLine, // A logical line.
70 IsScope, // A logical scope.
71 IsSymbol, // A logical symbol.
72 IsType, // A logical type.
73 IsEnumClass,
74 IsExternal,
75 HasType,
76 HasAugmentedName,
77 IsTypedefReduced,
78 IsArrayResolved,
79 IsMemberPointerResolved,
80 IsTemplateResolved,
81 IsInlined,
82 IsInlinedAbstract,
83 InvalidFilename,
84 HasReference,
85 HasReferenceAbstract,
86 HasReferenceExtension,
87 HasReferenceSpecification,
88 QualifiedResolved,
89 IncludeInPrint,
90 IsStatic,
91 TransformName,
92 IsScoped, // CodeView local type.
93 IsNested, // CodeView nested type.
94 IsScopedAlready, // CodeView nested type inserted in correct scope.
95 IsArtificial,
96 IsReferencedType,
97 IsSystem,
98 OffsetFromTypeIndex,
99 IsAnonymous,
101 };
102 // Typed bitvector with properties for this element.
103 LVProperties<Property> Properties;
104 static LVElementDispatch Dispatch;
105
106 /// RTTI.
107 const LVSubclassID SubclassID;
108
109 // Indexes in the String Pool.
110 size_t NameIndex = 0;
111 size_t QualifiedNameIndex = 0;
112 size_t FilenameIndex = 0;
113
114 uint16_t AccessibilityCode : 2; // DW_AT_accessibility.
115 uint16_t InlineCode : 2; // DW_AT_inline.
116 uint16_t VirtualityCode : 2; // DW_AT_virtuality.
117
118 // The given Specification points to an element that is connected via the
119 // DW_AT_specification, DW_AT_abstract_origin or DW_AT_extension attribute.
120 void setFileLine(LVElement *Specification);
121
122 // Get the qualified name that include its parents name.
123 void resolveQualifiedName();
124
125protected:
126 // Type of this element.
128
129 // Print the FileName Index.
130 void printFileIndex(raw_ostream &OS, bool Full = true) const override;
131
132public:
134 : LVObject(), SubclassID(ID), AccessibilityCode(0), InlineCode(0),
135 VirtualityCode(0) {}
136 LVElement(const LVElement &) = delete;
137 LVElement &operator=(const LVElement &) = delete;
138 virtual ~LVElement() = default;
139
140 LVSubclassID getSubclassID() const { return SubclassID; }
141
142 PROPERTY(Property, IsLine);
143 PROPERTY(Property, IsScope);
144 PROPERTY(Property, IsSymbol);
145 PROPERTY(Property, IsType);
146 PROPERTY(Property, IsEnumClass);
147 PROPERTY(Property, IsExternal);
148 PROPERTY(Property, HasType);
149 PROPERTY(Property, HasAugmentedName);
150 PROPERTY(Property, IsTypedefReduced);
151 PROPERTY(Property, IsArrayResolved);
152 PROPERTY(Property, IsMemberPointerResolved);
153 PROPERTY(Property, IsTemplateResolved);
154 PROPERTY(Property, IsInlined);
155 PROPERTY(Property, IsInlinedAbstract);
156 PROPERTY(Property, InvalidFilename);
157 PROPERTY(Property, HasReference);
158 PROPERTY(Property, HasReferenceAbstract);
159 PROPERTY(Property, HasReferenceExtension);
160 PROPERTY(Property, HasReferenceSpecification);
161 PROPERTY(Property, QualifiedResolved);
162 PROPERTY(Property, IncludeInPrint);
163 PROPERTY(Property, IsStatic);
164 PROPERTY(Property, TransformName);
165 PROPERTY(Property, IsScoped);
166 PROPERTY(Property, IsNested);
167 PROPERTY(Property, IsScopedAlready);
168 PROPERTY(Property, IsArtificial);
169 PROPERTY(Property, IsReferencedType);
170 PROPERTY(Property, IsSystem);
171 PROPERTY(Property, OffsetFromTypeIndex);
172 PROPERTY(Property, IsAnonymous);
173
174 bool isNamed() const override { return NameIndex != 0; }
175 bool isTyped() const override { return ElementType != nullptr; }
176 bool isFiled() const override { return FilenameIndex != 0; }
177
178 // The Element class type can point to a Type or Scope.
179 bool getIsKindType() const { return ElementType && ElementType->getIsType(); }
180 bool getIsKindScope() const {
181 return ElementType && ElementType->getIsScope();
182 }
183
184 StringRef getName() const override {
185 return getStringPool().getString(NameIndex);
186 }
187 void setName(StringRef ElementName) override;
188
189 // Get pathname associated with the Element.
192 }
193
194 // Set filename associated with the Element.
196
197 // Set the Element qualified name.
199 QualifiedNameIndex = getStringPool().getIndex(Name);
200 }
202 return getStringPool().getString(QualifiedNameIndex);
203 }
204
205 size_t getNameIndex() const { return NameIndex; }
206 size_t getQualifiedNameIndex() const { return QualifiedNameIndex; }
207
210
211 // Element type name.
212 StringRef getTypeName() const;
213
214 virtual StringRef getProducer() const { return StringRef(); }
215 virtual void setProducer(StringRef ProducerName) {}
216
217 virtual bool isCompileUnit() const { return false; }
218 virtual bool isRoot() const { return false; }
219
221 virtual void setReference(LVScope *Scope) {}
222 virtual void setReference(LVSymbol *Symbol) {}
223 virtual void setReference(LVType *Type) {}
224
226 virtual StringRef getLinkageName() const { return StringRef(); }
227 virtual size_t getLinkageNameIndex() const { return 0; }
228
229 virtual uint32_t getCallLineNumber() const { return 0; }
231 virtual size_t getCallFilenameIndex() const { return 0; }
232 virtual void setCallFilenameIndex(size_t Index) {}
233 size_t getFilenameIndex() const { return FilenameIndex; }
234 void setFilenameIndex(size_t Index) { FilenameIndex = Index; }
235
236 // Set the File location for the Element.
237 void setFile(LVElement *Reference = nullptr);
238
239 virtual bool isBase() const { return false; }
240 virtual bool isTemplateParam() const { return false; }
241
242 virtual uint32_t getBitSize() const { return 0; }
243 virtual void setBitSize(uint32_t Size) {}
244
245 virtual int64_t getCount() const { return 0; }
246 virtual void setCount(int64_t Value) {}
247 virtual int64_t getLowerBound() const { return 0; }
248 virtual void setLowerBound(int64_t Value) {}
249 virtual int64_t getUpperBound() const { return 0; }
250 virtual void setUpperBound(int64_t Value) {}
251 virtual std::pair<unsigned, unsigned> getBounds() const { return {}; }
252 virtual void setBounds(unsigned Lower, unsigned Upper) {}
253
254 // Access DW_AT_GNU_discriminator attribute.
255 virtual uint32_t getDiscriminator() const { return 0; }
257
258 // Process the values for a DW_TAG_enumerator.
259 virtual StringRef getValue() const { return {}; }
260 virtual void setValue(StringRef Value) {}
261 virtual size_t getValueIndex() const { return 0; }
262
263 // DWARF Accessibility Codes.
264 uint32_t getAccessibilityCode() const { return AccessibilityCode; }
265 void setAccessibilityCode(uint32_t Access) { AccessibilityCode = Access; }
268
269 // CodeView Accessibility Codes.
270 std::optional<uint32_t> getAccessibilityCode(codeview::MemberAccess Access);
272 if (std::optional<uint32_t> Code = getAccessibilityCode(Access))
273 AccessibilityCode = Code.value();
274 }
275
276 // DWARF Inline Codes.
277 uint32_t getInlineCode() const { return InlineCode; }
278 void setInlineCode(uint32_t Code) { InlineCode = Code; }
280
281 // DWARF Virtuality Codes.
282 uint32_t getVirtualityCode() const { return VirtualityCode; }
283 void setVirtualityCode(uint32_t Virtuality) { VirtualityCode = Virtuality; }
285 virtualityString(uint32_t Virtuality = dwarf::DW_VIRTUALITY_none) const;
286
287 // CodeView Virtuality Codes.
288 std::optional<uint32_t> getVirtualityCode(codeview::MethodKind Virtuality);
290 if (std::optional<uint32_t> Code = getVirtualityCode(Virtuality))
291 VirtualityCode = Code.value();
292 }
293
294 // DWARF Extern Codes.
296
297 LVElement *getType() const { return ElementType; }
298 LVType *getTypeAsType() const;
299 LVScope *getTypeAsScope() const;
300
301 void setType(LVElement *Element = nullptr) {
303 if (Element) {
304 setHasType();
305 Element->setIsReferencedType();
306 }
307 }
308
309 // Set the type for the element, handling template parameters.
311
314 }
315
316 StringRef typeAsString() const;
317 std::string typeOffsetAsString() const;
318 std::string discriminatorAsString() const;
319
320 LVScope *traverseParents(LVScopeGetFunction GetFunction) const;
321
322 LVScope *getFunctionParent() const;
323 virtual LVScope *getCompileUnitParent() const;
324
325 // Print any referenced element.
326 void printReference(raw_ostream &OS, bool Full, LVElement *Parent) const;
327
328 // Print the linkage name (Symbols and functions).
329 void printLinkageName(raw_ostream &OS, bool Full, LVElement *Parent,
330 LVScope *Scope) const;
331 void printLinkageName(raw_ostream &OS, bool Full, LVElement *Parent) const;
332
333 // Generate the full name for the Element.
335
336 // Generate a name for unnamed elements.
337 void generateName(std::string &Prefix) const;
338 void generateName();
339
340 virtual bool removeElement(LVElement *Element) { return false; }
341 virtual void updateLevel(LVScope *Parent, bool Moved = false);
342
343 // During the parsing of the debug information, the logical elements are
344 // created with information extracted from its description entries (DIE).
345 // But they are not complete for the logical view concept. A second pass
346 // is executed in order to collect their additional information.
347 // The following functions 'resolve' some of their properties, such as
348 // name, references, parents, extra information based on the element kind.
349 virtual void resolve();
350 virtual void resolveExtra() {}
351 virtual void resolveName();
352 virtual void resolveReferences() {}
353 void resolveParents();
354
355 bool referenceMatch(const LVElement *Element) const;
356
357 // Returns true if current element is logically equal to the given 'Element'.
358 bool equals(const LVElement *Element) const;
359
360 // Report the current element as missing or added during comparison.
361 virtual void report(LVComparePass Pass) {}
362
363 static LVElementDispatch &getDispatch() { return Dispatch; }
364};
365
366} // end namespace logicalview
367} // end namespace llvm
368
369#endif // LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVELEMENT_H
uint64_t Size
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
PROPERTY(Property, IsTypedefReduced)
virtual void setCount(int64_t Value)
Definition: LVElement.h:246
size_t getNameIndex() const
Definition: LVElement.h:205
PROPERTY(Property, IsEnumClass)
void setAccessibilityCode(codeview::MemberAccess Access)
Definition: LVElement.h:271
std::string discriminatorAsString() const
Definition: LVElement.cpp:59
PROPERTY(Property, IsScoped)
LVScope * traverseParents(LVScopeGetFunction GetFunction) const
Definition: LVElement.cpp:419
virtual void setCallLineNumber(uint32_t Number)
Definition: LVElement.h:230
PROPERTY(Property, HasReferenceSpecification)
virtual bool isTemplateParam() const
Definition: LVElement.h:240
virtual LVScope * getCompileUnitParent() const
Definition: LVElement.cpp:430
StringRef getQualifiedName() const
Definition: LVElement.h:201
virtual void setReference(LVScope *Scope)
Definition: LVElement.h:221
void resolveFullname(LVElement *BaseType, StringRef Name=emptyString())
Definition: LVElement.cpp:274
PROPERTY(Property, IsType)
virtual ~LVElement()=default
virtual void setReference(LVSymbol *Symbol)
Definition: LVElement.h:222
PROPERTY(Property, IsMemberPointerResolved)
virtual void setBitSize(uint32_t Size)
Definition: LVElement.h:243
PROPERTY(Property, IsInlinedAbstract)
virtual void setLinkageName(StringRef LinkageName)
Definition: LVElement.h:225
virtual void setProducer(StringRef ProducerName)
Definition: LVElement.h:215
LVScope * getFunctionParent() const
Definition: LVElement.cpp:426
static LVElementDispatch & getDispatch()
Definition: LVElement.h:363
virtual void setUpperBound(int64_t Value)
Definition: LVElement.h:250
virtual void setDiscriminator(uint32_t Value)
Definition: LVElement.h:256
virtual bool isRoot() const
Definition: LVElement.h:218
virtual size_t getCallFilenameIndex() const
Definition: LVElement.h:231
virtual void setLowerBound(int64_t Value)
Definition: LVElement.h:248
virtual void updateLevel(LVScope *Parent, bool Moved=false)
Definition: LVElement.cpp:267
LVElement(LVSubclassID ID)
Definition: LVElement.h:133
virtual int64_t getCount() const
Definition: LVElement.h:245
LVElement(const LVElement &)=delete
StringRef virtualityString(uint32_t Virtuality=dwarf::DW_VIRTUALITY_none) const
Definition: LVElement.cpp:171
bool isFiled() const override
Definition: LVElement.h:176
uint32_t getInlineCode() const
Definition: LVElement.h:277
StringRef typeAsString() const
Definition: LVElement.cpp:69
virtual uint32_t getDiscriminator() const
Definition: LVElement.h:255
virtual StringRef getValue() const
Definition: LVElement.h:259
virtual bool isBase() const
Definition: LVElement.h:239
virtual void setValue(StringRef Value)
Definition: LVElement.h:260
void setFilename(StringRef Filename)
Definition: LVElement.cpp:102
void setInlineCode(uint32_t Code)
Definition: LVElement.h:278
void setQualifiedName(StringRef Name)
Definition: LVElement.h:198
PROPERTY(Property, InvalidFilename)
StringRef externalString() const
Definition: LVElement.cpp:151
virtual void setReference(LVElement *Element)
Definition: LVElement.h:220
PROPERTY(Property, IsLine)
PROPERTY(Property, HasAugmentedName)
virtual StringRef getLinkageName() const
Definition: LVElement.h:226
void setName(StringRef ElementName) override
Definition: LVElement.cpp:96
void setGenericType(LVElement *Element)
Definition: LVElement.cpp:43
virtual bool isCompileUnit() const
Definition: LVElement.h:217
virtual size_t getValueIndex() const
Definition: LVElement.h:261
PROPERTY(Property, IsSymbol)
PROPERTY(Property, HasReferenceExtension)
StringRef getName() const override
Definition: LVElement.h:184
virtual int64_t getUpperBound() const
Definition: LVElement.h:249
PROPERTY(Property, HasReference)
LVType * getTypeAsType() const
Definition: LVElement.cpp:30
LVElement & operator=(const LVElement &)=delete
LVElement * getType() const
Definition: LVElement.h:297
bool referenceMatch(const LVElement *Element) const
Definition: LVElement.cpp:470
PROPERTY(Property, IsStatic)
PROPERTY(Property, IsArrayResolved)
virtual StringRef getProducer() const
Definition: LVElement.h:214
PROPERTY(Property, IsAnonymous)
PROPERTY(Property, IsInlined)
void setAccessibilityCode(uint32_t Access)
Definition: LVElement.h:265
virtual uint32_t getCallLineNumber() const
Definition: LVElement.h:229
uint32_t getAccessibilityCode() const
Definition: LVElement.h:264
PROPERTY(Property, IsNested)
virtual uint32_t getBitSize() const
Definition: LVElement.h:242
PROPERTY(Property, HasType)
void setVirtualityCode(uint32_t Virtuality)
Definition: LVElement.h:283
virtual void setReference(LVType *Type)
Definition: LVElement.h:223
void setFile(LVElement *Reference=nullptr)
Definition: LVElement.cpp:374
void setType(LVElement *Element=nullptr)
Definition: LVElement.h:301
StringRef getTypeName() const
Definition: LVElement.cpp:74
void printLinkageName(raw_ostream &OS, bool Full, LVElement *Parent, LVScope *Scope) const
Definition: LVElement.cpp:556
StringRef getTypeQualifiedName() const
Definition: LVElement.h:312
PROPERTY(Property, IsReferencedType)
virtual void report(LVComparePass Pass)
Definition: LVElement.h:361
PROPERTY(Property, IsSystem)
virtual int64_t getLowerBound() const
Definition: LVElement.h:247
PROPERTY(Property, IsArtificial)
StringRef accessibilityString(uint32_t Access=dwarf::DW_ACCESS_private) const
Definition: LVElement.cpp:124
void setFilenameIndex(size_t Index)
Definition: LVElement.h:234
PROPERTY(Property, IncludeInPrint)
bool equals(const LVElement *Element) const
Definition: LVElement.cpp:475
StringRef inlineCodeString(uint32_t Code) const
Definition: LVElement.cpp:155
virtual std::pair< unsigned, unsigned > getBounds() const
Definition: LVElement.h:251
uint32_t getVirtualityCode() const
Definition: LVElement.h:282
PROPERTY(Property, QualifiedResolved)
size_t getFilenameIndex() const
Definition: LVElement.h:233
std::string typeOffsetAsString() const
Definition: LVElement.cpp:116
bool isTyped() const override
Definition: LVElement.h:175
void printFileIndex(raw_ostream &OS, bool Full=true) const override
Definition: LVElement.cpp:520
PROPERTY(Property, HasReferenceAbstract)
virtual void setCallFilenameIndex(size_t Index)
Definition: LVElement.h:232
StringRef getPathname() const
Definition: LVElement.h:190
PROPERTY(Property, IsScope)
size_t getQualifiedNameIndex() const
Definition: LVElement.h:206
virtual bool removeElement(LVElement *Element)
Definition: LVElement.h:340
PROPERTY(Property, IsExternal)
void setVirtualityCode(codeview::MethodKind Virtuality)
Definition: LVElement.h:289
PROPERTY(Property, OffsetFromTypeIndex)
virtual size_t getLinkageNameIndex() const
Definition: LVElement.h:227
PROPERTY(Property, TransformName)
PROPERTY(Property, IsScopedAlready)
LVSubclassID getSubclassID() const
Definition: LVElement.h:140
bool isNamed() const override
Definition: LVElement.h:174
void printReference(raw_ostream &OS, bool Full, LVElement *Parent) const
Definition: LVElement.cpp:540
virtual void resolveExtra()
Definition: LVElement.h:350
LVScope * getTypeAsScope() const
Definition: LVElement.cpp:36
virtual void setBounds(unsigned Lower, unsigned Upper)
Definition: LVElement.h:252
PROPERTY(Property, IsTemplateResolved)
virtual void resolveReferences()
Definition: LVElement.h:352
StringRef getString(size_t Index) const
Definition: LVStringPool.h:70
size_t getIndex(StringRef Key)
Definition: LVStringPool.h:58
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
MethodKind
Part of member attribute flags. (CV_methodprop_e)
Definition: CodeView.h:280
MemberAccess
Source-level access specifier. (CV_access_e)
Definition: CodeView.h:272
@ DW_ACCESS_private
Definition: Dwarf.h:185
LVStringPool & getStringPool()
Definition: LVSupport.cpp:27
std::set< LVElementKind > LVElementKindSet
Definition: LVElement.h:63
StringRef emptyString()
Definition: LVObject.cpp:32
bool(LVScope::*)() const LVScopeGetFunction
Definition: LVObject.h:70
std::vector< LVElementGetFunction > LVElementRequest
Definition: LVElement.h:65
std::map< LVElementKind, LVElementGetFunction > LVElementDispatch
Definition: LVElement.h:64
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18