LLVM  8.0.1
SDNodeDbgValue.h
Go to the documentation of this file.
1 //===-- llvm/CodeGen/SDNodeDbgValue.h - SelectionDAG dbg_value --*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the SDDbgValue class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_SDNODEDBGVALUE_H
15 #define LLVM_LIB_CODEGEN_SELECTIONDAG_SDNODEDBGVALUE_H
16 
17 #include "llvm/IR/DebugLoc.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 from a dbg_value node through SDISel.
30 /// We do not use SDValue here to avoid including its header.
31 class SDDbgValue {
32 public:
33  enum DbgValueKind {
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 private:
40  union {
41  struct {
42  SDNode *Node; ///< Valid for expressions.
43  unsigned ResNo; ///< Valid for expressions.
44  } s;
45  const Value *Const; ///< Valid for constants.
46  unsigned FrameIx; ///< Valid for stack objects.
47  unsigned VReg; ///< Valid for registers.
48  } u;
49  DIVariable *Var;
50  DIExpression *Expr;
51  DebugLoc DL;
52  unsigned Order;
53  enum DbgValueKind kind;
54  bool IsIndirect;
55  bool Invalid = false;
56  bool Emitted = false;
57 
58 public:
59  /// Constructor for non-constants.
60  SDDbgValue(DIVariable *Var, DIExpression *Expr, SDNode *N, unsigned R,
61  bool indir, DebugLoc dl, unsigned O)
62  : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(indir) {
63  kind = SDNODE;
64  u.s.Node = N;
65  u.s.ResNo = R;
66  }
67 
68  /// Constructor for constants.
69  SDDbgValue(DIVariable *Var, DIExpression *Expr, const Value *C, DebugLoc dl,
70  unsigned O)
71  : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(false) {
72  kind = CONST;
73  u.Const = C;
74  }
75 
76  /// Constructor for virtual registers and frame indices.
77  SDDbgValue(DIVariable *Var, DIExpression *Expr, unsigned VRegOrFrameIdx,
78  bool IsIndirect, DebugLoc DL, unsigned Order,
79  enum DbgValueKind Kind)
80  : Var(Var), Expr(Expr), DL(DL), Order(Order), IsIndirect(IsIndirect) {
81  assert((Kind == VREG || Kind == FRAMEIX) &&
82  "Invalid SDDbgValue constructor");
83  kind = Kind;
84  if (kind == VREG)
85  u.VReg = VRegOrFrameIdx;
86  else
87  u.FrameIx = VRegOrFrameIdx;
88  }
89 
90  /// Returns the kind.
91  DbgValueKind getKind() const { return kind; }
92 
93  /// Returns the DIVariable pointer for the variable.
94  DIVariable *getVariable() const { return Var; }
95 
96  /// Returns the DIExpression pointer for the expression.
97  DIExpression *getExpression() const { return Expr; }
98 
99  /// Returns the SDNode* for a register ref
100  SDNode *getSDNode() const { assert (kind==SDNODE); return u.s.Node; }
101 
102  /// Returns the ResNo for a register ref
103  unsigned getResNo() const { assert (kind==SDNODE); return u.s.ResNo; }
104 
105  /// Returns the Value* for a constant
106  const Value *getConst() const { assert (kind==CONST); return u.Const; }
107 
108  /// Returns the FrameIx for a stack object
109  unsigned getFrameIx() const { assert (kind==FRAMEIX); return u.FrameIx; }
110 
111  /// Returns the Virtual Register for a VReg
112  unsigned getVReg() const { assert (kind==VREG); return u.VReg; }
113 
114  /// Returns whether this is an indirect value.
115  bool isIndirect() const { return IsIndirect; }
116 
117  /// Returns the DebugLoc.
118  DebugLoc getDebugLoc() const { return DL; }
119 
120  /// Returns the SDNodeOrder. This is the order of the preceding node in the
121  /// input.
122  unsigned getOrder() const { return Order; }
123 
124  /// setIsInvalidated / isInvalidated - Setter / getter of the "Invalidated"
125  /// property. A SDDbgValue is invalid if the SDNode that produces the value is
126  /// deleted.
127  void setIsInvalidated() { Invalid = true; }
128  bool isInvalidated() const { return Invalid; }
129 
130  /// setIsEmitted / isEmitted - Getter/Setter for flag indicating that this
131  /// SDDbgValue has been emitted to an MBB.
132  void setIsEmitted() { Emitted = true; }
133  bool isEmitted() const { return Emitted; }
134 
135  /// clearIsEmitted - Reset Emitted flag, for certain special cases where
136  /// dbg.addr is emitted twice.
137  void clearIsEmitted() { Emitted = false; }
138 
139  LLVM_DUMP_METHOD void dump(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
struct llvm::SDDbgValue::@355::@356 s
This class represents lattice values for constants.
Definition: AllocatorList.h:24
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:34
Metadata node.
Definition: Metadata.h:864
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:938
unsigned getFrameIx() const
Returns the FrameIx for a stack object.
const Value * Const
Valid for constants.
#define LLVM_DUMP_METHOD
Definition: Compiler.h:74
Value is contents of a stack location.
LLVM_DUMP_METHOD void dump(raw_ostream &OS) const
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.
SDNode * Node
Valid for expressions.
Value is the result of an expression.
Holds the information from a dbg_label node through SDISel.
#define N
MDNode * getLabel() const
Returns the MDNode pointer for the label.
const unsigned Kind
void clearIsEmitted()
clearIsEmitted - Reset Emitted flag, for certain special cases where dbg.addr is emitted twice...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:73
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
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.