LLVM 19.0.0git
LVLocation.h
Go to the documentation of this file.
1//===-- LVLocation.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 LVOperation and LVLocation classes, which are used
10// to describe variable locations.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVLOCATION_H
15#define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVLOCATION_H
16
18
19namespace llvm {
20namespace logicalview {
21
22using LVLineRange = std::pair<LVLine *, LVLine *>;
23
24// The DW_AT_data_member_location attribute is a simple member offset.
26
27class LVOperation final {
28 // To describe an operation:
29 // OpCode
30 // Operands[0]: First operand.
31 // Operands[1]: Second operand.
32 // OP_bregx, OP_bit_piece, OP_[GNU_]const_type,
33 // OP_[GNU_]deref_type, OP_[GNU_]entry_value, OP_implicit_value,
34 // OP_[GNU_]implicit_pointer, OP_[GNU_]regval_type, OP_xderef_type.
35 LVSmall Opcode = 0;
36 SmallVector<uint64_t> Operands;
37
38public:
39 LVOperation() = delete;
41 : Opcode(Opcode), Operands(Operands) {}
42 LVOperation(const LVOperation &) = delete;
43 LVOperation &operator=(const LVOperation &) = delete;
44 ~LVOperation() = default;
45
46 LVSmall getOpcode() const { return Opcode; }
47 std::string getOperandsDWARFInfo();
48 std::string getOperandsCodeViewInfo();
49
50 void print(raw_ostream &OS, bool Full = true) const;
51
52#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
53 void dump() { print(dbgs()); }
54#endif
55};
56
57class LVLocation : public LVObject {
58 enum class Property {
59 IsAddressRange,
60 IsBaseClassOffset,
61 IsBaseClassStep,
62 IsClassOffset,
63 IsFixedAddress,
64 IsLocationSimple,
65 IsGapEntry,
66 IsOperation,
67 IsOperationList,
68 IsRegister,
69 IsStackOffset,
70 IsDiscardedRange,
71 IsInvalidRange,
72 IsInvalidLower,
73 IsInvalidUpper,
76 };
77 // Typed bitvector with properties for this location.
78 LVProperties<Property> Properties;
79
80 // True if the location it is associated with a debug range.
81 bool hasAssociatedRange() const {
82 return !getIsClassOffset() && !getIsDiscardedRange();
83 }
84
85protected:
86 // Line numbers associated with locations ranges.
87 LVLine *LowerLine = nullptr;
88 LVLine *UpperLine = nullptr;
89
90 // Active range:
91 // LowPC: an offset from an applicable base address, not a PC value.
92 // HighPC: an offset from an applicable base address, or a length.
95
96 void setKind();
97
98public:
99 LVLocation() : LVObject() { setIsLocation(); }
100 LVLocation(const LVLocation &) = delete;
101 LVLocation &operator=(const LVLocation &) = delete;
102 virtual ~LVLocation() = default;
103
104 PROPERTY(Property, IsAddressRange);
105 PROPERTY(Property, IsBaseClassOffset);
106 PROPERTY(Property, IsBaseClassStep);
107 PROPERTY_1(Property, IsClassOffset, IsLocationSimple);
108 PROPERTY_1(Property, IsFixedAddress, IsLocationSimple);
109 PROPERTY(Property, IsLocationSimple);
110 PROPERTY(Property, IsGapEntry);
111 PROPERTY(Property, IsOperationList);
112 PROPERTY(Property, IsOperation);
113 PROPERTY(Property, IsRegister);
114 PROPERTY_1(Property, IsStackOffset, IsLocationSimple);
115 PROPERTY(Property, IsDiscardedRange);
116 PROPERTY(Property, IsInvalidRange);
117 PROPERTY(Property, IsInvalidLower);
118 PROPERTY(Property, IsInvalidUpper);
119 PROPERTY(Property, IsCallSite);
120
121 const char *kind() const override;
122 // Mark the locations that have only DW_OP_fbreg as stack offset based.
123 virtual void updateKind() {}
124
125 // Line numbers for locations.
126 const LVLine *getLowerLine() const { return LowerLine; }
128 const LVLine *getUpperLine() const { return UpperLine; }
130
131 // Addresses for locations.
132 LVAddress getLowerAddress() const override { return LowPC; }
134 LVAddress getUpperAddress() const override { return HighPC; }
136
137 std::string getIntervalInfo() const;
138
139 bool validateRanges();
140
141 // In order to calculate a symbol coverage (percentage), take the ranges
142 // and obtain the number of units (bytes) covered by those ranges. We can't
143 // use the line numbers, because they can be zero or invalid.
144 // We return:
145 // false: No locations or multiple locations.
146 // true: a single location.
147 static bool calculateCoverage(LVLocations *Locations, unsigned &Factor,
148 float &Percentage);
149
151 LVUnsigned SectionOffset, uint64_t LocDescOffset) {}
153
154 static void print(LVLocations *Locations, raw_ostream &OS, bool Full = true);
155 void printInterval(raw_ostream &OS, bool Full = true) const;
156 void printRaw(raw_ostream &OS, bool Full = true) const;
157 virtual void printRawExtra(raw_ostream &OS, bool Full = true) const {}
158
159 void print(raw_ostream &OS, bool Full = true) const override;
160 void printExtra(raw_ostream &OS, bool Full = true) const override;
161
162#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
163 void dump() const override { print(dbgs()); }
164#endif
165};
166
167class LVLocationSymbol final : public LVLocation {
168 // Location descriptors for the active range.
169 std::unique_ptr<LVOperations> Entries;
170
171 void updateKind() override;
172
173public:
177 ~LVLocationSymbol() = default;
178
179 void addObject(LVAddress LowPC, LVAddress HighPC, LVUnsigned SectionOffset,
180 uint64_t LocDescOffset) override;
182
183 void printRawExtra(raw_ostream &OS, bool Full = true) const override;
184 void printExtra(raw_ostream &OS, bool Full = true) const override;
185};
186
187} // end namespace logicalview
188} // end namespace llvm
189
190#endif // LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVLOCATION_H
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 a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition: LVLocation.cpp:651
LVLocationSymbol(const LVLocationSymbol &)=delete
void printRawExtra(raw_ostream &OS, bool Full=true) const override
Definition: LVLocation.cpp:614
LVLocationSymbol & operator=(const LVLocationSymbol &)=delete
void addObject(LVAddress LowPC, LVAddress HighPC, LVUnsigned SectionOffset, uint64_t LocDescOffset) override
Definition: LVLocation.cpp:561
PROPERTY(Property, IsDiscardedRange)
const char * kind() const override
Definition: LVLocation.cpp:410
static bool calculateCoverage(LVLocations *Locations, unsigned &Factor, float &Percentage)
Definition: LVLocation.cpp:496
PROPERTY(Property, IsBaseClassStep)
PROPERTY(Property, IsInvalidLower)
void setUpperAddress(LVAddress Address) override
Definition: LVLocation.h:135
LVLocation(const LVLocation &)=delete
LVLocation & operator=(const LVLocation &)=delete
PROPERTY(Property, IsOperationList)
PROPERTY_1(Property, IsFixedAddress, IsLocationSimple)
const LVLine * getLowerLine() const
Definition: LVLocation.h:126
void setUpperLine(LVLine *Line)
Definition: LVLocation.h:129
PROPERTY(Property, IsInvalidRange)
PROPERTY_1(Property, IsStackOffset, IsLocationSimple)
PROPERTY(Property, IsInvalidUpper)
std::string getIntervalInfo() const
Definition: LVLocation.cpp:431
PROPERTY(Property, IsBaseClassOffset)
PROPERTY(Property, IsLocationSimple)
virtual void addObject(LVAddress LowPC, LVAddress HighPC, LVUnsigned SectionOffset, uint64_t LocDescOffset)
Definition: LVLocation.h:150
PROPERTY(Property, IsAddressRange)
PROPERTY_1(Property, IsClassOffset, IsLocationSimple)
virtual void printRawExtra(raw_ostream &OS, bool Full=true) const
Definition: LVLocation.h:157
void printRaw(raw_ostream &OS, bool Full=true) const
Definition: LVLocation.cpp:532
PROPERTY(Property, IsOperation)
LVAddress getLowerAddress() const override
Definition: LVLocation.h:132
PROPERTY(Property, IsRegister)
virtual void addObject(LVSmall Opcode, ArrayRef< LVUnsigned > Operands)
Definition: LVLocation.h:152
void dump() const override
Definition: LVLocation.h:163
const LVLine * getUpperLine() const
Definition: LVLocation.h:128
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition: LVLocation.cpp:552
PROPERTY(Property, IsGapEntry)
PROPERTY(Property, IsCallSite)
static void print(LVLocations *Locations, raw_ostream &OS, bool Full=true)
Definition: LVLocation.cpp:621
void setLowerLine(LVLine *Line)
Definition: LVLocation.h:127
LVAddress getUpperAddress() const override
Definition: LVLocation.h:134
void printInterval(raw_ostream &OS, bool Full=true) const
Definition: LVLocation.cpp:540
virtual ~LVLocation()=default
void setLowerAddress(LVAddress Address) override
Definition: LVLocation.h:133
void print(raw_ostream &OS, bool Full=true) const
Definition: LVLocation.cpp:23
LVOperation(const LVOperation &)=delete
std::string getOperandsDWARFInfo()
Definition: LVLocation.cpp:27
LVOperation & operator=(const LVOperation &)=delete
std::string getOperandsCodeViewInfo()
Definition: LVLocation.cpp:347
LVOperation(LVSmall Opcode, ArrayRef< LVUnsigned > Operands)
Definition: LVLocation.h:40
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
std::pair< LVLine *, LVLine * > LVLineRange
Definition: LVLocation.h:22
uint8_t LVSmall
Definition: LVObject.h:42
const LVSmall LVLocationMemberOffset
Definition: LVLocation.h:25
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