LLVM 19.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
16#include "llvm/IR/DebugLoc.h"
19#include <utility>
20
21namespace llvm {
22
23class DIVariable;
24class DIExpression;
25class SDNode;
26class Value;
27class raw_ostream;
28
29/// Holds the information for a single machine location through SDISel; either
30/// an SDNode, a constant, a stack location, or a virtual register.
32public:
33 enum Kind {
34 SDNODE = 0, ///< Value is the result of an expression.
35 CONST = 1, ///< Value is a constant.
36 FRAMEIX = 2, ///< Value is contents of a stack location.
37 VREG = 3 ///< Value is a virtual register.
38 };
39 Kind getKind() const { return kind; }
40
41 /// Returns the SDNode* for a register ref
42 SDNode *getSDNode() const {
43 assert(kind == SDNODE);
44 return u.s.Node;
45 }
46
47 /// Returns the ResNo for a register ref
48 unsigned getResNo() const {
49 assert(kind == SDNODE);
50 return u.s.ResNo;
51 }
52
53 /// Returns the Value* for a constant
54 const Value *getConst() const {
55 assert(kind == CONST);
56 return u.Const;
57 }
58
59 /// Returns the FrameIx for a stack object
60 unsigned getFrameIx() const {
61 assert(kind == FRAMEIX);
62 return u.FrameIx;
63 }
64
65 /// Returns the Virtual Register for a VReg
66 unsigned getVReg() const {
67 assert(kind == VREG);
68 return u.VReg;
69 }
70
71 static SDDbgOperand fromNode(SDNode *Node, unsigned ResNo) {
72 return SDDbgOperand(Node, ResNo);
73 }
74 static SDDbgOperand fromFrameIdx(unsigned FrameIdx) {
75 return SDDbgOperand(FrameIdx, FRAMEIX);
76 }
77 static SDDbgOperand fromVReg(unsigned VReg) {
78 return SDDbgOperand(VReg, VREG);
79 }
81 return SDDbgOperand(Const);
82 }
83
84 bool operator!=(const SDDbgOperand &Other) const { return !(*this == Other); }
85 bool operator==(const SDDbgOperand &Other) const {
86 if (kind != Other.kind)
87 return false;
88 switch (kind) {
89 case SDNODE:
90 return getSDNode() == Other.getSDNode() && getResNo() == Other.getResNo();
91 case CONST:
92 return getConst() == Other.getConst();
93 case VREG:
94 return getVReg() == Other.getVReg();
95 case FRAMEIX:
96 return getFrameIx() == Other.getFrameIx();
97 }
98 return false;
99 }
100
101private:
102 Kind kind;
103 union {
104 struct {
105 SDNode *Node; ///< Valid for expressions.
106 unsigned ResNo; ///< Valid for expressions.
107 } s;
108 const Value *Const; ///< Valid for constants.
109 unsigned FrameIx; ///< Valid for stack objects.
110 unsigned VReg; ///< Valid for registers.
111 } u;
112
113 /// Constructor for non-constants.
114 SDDbgOperand(SDNode *N, unsigned R) : kind(SDNODE) {
115 u.s.Node = N;
116 u.s.ResNo = R;
117 }
118 /// Constructor for constants.
119 SDDbgOperand(const Value *C) : kind(CONST) { u.Const = C; }
120 /// Constructor for virtual registers and frame indices.
121 SDDbgOperand(unsigned VRegOrFrameIdx, Kind Kind) : kind(Kind) {
122 assert((Kind == VREG || Kind == FRAMEIX) &&
123 "Invalid SDDbgValue constructor");
124 if (kind == VREG)
125 u.VReg = VRegOrFrameIdx;
126 else
127 u.FrameIx = VRegOrFrameIdx;
128 }
129};
130
131/// Holds the information from a dbg_value node through SDISel.
132/// We do not use SDValue here to avoid including its header.
134public:
135
136private:
137 // SDDbgValues are allocated by a BumpPtrAllocator, which means the destructor
138 // may not be called; therefore all member arrays must also be allocated by
139 // that BumpPtrAllocator, to ensure that they are correctly freed.
140 size_t NumLocationOps;
141 SDDbgOperand *LocationOps;
142 // SDNode dependencies will be calculated as SDNodes that appear in
143 // LocationOps plus these AdditionalDependencies.
144 size_t NumAdditionalDependencies;
145 SDNode **AdditionalDependencies;
146 DIVariable *Var;
147 DIExpression *Expr;
148 DebugLoc DL;
149 unsigned Order;
150 bool IsIndirect;
151 bool IsVariadic;
152 bool Invalid = false;
153 bool Emitted = false;
154
155public:
158 bool IsIndirect, DebugLoc DL, unsigned O, bool IsVariadic)
159 : NumLocationOps(L.size()),
160 LocationOps(Alloc.Allocate<SDDbgOperand>(L.size())),
161 NumAdditionalDependencies(Dependencies.size()),
162 AdditionalDependencies(Alloc.Allocate<SDNode *>(Dependencies.size())),
163 Var(Var), Expr(Expr), DL(DL), Order(O), IsIndirect(IsIndirect),
164 IsVariadic(IsVariadic) {
165 assert(IsVariadic || L.size() == 1);
166 assert(!(IsVariadic && IsIndirect));
167 std::copy(L.begin(), L.end(), LocationOps);
168 std::copy(Dependencies.begin(), Dependencies.end(), AdditionalDependencies);
169 }
170
171 // We allocate arrays with the BumpPtrAllocator and never free or copy them,
172 // for LocationOps and AdditionalDependencies, as we never expect to copy or
173 // destroy an SDDbgValue. If we ever start copying or destroying instances, we
174 // should manage the allocated memory appropriately.
175 SDDbgValue(const SDDbgValue &Other) = delete;
177 ~SDDbgValue() = delete;
178
179 /// Returns the DIVariable pointer for the variable.
180 DIVariable *getVariable() const { return Var; }
181
182 /// Returns the DIExpression pointer for the expression.
183 DIExpression *getExpression() const { return Expr; }
184
186 return ArrayRef<SDDbgOperand>(LocationOps, NumLocationOps);
187 }
188
190 return SmallVector<SDDbgOperand>(LocationOps, LocationOps + NumLocationOps);
191 }
192
193 // Returns the SDNodes which this SDDbgValue depends on.
195 SmallVector<SDNode *> Dependencies;
196 for (const SDDbgOperand &DbgOp : getLocationOps())
197 if (DbgOp.getKind() == SDDbgOperand::SDNODE)
198 Dependencies.push_back(DbgOp.getSDNode());
200 Dependencies.push_back(Node);
201 return Dependencies;
202 }
203
205 return ArrayRef<SDNode *>(AdditionalDependencies,
206 NumAdditionalDependencies);
207 }
208
209 /// Returns whether this is an indirect value.
210 bool isIndirect() const { return IsIndirect; }
211
212 bool isVariadic() const { return IsVariadic; }
213
214 /// Returns the DebugLoc.
215 const DebugLoc &getDebugLoc() const { return DL; }
216
217 /// Returns the SDNodeOrder. This is the order of the preceding node in the
218 /// input.
219 unsigned getOrder() const { return Order; }
220
221 /// setIsInvalidated / isInvalidated - Setter / getter of the "Invalidated"
222 /// property. A SDDbgValue is invalid if the SDNode that produces the value is
223 /// deleted.
224 void setIsInvalidated() { Invalid = true; }
225 bool isInvalidated() const { return Invalid; }
226
227 /// setIsEmitted / isEmitted - Getter/Setter for flag indicating that this
228 /// SDDbgValue has been emitted to an MBB.
229 void setIsEmitted() { Emitted = true; }
230 bool isEmitted() const { return Emitted; }
231
232 /// clearIsEmitted - Reset Emitted flag, for certain special cases where
233 /// SDDbgValue is emitted twice. DBG_INSTR_REF depends on this behaviour.
234 void clearIsEmitted() { Emitted = false; }
235
236 LLVM_DUMP_METHOD void dump() const;
238};
239
240/// Holds the information from a dbg_label node through SDISel.
241/// We do not use SDValue here to avoid including its header.
243 MDNode *Label;
244 DebugLoc DL;
245 unsigned Order;
246
247public:
248 SDDbgLabel(MDNode *Label, DebugLoc dl, unsigned O)
249 : Label(Label), DL(std::move(dl)), Order(O) {}
250
251 /// Returns the MDNode pointer for the label.
252 MDNode *getLabel() const { return Label; }
253
254 /// Returns the DebugLoc.
255 const DebugLoc &getDebugLoc() const { return DL; }
256
257 /// Returns the SDNodeOrder. This is the order of the preceding node in the
258 /// input.
259 unsigned getOrder() const { return Order; }
260};
261
262} // end llvm namespace
263
264#endif
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the BumpPtrAllocator interface.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:529
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
iterator end() const
Definition: ArrayRef.h:154
iterator begin() const
Definition: ArrayRef.h:153
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
DWARF expression.
Base class for variables.
A debug info location.
Definition: DebugLoc.h:33
Metadata node.
Definition: Metadata.h:1067
Holds the information from a dbg_label node through SDISel.
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,...
struct llvm::SDDbgOperand::@460::@461 s
static SDDbgOperand fromNode(SDNode *Node, unsigned ResNo)
bool operator!=(const SDDbgOperand &Other) const
static SDDbgOperand fromFrameIdx(unsigned FrameIdx)
unsigned VReg
Valid for registers.
unsigned getResNo() const
Returns the ResNo for a register ref.
unsigned getVReg() const
Returns the Virtual Register for a VReg.
unsigned ResNo
Valid for expressions.
static SDDbgOperand fromVReg(unsigned VReg)
unsigned FrameIx
Valid for stack objects.
unsigned getFrameIx() const
Returns the FrameIx for a stack object.
static SDDbgOperand fromConst(const Value *Const)
SDNode * getSDNode() const
Returns the SDNode* for a register ref.
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.
const Value * getConst() const
Returns the Value* for a constant.
bool operator==(const SDDbgOperand &Other) const
SDNode * Node
Valid for expressions.
Kind getKind() const
Holds the information from a dbg_value node through SDISel.
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)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
LLVM Value Representation.
Definition: Value.h:74
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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:1689
@ Other
Any other memory.
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:1858
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
#define N
TODO: Might pack better if we changed this to a Struct of Arrays, since MachineOperand is width 32,...