LLVM 24.0.0git
SDNodeDbgValue.h
Go to the documentation of this file.
1//===-- llvm/CodeGen/SDNodeDbgValue.h - SelectionDAG dbg_value --*- 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 declares the SDDbgValue class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_SDNODEDBGVALUE_H
14#define LLVM_LIB_CODEGEN_SELECTIONDAG_SDNODEDBGVALUE_H
15
17#include "llvm/IR/DebugLoc.h"
20#include <utility>
21
22namespace llvm {
23
24class DIVariable;
25class DIExpression;
26class GlobalValue;
27class SDNode;
28class Value;
29class raw_ostream;
30
31/// Holds the information for a single machine location through SDISel; either
32/// an SDNode, a constant, a stack location, a virtual register, or the address
33/// of a global.
34class SDDbgOperand {
35public:
36 enum Kind {
37 SDNODE = 0, ///< Value is the result of an expression.
38 CONST = 1, ///< Value is a constant.
39 FRAMEIX = 2, ///< Value is contents of a stack location.
40 VREG = 3, ///< Value is a virtual register.
41 GLOBALADDR = 4 ///< Value is the address of a global.
42 };
43 Kind getKind() const { return kind; }
44
45 /// Returns the SDNode* for a register ref
46 SDNode *getSDNode() const {
47 assert(kind == SDNODE);
48 return u.s.Node;
49 }
50
51 /// Returns the ResNo for a register ref
52 unsigned getResNo() const {
53 assert(kind == SDNODE);
54 return u.s.ResNo;
55 }
56
57 /// Returns the Value* for a constant
58 const Value *getConst() const {
59 assert(kind == CONST);
60 return u.Const;
61 }
62
63 /// Returns the FrameIx for a stack object
64 unsigned getFrameIx() const {
65 assert(kind == FRAMEIX);
66 return u.FrameIx;
67 }
68
69 /// Returns the Virtual Register for a VReg
70 Register getVReg() const {
71 assert(kind == VREG);
72 return u.VReg;
73 }
74
75 /// Returns the GlobalValue whose address describes the variable.
76 const GlobalValue *getGlobal() const {
77 assert(kind == GLOBALADDR);
78 return u.GA;
79 }
80
81 static SDDbgOperand fromNode(SDNode *Node, unsigned ResNo) {
82 return SDDbgOperand(Node, ResNo);
83 }
84 static SDDbgOperand fromFrameIdx(unsigned FrameIdx) {
85 return SDDbgOperand(FrameIdx, FRAMEIX);
86 }
87 static SDDbgOperand fromVReg(Register VReg) {
88 return SDDbgOperand(VReg.id(), VREG);
89 }
90 static SDDbgOperand fromConst(const Value *Const) {
91 return SDDbgOperand(Const);
92 }
93 static SDDbgOperand fromGlobalAddr(const GlobalValue *GV) {
94 return SDDbgOperand(GV, GLOBALADDR);
95 }
96
97 bool operator!=(const SDDbgOperand &Other) const { return !(*this == Other); }
98 bool operator==(const SDDbgOperand &Other) const {
99 if (kind != Other.kind)
100 return false;
101 switch (kind) {
102 case SDNODE:
103 return getSDNode() == Other.getSDNode() && getResNo() == Other.getResNo();
104 case CONST:
105 return getConst() == Other.getConst();
106 case VREG:
107 return getVReg() == Other.getVReg();
108 case FRAMEIX:
109 return getFrameIx() == Other.getFrameIx();
110 case GLOBALADDR:
111 return getGlobal() == Other.getGlobal();
112 }
113 return false;
114 }
115
116private:
117 Kind kind;
118 union {
119 struct {
120 SDNode *Node; ///< Valid for expressions.
121 unsigned ResNo; ///< Valid for expressions.
122 } s;
123 const Value *Const; ///< Valid for constants.
124 unsigned FrameIx; ///< Valid for stack objects.
125 unsigned VReg; ///< Valid for registers.
126 const GlobalValue *GA; ///< Valid for global addresses.
127 } u;
128
129 /// Constructor for non-constants.
130 SDDbgOperand(SDNode *N, unsigned R) : kind(SDNODE) {
131 u.s.Node = N;
132 u.s.ResNo = R;
133 }
134 /// Constructor for constants.
135 SDDbgOperand(const Value *C) : kind(CONST) { u.Const = C; }
136 /// Constructor for global addresses. Takes an explicit Kind because a
137 /// GlobalValue would otherwise be ambiguous with the Value constructor.
138 SDDbgOperand(const GlobalValue *GV, Kind Kind) : kind(Kind) {
139 assert(Kind == GLOBALADDR && "Invalid SDDbgValue constructor");
140 u.GA = GV;
141 }
142 /// Constructor for virtual registers and frame indices.
143 SDDbgOperand(unsigned VRegOrFrameIdx, Kind Kind) : kind(Kind) {
144 assert((Kind == VREG || Kind == FRAMEIX) &&
145 "Invalid SDDbgValue constructor");
146 if (kind == VREG)
147 u.VReg = VRegOrFrameIdx;
148 else
149 u.FrameIx = VRegOrFrameIdx;
150 }
151};
152
153/// Holds the information from a dbg_value node through SDISel.
154/// We do not use SDValue here to avoid including its header.
156public:
157
158private:
159 // SDDbgValues are allocated by a BumpPtrAllocator, which means the destructor
160 // may not be called; therefore all member arrays must also be allocated by
161 // that BumpPtrAllocator, to ensure that they are correctly freed.
162 size_t NumLocationOps;
163 SDDbgOperand *LocationOps;
164 // SDNode dependencies will be calculated as SDNodes that appear in
165 // LocationOps plus these AdditionalDependencies.
166 size_t NumAdditionalDependencies;
167 SDNode **AdditionalDependencies;
168 DIVariable *Var;
169 DIExpression *Expr;
170 DebugLoc DL;
171 unsigned Order;
172 bool IsIndirect;
173 bool IsVariadic;
174 bool Invalid = false;
175 bool Emitted = false;
176
177public:
180 bool IsIndirect, DebugLoc DL, unsigned O, bool IsVariadic)
181 : NumLocationOps(L.size()),
182 LocationOps(Alloc.Allocate<SDDbgOperand>(L.size())),
183 NumAdditionalDependencies(Dependencies.size()),
184 AdditionalDependencies(Alloc.Allocate<SDNode *>(Dependencies.size())),
185 Var(Var), Expr(Expr), DL(DL), Order(O), IsIndirect(IsIndirect),
186 IsVariadic(IsVariadic) {
187 assert(IsVariadic || L.size() == 1);
188 assert(!(IsVariadic && IsIndirect));
189 llvm::copy(L, LocationOps);
190 llvm::copy(Dependencies, AdditionalDependencies);
191 }
192
193 // We allocate arrays with the BumpPtrAllocator and never free or copy them,
194 // for LocationOps and AdditionalDependencies, as we never expect to copy or
195 // destroy an SDDbgValue. If we ever start copying or destroying instances, we
196 // should manage the allocated memory appropriately.
197 SDDbgValue(const SDDbgValue &Other) = delete;
199 ~SDDbgValue() = delete;
200
201 /// Returns the DIVariable pointer for the variable.
202 DIVariable *getVariable() const { return Var; }
203
204 /// Returns the DIExpression pointer for the expression.
205 DIExpression *getExpression() const { return Expr; }
206
208 return ArrayRef<SDDbgOperand>(LocationOps, NumLocationOps);
209 }
210
212 return SmallVector<SDDbgOperand>(LocationOps, LocationOps + NumLocationOps);
213 }
214
215 // Returns the SDNodes which this SDDbgValue depends on.
217 SmallVector<SDNode *> Dependencies;
218 for (const SDDbgOperand &DbgOp : getLocationOps())
219 if (DbgOp.getKind() == SDDbgOperand::SDNODE)
220 Dependencies.push_back(DbgOp.getSDNode());
222 return Dependencies;
223 }
224
226 return ArrayRef<SDNode *>(AdditionalDependencies,
227 NumAdditionalDependencies);
228 }
229
230 /// Returns whether this is an indirect value.
231 bool isIndirect() const { return IsIndirect; }
232
233 bool isVariadic() const { return IsVariadic; }
234
235 /// Returns the DebugLoc.
236 const DebugLoc &getDebugLoc() const { return DL; }
237
238 /// Returns the SDNodeOrder. This is the order of the preceding node in the
239 /// input.
240 unsigned getOrder() const { return Order; }
241
242 /// setIsInvalidated / isInvalidated - Setter / getter of the "Invalidated"
243 /// property. A SDDbgValue is invalid if the SDNode that produces the value is
244 /// deleted.
245 void setIsInvalidated() { Invalid = true; }
246 bool isInvalidated() const { return Invalid; }
247
248 /// setIsEmitted / isEmitted - Getter/Setter for flag indicating that this
249 /// SDDbgValue has been emitted to an MBB.
250 void setIsEmitted() { Emitted = true; }
251 bool isEmitted() const { return Emitted; }
252
253 /// clearIsEmitted - Reset Emitted flag, for certain special cases where
254 /// SDDbgValue is emitted twice. DBG_INSTR_REF depends on this behaviour.
255 void clearIsEmitted() { Emitted = false; }
256
257 LLVM_DUMP_METHOD void dump() const;
258 LLVM_DUMP_METHOD void print(raw_ostream &OS) const;
259};
260
261/// Holds the information from a dbg_label node through SDISel.
262/// We do not use SDValue here to avoid including its header.
264 MDNode *Label;
265 DebugLoc DL;
266 unsigned Order;
267
268public:
269 SDDbgLabel(MDNode *Label, DebugLoc dl, unsigned O)
270 : Label(Label), DL(std::move(dl)), Order(O) {}
271
272 /// Returns the MDNode pointer for the label.
273 MDNode *getLabel() const { return Label; }
274
275 /// Returns the DebugLoc.
276 const DebugLoc &getDebugLoc() const { return DL; }
277
278 /// Returns the SDNodeOrder. This is the order of the preceding node in the
279 /// input.
280 unsigned getOrder() const { return Order; }
281};
282
283} // end llvm namespace
284
285#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:686
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
DWARF expression.
Base class for variables.
A debug info location.
Definition DebugLoc.h:126
Metadata node.
Definition Metadata.h:1081
Wrapper class representing virtual and physical registers.
Definition Register.h:20
MDNode * getLabel() const
Returns the MDNode pointer for the label.
SDDbgLabel(MDNode *Label, DebugLoc dl, unsigned O)
unsigned getOrder() const
Returns the SDNodeOrder.
const DebugLoc & getDebugLoc() const
Returns the DebugLoc.
Holds the information for a single machine location through SDISel; either an SDNode,...
static SDDbgOperand fromNode(SDNode *Node, unsigned ResNo)
bool operator!=(const SDDbgOperand &Other) const
const GlobalValue * getGlobal() const
Returns the GlobalValue whose address describes the variable.
static SDDbgOperand fromFrameIdx(unsigned FrameIdx)
Register getVReg() const
Returns the Virtual Register for a VReg.
unsigned VReg
Valid for registers.
unsigned getResNo() const
Returns the ResNo for a register ref.
unsigned ResNo
Valid for expressions.
struct llvm::SDDbgOperand::@102256054047252322001367132133154236226360121031::@167330344224375143036156327334061363243101214203 s
static SDDbgOperand fromVReg(Register VReg)
unsigned FrameIx
Valid for stack objects.
unsigned getFrameIx() const
Returns the FrameIx for a stack object.
static SDDbgOperand fromConst(const Value *Const)
static SDDbgOperand fromGlobalAddr(const GlobalValue *GV)
SDNode * getSDNode() const
Returns the SDNode* for a register ref.
const GlobalValue * GA
Valid for global addresses.
const Value * Const
Valid for constants.
@ VREG
Value is a virtual register.
@ FRAMEIX
Value is contents of a stack location.
@ SDNODE
Value is the result of an expression.
@ CONST
Value is a constant.
@ GLOBALADDR
Value is the address of a global.
const Value * getConst() const
Returns the Value* for a constant.
bool operator==(const SDDbgOperand &Other) const
SDNode * Node
Valid for expressions.
Kind getKind() const
SDDbgValue & operator=(const SDDbgValue &Other)=delete
bool isEmitted() const
LLVM_DUMP_METHOD void print(raw_ostream &OS) const
const DebugLoc & getDebugLoc() const
Returns the DebugLoc.
SDDbgValue(const SDDbgValue &Other)=delete
~SDDbgValue()=delete
SmallVector< SDDbgOperand > copyLocationOps() const
DIVariable * getVariable() const
Returns the DIVariable pointer for the variable.
void setIsInvalidated()
setIsInvalidated / isInvalidated - Setter / getter of the "Invalidated" property.
unsigned getOrder() const
Returns the SDNodeOrder.
LLVM_DUMP_METHOD void dump() const
SDDbgValue(BumpPtrAllocator &Alloc, DIVariable *Var, DIExpression *Expr, ArrayRef< SDDbgOperand > L, ArrayRef< SDNode * > Dependencies, bool IsIndirect, DebugLoc DL, unsigned O, bool IsVariadic)
bool isInvalidated() const
ArrayRef< SDDbgOperand > getLocationOps() const
void clearIsEmitted()
clearIsEmitted - Reset Emitted flag, for certain special cases where SDDbgValue is emitted twice.
SmallVector< SDNode * > getSDNodes() const
DIExpression * getExpression() const
Returns the DIExpression pointer for the expression.
ArrayRef< SDNode * > getAdditionalDependencies() const
bool isIndirect() const
Returns whether this is an indirect value.
void setIsEmitted()
setIsEmitted / isEmitted - Getter/Setter for flag indicating that this SDDbgValue has been emitted to...
bool isVariadic() const
Represents one node in the SelectionDAG.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
LLVM Value Representation.
Definition Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition STLExtras.h:1685
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2224
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
@ Other
Any other memory.
Definition ModRef.h:68
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt copy(R &&Range, OutputIt Out)
Definition STLExtras.h:1901
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1933
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:390
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:878
#define N
TODO: Might pack better if we changed this to a Struct of Arrays, since MachineOperand is width 32,...