• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
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 
56 public:
57   /// Constructor for non-constants.
SDDbgValue(DIVariable * Var,DIExpression * Expr,SDNode * N,unsigned R,bool indir,DebugLoc dl,unsigned O)58   SDDbgValue(DIVariable *Var, DIExpression *Expr, SDNode *N, unsigned R,
59              bool indir, DebugLoc dl, unsigned O)
60       : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(indir) {
61     kind = SDNODE;
62     u.s.Node = N;
63     u.s.ResNo = R;
64   }
65 
66   /// Constructor for constants.
SDDbgValue(DIVariable * Var,DIExpression * Expr,const Value * C,DebugLoc dl,unsigned O)67   SDDbgValue(DIVariable *Var, DIExpression *Expr, const Value *C, DebugLoc dl,
68              unsigned O)
69       : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(false) {
70     kind = CONST;
71     u.Const = C;
72   }
73 
74   /// Constructor for virtual registers and frame indices.
SDDbgValue(DIVariable * Var,DIExpression * Expr,unsigned VRegOrFrameIdx,bool IsIndirect,DebugLoc DL,unsigned Order,enum DbgValueKind Kind)75   SDDbgValue(DIVariable *Var, DIExpression *Expr, unsigned VRegOrFrameIdx,
76              bool IsIndirect, DebugLoc DL, unsigned Order,
77              enum DbgValueKind Kind)
78       : Var(Var), Expr(Expr), DL(DL), Order(Order), IsIndirect(IsIndirect) {
79     assert((Kind == VREG || Kind == FRAMEIX) &&
80            "Invalid SDDbgValue constructor");
81     kind = Kind;
82     if (kind == VREG)
83       u.VReg = VRegOrFrameIdx;
84     else
85       u.FrameIx = VRegOrFrameIdx;
86   }
87 
88   /// Returns the kind.
getKind()89   DbgValueKind getKind() const { return kind; }
90 
91   /// Returns the DIVariable pointer for the variable.
getVariable()92   DIVariable *getVariable() const { return Var; }
93 
94   /// Returns the DIExpression pointer for the expression.
getExpression()95   DIExpression *getExpression() const { return Expr; }
96 
97   /// Returns the SDNode* for a register ref
getSDNode()98   SDNode *getSDNode() const { assert (kind==SDNODE); return u.s.Node; }
99 
100   /// Returns the ResNo for a register ref
getResNo()101   unsigned getResNo() const { assert (kind==SDNODE); return u.s.ResNo; }
102 
103   /// Returns the Value* for a constant
getConst()104   const Value *getConst() const { assert (kind==CONST); return u.Const; }
105 
106   /// Returns the FrameIx for a stack object
getFrameIx()107   unsigned getFrameIx() const { assert (kind==FRAMEIX); return u.FrameIx; }
108 
109   /// Returns the Virtual Register for a VReg
getVReg()110   unsigned getVReg() const { assert (kind==VREG); return u.VReg; }
111 
112   /// Returns whether this is an indirect value.
isIndirect()113   bool isIndirect() const { return IsIndirect; }
114 
115   /// Returns the DebugLoc.
getDebugLoc()116   DebugLoc getDebugLoc() const { return DL; }
117 
118   /// Returns the SDNodeOrder.  This is the order of the preceding node in the
119   /// input.
getOrder()120   unsigned getOrder() const { return Order; }
121 
122   /// setIsInvalidated / isInvalidated - Setter / getter of the "Invalidated"
123   /// property. A SDDbgValue is invalid if the SDNode that produces the value is
124   /// deleted.
setIsInvalidated()125   void setIsInvalidated() { Invalid = true; }
isInvalidated()126   bool isInvalidated() const { return Invalid; }
127 };
128 
129 /// Holds the information from a dbg_label node through SDISel.
130 /// We do not use SDValue here to avoid including its header.
131 class SDDbgLabel {
132   MDNode *Label;
133   DebugLoc DL;
134   unsigned Order;
135 
136 public:
SDDbgLabel(MDNode * Label,DebugLoc dl,unsigned O)137   SDDbgLabel(MDNode *Label, DebugLoc dl, unsigned O)
138       : Label(Label), DL(std::move(dl)), Order(O) {}
139 
140   /// Returns the MDNode pointer for the label.
getLabel()141   MDNode *getLabel() const { return Label; }
142 
143   /// Returns the DebugLoc.
getDebugLoc()144   DebugLoc getDebugLoc() const { return DL; }
145 
146   /// Returns the SDNodeOrder.  This is the order of the preceding node in the
147   /// input.
getOrder()148   unsigned getOrder() const { return Order; }
149 };
150 
151 } // end llvm namespace
152 
153 #endif
154