LLVM  14.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"
17 #include "llvm/Support/DataTypes.h"
18 #include <utility>
19 
20 namespace llvm {
21 
22 class DIVariable;
23 class DIExpression;
24 class SDNode;
25 class Value;
26 class raw_ostream;
27 
28 /// Holds the information for a single machine location through SDISel; either
29 /// an SDNode, a constant, a stack location, or a virtual register.
30 class SDDbgOperand {
31 public:
32  enum Kind {
33  SDNODE = 0, ///< Value is the result of an expression.
34  CONST = 1, ///< Value is a constant.
35  FRAMEIX = 2, ///< Value is contents of a stack location.
36  VREG = 3 ///< Value is a virtual register.
37  };
38  Kind getKind() const { return kind; }
39 
40  /// Returns the SDNode* for a register ref
41  SDNode *getSDNode() const {
42  assert(kind == SDNODE);
43  return u.s.Node;
44  }
45 
46  /// Returns the ResNo for a register ref
47  unsigned getResNo() const {
48  assert(kind == SDNODE);
49  return u.s.ResNo;
50  }
51 
52  /// Returns the Value* for a constant
53  const Value *getConst() const {
54  assert(kind == CONST);
55  return u.Const;
56  }
57 
58  /// Returns the FrameIx for a stack object
59  unsigned getFrameIx() const {
60  assert(kind == FRAMEIX);
61  return u.FrameIx;
62  }
63 
64  /// Returns the Virtual Register for a VReg
65  unsigned getVReg() const {
66  assert(kind == VREG);
67  return u.VReg;
68  }
69 
70  static SDDbgOperand fromNode(SDNode *Node, unsigned ResNo) {
71  return SDDbgOperand(Node, ResNo);
72  }
73  static SDDbgOperand fromFrameIdx(unsigned FrameIdx) {
74  return SDDbgOperand(FrameIdx, FRAMEIX);
75  }
76  static SDDbgOperand fromVReg(unsigned VReg) {
77  return SDDbgOperand(VReg, VREG);
78  }
79  static SDDbgOperand fromConst(const Value *Const) {
80  return SDDbgOperand(Const);
81  }
82 
83  bool operator!=(const SDDbgOperand &Other) const { return !(*this == Other); }
84  bool operator==(const SDDbgOperand &Other) const {
85  if (kind != Other.kind)
86  return false;
87  switch (kind) {
88  case SDNODE:
89  return getSDNode() == Other.getSDNode() && getResNo() == Other.getResNo();
90  case CONST:
91  return getConst() == Other.getConst();
92  case VREG:
93  return getVReg() == Other.getVReg();
94  case FRAMEIX:
95  return getFrameIx() == Other.getFrameIx();
96  }
97  return false;
98  }
99 
100 private:
101  Kind kind;
102  union {
103  struct {
104  SDNode *Node; ///< Valid for expressions.
105  unsigned ResNo; ///< Valid for expressions.
106  } s;
107  const Value *Const; ///< Valid for constants.
108  unsigned FrameIx; ///< Valid for stack objects.
109  unsigned VReg; ///< Valid for registers.
110  } u;
111 
112  /// Constructor for non-constants.
113  SDDbgOperand(SDNode *N, unsigned R) : kind(SDNODE) {
114  u.s.Node = N;
115  u.s.ResNo = R;
116  }
117  /// Constructor for constants.
118  SDDbgOperand(const Value *C) : kind(CONST) { u.Const = C; }
119  /// Constructor for virtual registers and frame indices.
120  SDDbgOperand(unsigned VRegOrFrameIdx, Kind Kind) : kind(Kind) {
121  assert((Kind == VREG || Kind == FRAMEIX) &&
122  "Invalid SDDbgValue constructor");
123  if (kind == VREG)
124  u.VReg = VRegOrFrameIdx;
125  else
126  u.FrameIx = VRegOrFrameIdx;
127  }
128 };
129 
130 /// Holds the information from a dbg_value node through SDISel.
131 /// We do not use SDValue here to avoid including its header.
132 class SDDbgValue {
133 public:
134 
135 private:
136  // SDDbgValues are allocated by a BumpPtrAllocator, which means the destructor
137  // may not be called; therefore all member arrays must also be allocated by
138  // that BumpPtrAllocator, to ensure that they are correctly freed.
139  size_t NumLocationOps;
140  SDDbgOperand *LocationOps;
141  // SDNode dependencies will be calculated as SDNodes that appear in
142  // LocationOps plus these AdditionalDependencies.
143  size_t NumAdditionalDependencies;
144  SDNode **AdditionalDependencies;
145  DIVariable *Var;
146  DIExpression *Expr;
147  DebugLoc DL;
148  unsigned Order;
149  bool IsIndirect;
150  bool IsVariadic;
151  bool Invalid = false;
152  bool Emitted = false;
153 
154 public:
157  bool IsIndirect, DebugLoc DL, unsigned O, bool IsVariadic)
158  : NumLocationOps(L.size()),
159  LocationOps(Alloc.Allocate<SDDbgOperand>(L.size())),
160  NumAdditionalDependencies(Dependencies.size()),
161  AdditionalDependencies(Alloc.Allocate<SDNode *>(Dependencies.size())),
162  Var(Var), Expr(Expr), DL(DL), Order(O), IsIndirect(IsIndirect),
163  IsVariadic(IsVariadic) {
164  assert(IsVariadic || L.size() == 1);
165  assert(!(IsVariadic && IsIndirect));
166  std::copy(L.begin(), L.end(), LocationOps);
167  std::copy(Dependencies.begin(), Dependencies.end(), AdditionalDependencies);
168  }
169 
170  // We allocate arrays with the BumpPtrAllocator and never free or copy them,
171  // for LocationOps and AdditionalDependencies, as we never expect to copy or
172  // destroy an SDDbgValue. If we ever start copying or destroying instances, we
173  // should manage the allocated memory appropriately.
174  SDDbgValue(const SDDbgValue &Other) = delete;
175  SDDbgValue &operator=(const SDDbgValue &Other) = delete;
176  ~SDDbgValue() = delete;
177 
178  /// Returns the DIVariable pointer for the variable.
179  DIVariable *getVariable() const { return Var; }
180 
181  /// Returns the DIExpression pointer for the expression.
182  DIExpression *getExpression() const { return Expr; }
183 
185  return ArrayRef<SDDbgOperand>(LocationOps, NumLocationOps);
186  }
187 
189  return SmallVector<SDDbgOperand>(LocationOps, LocationOps + NumLocationOps);
190  }
191 
192  // Returns the SDNodes which this SDDbgValue depends on.
194  SmallVector<SDNode *> Dependencies;
195  for (SDDbgOperand DbgOp : getLocationOps())
196  if (DbgOp.getKind() == SDDbgOperand::SDNODE)
197  Dependencies.push_back(DbgOp.getSDNode());
199  Dependencies.push_back(Node);
200  return Dependencies;
201  }
202 
204  return ArrayRef<SDNode *>(AdditionalDependencies,
205  NumAdditionalDependencies);
206  }
207 
208  /// Returns whether this is an indirect value.
209  bool isIndirect() const { return IsIndirect; }
210 
211  bool isVariadic() const { return IsVariadic; }
212 
213  /// Returns the DebugLoc.
214  const DebugLoc &getDebugLoc() const { return DL; }
215 
216  /// Returns the SDNodeOrder. This is the order of the preceding node in the
217  /// input.
218  unsigned getOrder() const { return Order; }
219 
220  /// setIsInvalidated / isInvalidated - Setter / getter of the "Invalidated"
221  /// property. A SDDbgValue is invalid if the SDNode that produces the value is
222  /// deleted.
223  void setIsInvalidated() { Invalid = true; }
224  bool isInvalidated() const { return Invalid; }
225 
226  /// setIsEmitted / isEmitted - Getter/Setter for flag indicating that this
227  /// SDDbgValue has been emitted to an MBB.
228  void setIsEmitted() { Emitted = true; }
229  bool isEmitted() const { return Emitted; }
230 
231  /// clearIsEmitted - Reset Emitted flag, for certain special cases where
232  /// dbg.addr is emitted twice.
233  void clearIsEmitted() { Emitted = false; }
234 
235  LLVM_DUMP_METHOD void dump() const;
236  LLVM_DUMP_METHOD void print(raw_ostream &OS) const;
237 };
238 
239 /// Holds the information from a dbg_label node through SDISel.
240 /// We do not use SDValue here to avoid including its header.
241 class SDDbgLabel {
242  MDNode *Label;
243  DebugLoc DL;
244  unsigned Order;
245 
246 public:
247  SDDbgLabel(MDNode *Label, DebugLoc dl, unsigned O)
248  : Label(Label), DL(std::move(dl)), Order(O) {}
249 
250  /// Returns the MDNode pointer for the label.
251  MDNode *getLabel() const { return Label; }
252 
253  /// Returns the DebugLoc.
254  const DebugLoc &getDebugLoc() const { return DL; }
255 
256  /// Returns the SDNodeOrder. This is the order of the preceding node in the
257  /// input.
258  unsigned getOrder() const { return Order; }
259 };
260 
261 } // end llvm namespace
262 
263 #endif
llvm::SDDbgValue::getExpression
DIExpression * getExpression() const
Returns the DIExpression pointer for the expression.
Definition: SDNodeDbgValue.h:182
llvm::SDDbgValue
Holds the information from a dbg_value node through SDISel.
Definition: SDNodeDbgValue.h:132
llvm::SDDbgOperand::fromConst
static SDDbgOperand fromConst(const Value *Const)
Definition: SDNodeDbgValue.h:79
LLVM_DUMP_METHOD
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:491
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::SDDbgOperand::operator!=
bool operator!=(const SDDbgOperand &Other) const
Definition: SDNodeDbgValue.h:83
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::SDDbgOperand::s
struct llvm::SDDbgOperand::@410::@411 s
llvm::SDDbgOperand::getResNo
unsigned getResNo() const
Returns the ResNo for a register ref.
Definition: SDNodeDbgValue.h:47
llvm::SDNode
Represents one node in the SelectionDAG.
Definition: SelectionDAGNodes.h:455
llvm::SDDbgLabel::getOrder
unsigned getOrder() const
Returns the SDNodeOrder.
Definition: SDNodeDbgValue.h:258
llvm::SDDbgOperand
Holds the information for a single machine location through SDISel; either an SDNode,...
Definition: SDNodeDbgValue.h:30
llvm::DIExpression
DWARF expression.
Definition: DebugInfoMetadata.h:2557
llvm::SDDbgValue::getAdditionalDependencies
ArrayRef< SDNode * > getAdditionalDependencies() const
Definition: SDNodeDbgValue.h:203
llvm::SDDbgValue::getDebugLoc
const DebugLoc & getDebugLoc() const
Returns the DebugLoc.
Definition: SDNodeDbgValue.h:214
llvm::SDDbgOperand::Kind
Kind
Definition: SDNodeDbgValue.h:32
llvm::SDDbgOperand::getVReg
unsigned getVReg() const
Returns the Virtual Register for a VReg.
Definition: SDNodeDbgValue.h:65
llvm::SDDbgOperand::FrameIx
unsigned FrameIx
Valid for stack objects.
Definition: SDNodeDbgValue.h:108
llvm::SDDbgValue::dump
LLVM_DUMP_METHOD void dump() const
Definition: SelectionDAGDumper.cpp:880
llvm::SDDbgLabel
Holds the information from a dbg_label node through SDISel.
Definition: SDNodeDbgValue.h:241
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::SDDbgValue::isIndirect
bool isIndirect() const
Returns whether this is an indirect value.
Definition: SDNodeDbgValue.h:209
llvm::SDDbgOperand::VREG
@ VREG
Value is a virtual register.
Definition: SDNodeDbgValue.h:36
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::SDDbgValue::getSDNodes
SmallVector< SDNode * > getSDNodes() const
Definition: SDNodeDbgValue.h:193
DebugLoc.h
llvm::SDDbgValue::clearIsEmitted
void clearIsEmitted()
clearIsEmitted - Reset Emitted flag, for certain special cases where dbg.addr is emitted twice.
Definition: SDNodeDbgValue.h:233
llvm::SDDbgOperand::getConst
const Value * getConst() const
Returns the Value* for a constant.
Definition: SDNodeDbgValue.h:53
llvm::SDDbgOperand::Const
const Value * Const
Valid for constants.
Definition: SDNodeDbgValue.h:107
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:179
llvm::SDDbgOperand::ResNo
unsigned ResNo
Valid for expressions.
Definition: SDNodeDbgValue.h:105
llvm::SDDbgLabel::getLabel
MDNode * getLabel() const
Returns the MDNode pointer for the label.
Definition: SDNodeDbgValue.h:251
llvm::SDDbgOperand::VReg
unsigned VReg
Valid for registers.
Definition: SDNodeDbgValue.h:109
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
llvm::SDDbgOperand::getKind
Kind getKind() const
Definition: SDNodeDbgValue.h:38
llvm::SDDbgValue::isInvalidated
bool isInvalidated() const
Definition: SDNodeDbgValue.h:224
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
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:1605
llvm::MDNode
Metadata node.
Definition: Metadata.h:897
llvm::SDDbgValue::getOrder
unsigned getOrder() const
Returns the SDNodeOrder.
Definition: SDNodeDbgValue.h:218
llvm::SDDbgOperand::getFrameIx
unsigned getFrameIx() const
Returns the FrameIx for a stack object.
Definition: SDNodeDbgValue.h:59
llvm::size
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:1528
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::SDDbgOperand::getSDNode
SDNode * getSDNode() const
Returns the SDNode* for a register ref.
Definition: SDNodeDbgValue.h:41
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
Node
Definition: ItaniumDemangle.h:114
llvm::DIVariable
Base class for variables.
Definition: DebugInfoMetadata.h:2489
llvm::SDDbgOperand::Node
SDNode * Node
Valid for expressions.
Definition: SDNodeDbgValue.h:104
llvm::SDDbgLabel::SDDbgLabel
SDDbgLabel(MDNode *Label, DebugLoc dl, unsigned O)
Definition: SDNodeDbgValue.h:247
llvm::SDDbgValue::isEmitted
bool isEmitted() const
Definition: SDNodeDbgValue.h:229
llvm::SDDbgValue::isVariadic
bool isVariadic() const
Definition: SDNodeDbgValue.h:211
llvm::SDDbgLabel::getDebugLoc
const DebugLoc & getDebugLoc() const
Returns the DebugLoc.
Definition: SDNodeDbgValue.h:254
llvm::SDDbgOperand::fromVReg
static SDDbgOperand fromVReg(unsigned VReg)
Definition: SDNodeDbgValue.h:76
std
Definition: BitVector.h:838
llvm::ArrayRef::begin
iterator begin() const
Definition: ArrayRef.h:153
llvm::SDDbgOperand::operator==
bool operator==(const SDDbgOperand &Other) const
Definition: SDNodeDbgValue.h:84
llvm::SDDbgOperand::fromNode
static SDDbgOperand fromNode(SDNode *Node, unsigned ResNo)
Definition: SDNodeDbgValue.h:70
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::SDDbgOperand::SDNODE
@ SDNODE
Value is the result of an expression.
Definition: SDNodeDbgValue.h:33
llvm::SDDbgValue::operator=
SDDbgValue & operator=(const SDDbgValue &Other)=delete
llvm::SDDbgValue::getVariable
DIVariable * getVariable() const
Returns the DIVariable pointer for the variable.
Definition: SDNodeDbgValue.h:179
llvm::SDDbgValue::setIsInvalidated
void setIsInvalidated()
setIsInvalidated / isInvalidated - Setter / getter of the "Invalidated" property.
Definition: SDNodeDbgValue.h:223
llvm::SDDbgValue::getLocationOps
ArrayRef< SDDbgOperand > getLocationOps() const
Definition: SDNodeDbgValue.h:184
llvm::SDDbgValue::print
LLVM_DUMP_METHOD void print(raw_ostream &OS) const
Definition: SelectionDAGDumper.cpp:838
N
#define N
llvm::SDDbgOperand::FRAMEIX
@ FRAMEIX
Value is contents of a stack location.
Definition: SDNodeDbgValue.h:35
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
llvm::SDDbgValue::SDDbgValue
SDDbgValue(BumpPtrAllocator &Alloc, DIVariable *Var, DIExpression *Expr, ArrayRef< SDDbgOperand > L, ArrayRef< SDNode * > Dependencies, bool IsIndirect, DebugLoc DL, unsigned O, bool IsVariadic)
Definition: SDNodeDbgValue.h:155
llvm::SDDbgOperand::CONST
@ CONST
Value is a constant.
Definition: SDNodeDbgValue.h:34
DataTypes.h
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
llvm::SDDbgValue::setIsEmitted
void setIsEmitted()
setIsEmitted / isEmitted - Getter/Setter for flag indicating that this SDDbgValue has been emitted to...
Definition: SDNodeDbgValue.h:228
copy
we should consider alternate ways to model stack dependencies Lots of things could be done in WebAssemblyTargetTransformInfo cpp there are numerous optimization related hooks that can be overridden in WebAssemblyTargetLowering Instead of the OptimizeReturned which should consider preserving the returned attribute through to MachineInstrs and extending the MemIntrinsicResults pass to do this optimization on calls too That would also let the WebAssemblyPeephole pass clean up dead defs for such as it does for stores Consider implementing and or getMachineCombinerPatterns Find a clean way to fix the problem which leads to the Shrink Wrapping pass being run after the WebAssembly PEI pass When setting multiple variables to the same we currently get code like const It could be done with a smaller encoding like local tee $pop5 local copy
Definition: README.txt:101
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::SDDbgOperand::fromFrameIdx
static SDDbgOperand fromFrameIdx(unsigned FrameIdx)
Definition: SDNodeDbgValue.h:73
llvm::SDDbgValue::copyLocationOps
SmallVector< SDDbgOperand > copyLocationOps() const
Definition: SDNodeDbgValue.h:188
llvm::ArrayRef::end
iterator end() const
Definition: ArrayRef.h:154
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1172
llvm::SDDbgValue::~SDDbgValue
~SDDbgValue()=delete