LLVM 22.0.0git
LVSymbol.h
Go to the documentation of this file.
1//===-- LVSymbol.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 LVSymbol class, which is used to describe a debug
10// information symbol.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSYMBOL_H
15#define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSYMBOL_H
16
19
20namespace llvm {
21namespace logicalview {
22
23enum class LVSymbolKind {
32};
33using LVSymbolKindSet = std::set<LVSymbolKind>;
34using LVSymbolDispatch = std::map<LVSymbolKind, LVSymbolGetFunction>;
35using LVSymbolRequest = std::vector<LVSymbolGetFunction>;
36
37class LLVM_ABI LVSymbol final : public LVElement {
38 enum class Property { HasLocation, FillGaps, LastEntry };
39
40 // Typed bitvector with kinds and properties for this symbol.
42 LVProperties<Property> Properties;
43 static LVSymbolDispatch Dispatch;
44
45 // CodeView symbol Linkage name.
46 size_t LinkageNameIndex = 0;
47
48 // Reference to DW_AT_specification, DW_AT_abstract_origin attribute.
49 LVSymbol *Reference = nullptr;
50 std::unique_ptr<LVLocations> Locations;
51 LVLocation *CurrentLocation = nullptr;
52
53 // Bitfields length.
54 uint32_t BitSize = 0;
55
56 // Index in the String pool representing any initial value.
57 size_t ValueIndex = 0;
58
59 // Coverage factor in units (bytes).
60 unsigned CoverageFactor = 0;
61 float CoveragePercentage = 0;
62
63 // Add a location gap into the location list.
65 LVAddress LowPC, LVAddress HighPC);
66
67 // Find the current symbol in the given 'Targets'.
68 LVSymbol *findIn(const LVSymbols *Targets) const;
69
70public:
72 setIsSymbol();
73 setIncludeInPrint();
74 }
75 LVSymbol(const LVSymbol &) = delete;
76 LVSymbol &operator=(const LVSymbol &) = delete;
77 ~LVSymbol() = default;
78
79 static bool classof(const LVElement *Element) {
80 return Element->getSubclassID() == LVSubclassID::LV_SYMBOL;
81 }
82
83 KIND(LVSymbolKind, IsCallSiteParameter);
84 KIND(LVSymbolKind, IsConstant);
85 KIND(LVSymbolKind, IsInheritance);
86 KIND(LVSymbolKind, IsMember);
87 KIND(LVSymbolKind, IsParameter);
88 KIND(LVSymbolKind, IsUnspecified);
89 KIND(LVSymbolKind, IsVariable);
90
91 PROPERTY(Property, HasLocation);
92 PROPERTY(Property, FillGaps);
93
94 const char *kind() const override;
95
96 // Access DW_AT_specification, DW_AT_abstract_origin reference.
97 LVSymbol *getReference() const { return Reference; }
98 void setReference(LVSymbol *Symbol) override {
99 Reference = Symbol;
100 setHasReference();
101 }
102 void setReference(LVElement *Element) override {
103 assert((!Element || isa<LVSymbol>(Element)) && "Invalid element");
104 setReference(static_cast<LVSymbol *>(Element));
105 }
106
107 void setLinkageName(StringRef LinkageName) override {
108 LinkageNameIndex = getStringPool().getIndex(LinkageName);
109 }
110 StringRef getLinkageName() const override {
111 return getStringPool().getString(LinkageNameIndex);
112 }
113 size_t getLinkageNameIndex() const override { return LinkageNameIndex; }
114
115 uint32_t getBitSize() const override { return BitSize; }
116 void setBitSize(uint32_t Size) override { BitSize = Size; }
117
118 // Process the values for a DW_AT_const_value.
119 StringRef getValue() const override {
120 return getStringPool().getString(ValueIndex);
121 }
122 void setValue(StringRef Value) override {
123 ValueIndex = getStringPool().getIndex(Value);
124 }
125 size_t getValueIndex() const override { return ValueIndex; }
126
127 // Add a Location Entry.
128 void addLocationConstant(dwarf::Attribute Attr, LVUnsigned Constant,
129 uint64_t LocDescOffset);
130 void addLocationOperands(LVSmall Opcode, ArrayRef<uint64_t> Operands);
131 void addLocation(dwarf::Attribute Attr, LVAddress LowPC, LVAddress HighPC,
132 LVUnsigned SectionOffset, uint64_t LocDescOffset,
133 bool CallSiteLocation = false);
134
135 // Fill gaps in the location list.
136 void fillLocationGaps();
137
138 // Get all the locations associated with symbols.
139 void getLocations(LVLocations &LocationList, LVValidLocation ValidLocation,
140 bool RecordInvalid = false);
141 void getLocations(LVLocations &LocationList) const;
142
143 // Calculate coverage factor.
144 void calculateCoverage();
145
146 unsigned getCoverageFactor() const { return CoverageFactor; }
147 void setCoverageFactor(unsigned Value) { CoverageFactor = Value; }
148 float getCoveragePercentage() const { return CoveragePercentage; }
149 void setCoveragePercentage(float Value) { CoveragePercentage = Value; }
150
151 // Print location in raw format.
152 void printLocations(raw_ostream &OS, bool Full = true) const;
153
154 // Follow a chain of references given by DW_AT_abstract_origin and/or
155 // DW_AT_specification and update the symbol name.
156 StringRef resolveReferencesChain();
157
158 void resolveName() override;
159 void resolveReferences() override;
160
161 static LVSymbolDispatch &getDispatch() { return Dispatch; }
162
163 static bool parametersMatch(const LVSymbols *References,
164 const LVSymbols *Targets);
165
166 static void getParameters(const LVSymbols *Symbols, LVSymbols *Parameters);
167
168 // Iterate through the 'References' set and check that all its elements
169 // are present in the 'Targets' set. For a missing element, mark its
170 // parents as missing.
171 static void markMissingParents(const LVSymbols *References,
172 const LVSymbols *Targets);
173
174 // Returns true if current type is logically equal to the given 'Symbol'.
175 bool equals(const LVSymbol *Symbol) const;
176
177 // Returns true if the given 'References' are logically equal to the
178 // given 'Targets'.
179 static bool equals(const LVSymbols *References, const LVSymbols *Targets);
180
181 // Report the current symbol as missing or added during comparison.
182 void report(LVComparePass Pass) override;
183
184 void print(raw_ostream &OS, bool Full = true) const override;
185 void printExtra(raw_ostream &OS, bool Full = true) const override;
186};
187
188} // end namespace logicalview
189} // end namespace llvm
190
191#endif // LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSYMBOL_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
#define LLVM_ABI
Definition: Compiler.h:213
uint64_t Size
mir Rename Register Operands
raw_pwrite_stream & OS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
This is an important base class in LLVM.
Definition: Constant.h:43
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:99
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
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 setBitSize(uint32_t Size) override
Definition: LVSymbol.h:116
LVSymbol & operator=(const LVSymbol &)=delete
void setCoveragePercentage(float Value)
Definition: LVSymbol.h:149
size_t getLinkageNameIndex() const override
Definition: LVSymbol.h:113
LVSymbol(const LVSymbol &)=delete
PROPERTY(Property, FillGaps)
KIND(LVSymbolKind, IsUnspecified)
KIND(LVSymbolKind, IsCallSiteParameter)
KIND(LVSymbolKind, IsConstant)
float getCoveragePercentage() const
Definition: LVSymbol.h:148
KIND(LVSymbolKind, IsInheritance)
StringRef getLinkageName() const override
Definition: LVSymbol.h:110
KIND(LVSymbolKind, IsMember)
static LVSymbolDispatch & getDispatch()
Definition: LVSymbol.h:161
StringRef getValue() const override
Definition: LVSymbol.h:119
void setLinkageName(StringRef LinkageName) override
Definition: LVSymbol.h:107
KIND(LVSymbolKind, IsParameter)
void setReference(LVElement *Element) override
Definition: LVSymbol.h:102
static bool classof(const LVElement *Element)
Definition: LVSymbol.h:79
PROPERTY(Property, HasLocation)
uint32_t getBitSize() const override
Definition: LVSymbol.h:115
void setReference(LVSymbol *Symbol) override
Definition: LVSymbol.h:98
void setCoverageFactor(unsigned Value)
Definition: LVSymbol.h:147
size_t getValueIndex() const override
Definition: LVSymbol.h:125
LVSymbol * getReference() const
Definition: LVSymbol.h:97
void setValue(StringRef Value) override
Definition: LVSymbol.h:122
KIND(LVSymbolKind, IsVariable)
unsigned getCoverageFactor() const
Definition: LVSymbol.h:146
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
Attribute
Attributes.
Definition: Dwarf.h:124
std::vector< LVSymbolGetFunction > LVSymbolRequest
Definition: LVSymbol.h:35
LLVM_ABI LVStringPool & getStringPool()
Definition: LVSupport.cpp:25
std::set< LVSymbolKind > LVSymbolKindSet
Definition: LVSymbol.h:33
bool(LVLocation::*)() LVValidLocation
Definition: LVObject.h:101
std::map< LVSymbolKind, LVSymbolGetFunction > LVSymbolDispatch
Definition: LVSymbol.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18