[llvm-objdump] - Remove one overload of reportError. NFCI.
[llvm-complete.git] / lib / CodeGen / SelectionDAG / SDNodeDbgValue.h
blob65b9d017fc5cdf786ad5cb67dbbce96f0bf0bcac
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.
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"
18 #include <utility>
20 namespace llvm {
22 class DIVariable;
23 class DIExpression;
24 class SDNode;
25 class Value;
26 class raw_ostream;
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.
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;
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;
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;
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;
89 /// Returns the kind.
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
120 /// input.
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
125 /// deleted.
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.
144 class SDDbgLabel {
145 MDNode *Label;
146 DebugLoc DL;
147 unsigned Order;
149 public:
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
160 /// input.
161 unsigned getOrder() const { return Order; }
164 } // end llvm namespace
166 #endif