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