LLVM  16.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/Allocator.h"
18 #include "llvm/Support/DataTypes.h"
19 #include <utility>
20 
21 namespace llvm {
22 
23 class DIVariable;
24 class DIExpression;
25 class SDNode;
26 class Value;
27 class 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.
31 class SDDbgOperand {
32 public:
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  }
80  static SDDbgOperand fromConst(const Value *Const) {
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 
101 private:
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.
133 class SDDbgValue {
134 public:
135 
136 private:
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 
155 public:
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;
176  SDDbgValue &operator=(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  /// dbg.addr is emitted twice.
234  void clearIsEmitted() { Emitted = false; }
235 
236  LLVM_DUMP_METHOD void dump() const;
237  LLVM_DUMP_METHOD void print(raw_ostream &OS) 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.
242 class SDDbgLabel {
243  MDNode *Label;
244  DebugLoc DL;
245  unsigned Order;
246 
247 public:
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
llvm::SDDbgValue::getExpression
DIExpression * getExpression() const
Returns the DIExpression pointer for the expression.
Definition: SDNodeDbgValue.h:183
llvm::SDDbgValue
Holds the information from a dbg_value node through SDISel.
Definition: SDNodeDbgValue.h:133
llvm::SDDbgOperand::fromConst
static SDDbgOperand fromConst(const Value *Const)
Definition: SDNodeDbgValue.h:80
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:492
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::SDDbgOperand::operator!=
bool operator!=(const SDDbgOperand &Other) const
Definition: SDNodeDbgValue.h:84
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1199
llvm::SDDbgOperand::getResNo
unsigned getResNo() const
Returns the ResNo for a register ref.
Definition: SDNodeDbgValue.h:48
Allocator.h
llvm::SDNode
Represents one node in the SelectionDAG.
Definition: SelectionDAGNodes.h:463
LiveDebugValues::DbgOp
TODO: Might pack better if we changed this to a Struct of Arrays, since MachineOperand is width 32,...
Definition: InstrRefBasedImpl.h:276
llvm::SDDbgOperand::s
struct llvm::SDDbgOperand::@448::@449 s
llvm::SDDbgLabel::getOrder
unsigned getOrder() const
Returns the SDNodeOrder.
Definition: SDNodeDbgValue.h:259
llvm::SDDbgOperand
Holds the information for a single machine location through SDISel; either an SDNode,...
Definition: SDNodeDbgValue.h:31
llvm::DIExpression
DWARF expression.
Definition: DebugInfoMetadata.h:2596
llvm::SDDbgValue::getAdditionalDependencies
ArrayRef< SDNode * > getAdditionalDependencies() const
Definition: SDNodeDbgValue.h:204
llvm::SDDbgValue::getDebugLoc
const DebugLoc & getDebugLoc() const
Returns the DebugLoc.
Definition: SDNodeDbgValue.h:215
llvm::SDDbgOperand::Kind
Kind
Definition: SDNodeDbgValue.h:33
llvm::SDDbgOperand::getVReg
unsigned getVReg() const
Returns the Virtual Register for a VReg.
Definition: SDNodeDbgValue.h:66
llvm::SDDbgOperand::FrameIx
unsigned FrameIx
Valid for stack objects.
Definition: SDNodeDbgValue.h:109
llvm::SDDbgValue::dump
LLVM_DUMP_METHOD void dump() const
Definition: SelectionDAGDumper.cpp:892
llvm::SDDbgLabel
Holds the information from a dbg_label node through SDISel.
Definition: SDNodeDbgValue.h:242
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:210
llvm::SDDbgOperand::VREG
@ VREG
Value is a virtual register.
Definition: SDNodeDbgValue.h:37
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:194
DebugLoc.h
llvm::SDDbgValue::clearIsEmitted
void clearIsEmitted()
clearIsEmitted - Reset Emitted flag, for certain special cases where dbg.addr is emitted twice.
Definition: SDNodeDbgValue.h:234
llvm::SDDbgOperand::getConst
const Value * getConst() const
Returns the Value* for a constant.
Definition: SDNodeDbgValue.h:54
llvm::SDDbgOperand::Const
const Value * Const
Valid for constants.
Definition: SDNodeDbgValue.h:108
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:264
llvm::SDDbgOperand::ResNo
unsigned ResNo
Valid for expressions.
Definition: SDNodeDbgValue.h:106
llvm::SDDbgLabel::getLabel
MDNode * getLabel() const
Returns the MDNode pointer for the label.
Definition: SDNodeDbgValue.h:252
llvm::SDDbgOperand::VReg
unsigned VReg
Valid for registers.
Definition: SDNodeDbgValue.h:110
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:63
llvm::SDDbgOperand::getKind
Kind getKind() const
Definition: SDNodeDbgValue.h:39
llvm::SDDbgValue::isInvalidated
bool isInvalidated() const
Definition: SDNodeDbgValue.h:225
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:1836
llvm::MDNode
Metadata node.
Definition: Metadata.h:944
llvm::SDDbgValue::getOrder
unsigned getOrder() const
Returns the SDNodeOrder.
Definition: SDNodeDbgValue.h:219
llvm::SDDbgOperand::getFrameIx
unsigned getFrameIx() const
Returns the FrameIx for a stack object.
Definition: SDNodeDbgValue.h:60
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:1690
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:42
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
Node
Definition: ItaniumDemangle.h:156
llvm::DIVariable
Base class for variables.
Definition: DebugInfoMetadata.h:2530
llvm::SDDbgOperand::Node
SDNode * Node
Valid for expressions.
Definition: SDNodeDbgValue.h:105
llvm::SDDbgLabel::SDDbgLabel
SDDbgLabel(MDNode *Label, DebugLoc dl, unsigned O)
Definition: SDNodeDbgValue.h:248
llvm::SDDbgValue::isEmitted
bool isEmitted() const
Definition: SDNodeDbgValue.h:230
llvm::SDDbgValue::isVariadic
bool isVariadic() const
Definition: SDNodeDbgValue.h:212
llvm::SDDbgLabel::getDebugLoc
const DebugLoc & getDebugLoc() const
Returns the DebugLoc.
Definition: SDNodeDbgValue.h:255
llvm::SDDbgOperand::fromVReg
static SDDbgOperand fromVReg(unsigned VReg)
Definition: SDNodeDbgValue.h:77
std
Definition: BitVector.h:851
llvm::ArrayRef::begin
iterator begin() const
Definition: ArrayRef.h:152
llvm::SDDbgOperand::operator==
bool operator==(const SDDbgOperand &Other) const
Definition: SDNodeDbgValue.h:85
llvm::SDDbgOperand::fromNode
static SDDbgOperand fromNode(SDNode *Node, unsigned ResNo)
Definition: SDNodeDbgValue.h:71
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::SDDbgOperand::SDNODE
@ SDNODE
Value is the result of an expression.
Definition: SDNodeDbgValue.h:34
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:180
llvm::SDDbgValue::setIsInvalidated
void setIsInvalidated()
setIsInvalidated / isInvalidated - Setter / getter of the "Invalidated" property.
Definition: SDNodeDbgValue.h:224
llvm::SDDbgValue::getLocationOps
ArrayRef< SDDbgOperand > getLocationOps() const
Definition: SDNodeDbgValue.h:185
llvm::SDDbgValue::print
LLVM_DUMP_METHOD void print(raw_ostream &OS) const
Definition: SelectionDAGDumper.cpp:850
N
#define N
llvm::SDDbgOperand::FRAMEIX
@ FRAMEIX
Value is contents of a stack location.
Definition: SDNodeDbgValue.h:36
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:164
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:156
llvm::SDDbgOperand::CONST
@ CONST
Value is a constant.
Definition: SDNodeDbgValue.h:35
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:229
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:74
llvm::SDDbgOperand::fromFrameIdx
static SDDbgOperand fromFrameIdx(unsigned FrameIdx)
Definition: SDNodeDbgValue.h:74
llvm::SDDbgValue::copyLocationOps
SmallVector< SDDbgOperand > copyLocationOps() const
Definition: SDNodeDbgValue.h:189
llvm::ArrayRef::end
iterator end() const
Definition: ArrayRef.h:153
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1251
llvm::SDDbgValue::~SDDbgValue
~SDDbgValue()=delete