1 //===-- llvm/CodeGen/SDNodeDbgValue.h - SelectionDAG dbg_value --*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file declares the SDDbgValue class.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_SDNODEDBGVALUE_H
14 #define LLVM_LIB_CODEGEN_SELECTIONDAG_SDNODEDBGVALUE_H
16 #include "llvm/IR/DebugLoc.h"
17 #include "llvm/Support/DataTypes.h"
28 /// Holds the information from a dbg_value node through SDISel.
29 /// We do not use SDValue here to avoid including its header.
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.
41 SDNode
*Node
; ///< Valid for expressions.
42 unsigned ResNo
; ///< Valid for expressions.
44 const Value
*Const
; ///< Valid for constants.
45 unsigned FrameIx
; ///< Valid for stack objects.
46 unsigned VReg
; ///< Valid for registers.
52 enum DbgValueKind kind
;
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
) {
67 /// Constructor for constants.
68 SDDbgValue(DIVariable
*Var
, DIExpression
*Expr
, const Value
*C
, DebugLoc dl
,
70 : Var(Var
), Expr(Expr
), DL(std::move(dl
)), Order(O
), IsIndirect(false) {
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");
84 u
.VReg
= VRegOrFrameIdx
;
86 u
.FrameIx
= VRegOrFrameIdx
;
90 DbgValueKind
getKind() const { return kind
; }
92 /// Returns the DIVariable pointer for the variable.
93 DIVariable
*getVariable() const { return Var
; }
95 /// Returns the DIExpression pointer for the expression.
96 DIExpression
*getExpression() const { return Expr
; }
98 /// Returns the SDNode* for a register ref
99 SDNode
*getSDNode() const { assert (kind
==SDNODE
); return u
.s
.Node
; }
101 /// Returns the ResNo for a register ref
102 unsigned getResNo() const { assert (kind
==SDNODE
); return u
.s
.ResNo
; }
104 /// Returns the Value* for a constant
105 const Value
*getConst() const { assert (kind
==CONST
); return u
.Const
; }
107 /// Returns the FrameIx for a stack object
108 unsigned getFrameIx() const { assert (kind
==FRAMEIX
); return u
.FrameIx
; }
110 /// Returns the Virtual Register for a VReg
111 unsigned getVReg() const { assert (kind
==VREG
); return u
.VReg
; }
113 /// Returns whether this is an indirect value.
114 bool isIndirect() const { return IsIndirect
; }
116 /// Returns the DebugLoc.
117 DebugLoc
getDebugLoc() const { return DL
; }
119 /// Returns the SDNodeOrder. This is the order of the preceding node in the
121 unsigned getOrder() const { return Order
; }
123 /// setIsInvalidated / isInvalidated - Setter / getter of the "Invalidated"
124 /// property. A SDDbgValue is invalid if the SDNode that produces the value is
126 void setIsInvalidated() { Invalid
= true; }
127 bool isInvalidated() const { return Invalid
; }
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
; }
134 /// clearIsEmitted - Reset Emitted flag, for certain special cases where
135 /// dbg.addr is emitted twice.
136 void clearIsEmitted() { Emitted
= false; }
138 LLVM_DUMP_METHOD
void dump() const;
139 LLVM_DUMP_METHOD
void print(raw_ostream
&OS
) const;
142 /// Holds the information from a dbg_label node through SDISel.
143 /// We do not use SDValue here to avoid including its header.
150 SDDbgLabel(MDNode
*Label
, DebugLoc dl
, unsigned O
)
151 : Label(Label
), DL(std::move(dl
)), Order(O
) {}
153 /// Returns the MDNode pointer for the label.
154 MDNode
*getLabel() const { return Label
; }
156 /// Returns the DebugLoc.
157 DebugLoc
getDebugLoc() const { return DL
; }
159 /// Returns the SDNodeOrder. This is the order of the preceding node in the
161 unsigned getOrder() const { return Order
; }
164 } // end llvm namespace