Line data Source code
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 :
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 51798 : : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(indir) {
62 51798 : kind = SDNODE;
63 51798 : u.s.Node = N;
64 51798 : 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 25834 : : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(false) {
71 25834 : kind = CONST;
72 25834 : 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 27347 : : Var(Var), Expr(Expr), DL(DL), Order(Order), IsIndirect(IsIndirect) {
80 : assert((Kind == VREG || Kind == FRAMEIX) &&
81 : "Invalid SDDbgValue constructor");
82 27347 : kind = Kind;
83 : if (kind == VREG)
84 10696 : u.VReg = VRegOrFrameIdx;
85 : else
86 16651 : u.FrameIx = VRegOrFrameIdx;
87 : }
88 :
89 : /// Returns the kind.
90 0 : DbgValueKind getKind() const { return kind; }
91 :
92 : /// Returns the DIVariable pointer for the variable.
93 0 : DIVariable *getVariable() const { return Var; }
94 :
95 : /// Returns the DIExpression pointer for the expression.
96 0 : DIExpression *getExpression() const { return Expr; }
97 :
98 : /// Returns the SDNode* for a register ref
99 0 : SDNode *getSDNode() const { assert (kind==SDNODE); return u.s.Node; }
100 :
101 : /// Returns the ResNo for a register ref
102 0 : unsigned getResNo() const { assert (kind==SDNODE); return u.s.ResNo; }
103 :
104 : /// Returns the Value* for a constant
105 0 : const Value *getConst() const { assert (kind==CONST); return u.Const; }
106 :
107 : /// Returns the FrameIx for a stack object
108 0 : unsigned getFrameIx() const { assert (kind==FRAMEIX); return u.FrameIx; }
109 :
110 : /// Returns the Virtual Register for a VReg
111 0 : unsigned getVReg() const { assert (kind==VREG); return u.VReg; }
112 :
113 : /// Returns whether this is an indirect value.
114 0 : 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 0 : 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 114255 : void setIsInvalidated() { Invalid = true; }
127 0 : bool isInvalidated() const { return Invalid; }
128 :
129 : LLVM_DUMP_METHOD void dump(raw_ostream &OS) const;
130 : };
131 :
132 : /// Holds the information from a dbg_label node through SDISel.
133 : /// We do not use SDValue here to avoid including its header.
134 : class SDDbgLabel {
135 : MDNode *Label;
136 : DebugLoc DL;
137 : unsigned Order;
138 :
139 : public:
140 : SDDbgLabel(MDNode *Label, DebugLoc dl, unsigned O)
141 2 : : Label(Label), DL(std::move(dl)), Order(O) {}
142 :
143 : /// Returns the MDNode pointer for the label.
144 0 : MDNode *getLabel() const { return Label; }
145 :
146 : /// Returns the DebugLoc.
147 : DebugLoc getDebugLoc() const { return DL; }
148 :
149 : /// Returns the SDNodeOrder. This is the order of the preceding node in the
150 : /// input.
151 0 : unsigned getOrder() const { return Order; }
152 : };
153 :
154 : } // end llvm namespace
155 :
156 : #endif
|