LLVM  9.0.0svn
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 from a dbg_value node through SDISel.
29 /// We do not use SDValue here to avoid including its header.
30 class SDDbgValue {
31 public:
32  enum DbgValueKind {
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 private:
39  union {
40  struct {
41  SDNode *Node; ///< Valid for expressions.
42  unsigned ResNo; ///< Valid for expressions.
43  } s;
44  const Value *Const; ///< Valid for constants.
45  unsigned FrameIx; ///< Valid for stack objects.
46  unsigned VReg; ///< Valid for registers.
47  } u;
48  DIVariable *Var;
49  DIExpression *Expr;
50  DebugLoc DL;
51  unsigned Order;
52  enum DbgValueKind kind;
53  bool IsIndirect;
54  bool Invalid = false;
55  bool Emitted = false;
56 
57 public:
58  /// Constructor for non-constants.
59  SDDbgValue(DIVariable *Var, DIExpression *Expr, SDNode *N, unsigned R,
60  bool indir, DebugLoc dl, unsigned O)
61  : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(indir) {
62  kind = SDNODE;
63  u.s.Node = N;
64  u.s.ResNo = R;
65  }
66 
67  /// Constructor for constants.
68  SDDbgValue(DIVariable *Var, DIExpression *Expr, const Value *C, DebugLoc dl,
69  unsigned O)
70  : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(false) {
71  kind = CONST;
72  u.Const = C;
73  }
74 
75  /// Constructor for virtual registers and frame indices.
76  SDDbgValue(DIVariable *Var, DIExpression *Expr, unsigned VRegOrFrameIdx,
77  bool IsIndirect, DebugLoc DL, unsigned Order,
78  enum DbgValueKind Kind)
79  : Var(Var), Expr(Expr), DL(DL), Order(Order), IsIndirect(IsIndirect) {
80  assert((Kind == VREG || Kind == FRAMEIX) &&
81  "Invalid SDDbgValue constructor");
82  kind = Kind;
83  if (kind == VREG)
84  u.VReg = VRegOrFrameIdx;
85  else
86  u.FrameIx = VRegOrFrameIdx;
87  }
88 
89  /// Returns the kind.
90  DbgValueKind getKind() const { return kind; }
91 
92  /// Returns the DIVariable pointer for the variable.
93  DIVariable *getVariable() const { return Var; }
94 
95  /// Returns the DIExpression pointer for the expression.
96  DIExpression *getExpression() const { return Expr; }
97 
98  /// Returns the SDNode* for a register ref
99  SDNode *getSDNode() const { assert (kind==SDNODE); return u.s.Node; }
100 
101  /// Returns the ResNo for a register ref
102  unsigned getResNo() const { assert (kind==SDNODE); return u.s.ResNo; }
103 
104  /// Returns the Value* for a constant
105  const Value *getConst() const { assert (kind==CONST); return u.Const; }
106 
107  /// Returns the FrameIx for a stack object
108  unsigned getFrameIx() const { assert (kind==FRAMEIX); return u.FrameIx; }
109 
110  /// Returns the Virtual Register for a VReg
111  unsigned getVReg() const { assert (kind==VREG); return u.VReg; }
112 
113  /// Returns whether this is an indirect value.
114  bool isIndirect() const { return IsIndirect; }
115 
116  /// Returns the DebugLoc.
117  DebugLoc getDebugLoc() const { return DL; }
118 
119  /// Returns the SDNodeOrder. This is the order of the preceding node in the
120  /// input.
121  unsigned getOrder() const { return Order; }
122 
123  /// setIsInvalidated / isInvalidated - Setter / getter of the "Invalidated"
124  /// property. A SDDbgValue is invalid if the SDNode that produces the value is
125  /// deleted.
126  void setIsInvalidated() { Invalid = true; }
127  bool isInvalidated() const { return Invalid; }
128 
129  /// setIsEmitted / isEmitted - Getter/Setter for flag indicating that this
130  /// SDDbgValue has been emitted to an MBB.
131  void setIsEmitted() { Emitted = true; }
132  bool isEmitted() const { return Emitted; }
133 
134  /// clearIsEmitted - Reset Emitted flag, for certain special cases where
135  /// dbg.addr is emitted twice.
136  void clearIsEmitted() { Emitted = false; }
137 
138  LLVM_DUMP_METHOD void dump() const;
139  LLVM_DUMP_METHOD void print(raw_ostream &OS) const;
140 };
141 
142 /// Holds the information from a dbg_label node through SDISel.
143 /// We do not use SDValue here to avoid including its header.
144 class SDDbgLabel {
145  MDNode *Label;
146  DebugLoc DL;
147  unsigned Order;
148 
149 public:
150  SDDbgLabel(MDNode *Label, DebugLoc dl, unsigned O)
151  : Label(Label), DL(std::move(dl)), Order(O) {}
152 
153  /// Returns the MDNode pointer for the label.
154  MDNode *getLabel() const { return Label; }
155 
156  /// Returns the DebugLoc.
157  DebugLoc getDebugLoc() const { return DL; }
158 
159  /// Returns the SDNodeOrder. This is the order of the preceding node in the
160  /// input.
161  unsigned getOrder() const { return Order; }
162 };
163 
164 } // end llvm namespace
165 
166 #endif
bool isEmitted() const
unsigned VReg
Valid for registers.
uint64_t CallInst * C
This class represents lattice values for constants.
Definition: AllocatorList.h:23
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:473
SDNode * getSDNode() const
Returns the SDNode* for a register ref.
bool isInvalidated() const
void setIsEmitted()
setIsEmitted / isEmitted - Getter/Setter for flag indicating that this SDDbgValue has been emitted to...
const Value * getConst() const
Returns the Value* for a constant.
unsigned ResNo
Valid for expressions.
A debug info location.
Definition: DebugLoc.h:33
Metadata node.
Definition: Metadata.h:863
unsigned FrameIx
Valid for stack objects.
Value is a virtual register.
unsigned getResNo() const
Returns the ResNo for a register ref.
unsigned getVReg() const
Returns the Virtual Register for a VReg.
Definition: BitVector.h:937
unsigned getFrameIx() const
Returns the FrameIx for a stack object.
const Value * Const
Valid for constants.
Value is contents of a stack location.
DIVariable * getVariable() const
Returns the DIVariable pointer for the variable.
DbgValueKind getKind() const
Returns the kind.
Base class for variables.
SDDbgValue(DIVariable *Var, DIExpression *Expr, SDNode *N, unsigned R, bool indir, DebugLoc dl, unsigned O)
Constructor for non-constants.
DebugLoc getDebugLoc() const
Returns the DebugLoc.
SDDbgValue(DIVariable *Var, DIExpression *Expr, const Value *C, DebugLoc dl, unsigned O)
Constructor for constants.
DIExpression * getExpression() const
Returns the DIExpression pointer for the expression.
DebugLoc getDebugLoc() const
Returns the DebugLoc.
Value is a constant.
void setIsInvalidated()
setIsInvalidated / isInvalidated - Setter / getter of the "Invalidated" property. ...
Represents one node in the SelectionDAG.
DWARF expression.
LLVM_DUMP_METHOD void print(raw_ostream &OS) const
SDNode * Node
Valid for expressions.
Value is the result of an expression.
Holds the information from a dbg_label node through SDISel.
#define N
struct llvm::SDDbgValue::@361::@362 s
MDNode * getLabel() const
Returns the MDNode pointer for the label.
void clearIsEmitted()
clearIsEmitted - Reset Emitted flag, for certain special cases where dbg.addr is emitted twice...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM_DUMP_METHOD void dump() const
LLVM Value Representation.
Definition: Value.h:72
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
unsigned getOrder() const
Returns the SDNodeOrder.
SDDbgLabel(MDNode *Label, DebugLoc dl, unsigned O)
bool isIndirect() const
Returns whether this is an indirect value.
Holds the information from a dbg_value node through SDISel.
SDDbgValue(DIVariable *Var, DIExpression *Expr, unsigned VRegOrFrameIdx, bool IsIndirect, DebugLoc DL, unsigned Order, enum DbgValueKind Kind)
Constructor for virtual registers and frame indices.
unsigned getOrder() const
Returns the SDNodeOrder.