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 167