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 
20 namespace llvm {
21 
22 class MDNode;
23 class SDNode;
24 class Value;
25 
26 /// SDDbgValue - Holds the information from a dbg_value node through SDISel.
27 /// We do not use SDValue here to avoid including its header.
28 
29 class SDDbgValue {
30 public:
31   enum DbgValueKind {
32     SDNODE = 0,             // value is the result of an expression
33     CONST = 1,              // value is a constant
34     FRAMEIX = 2             // value is contents of a stack location
35   };
36 private:
37   union {
38     struct {
39       SDNode *Node;         // valid for expressions
40       unsigned ResNo;       // valid for expressions
41     } s;
42     const Value *Const;     // valid for constants
43     unsigned FrameIx;       // valid for stack objects
44   } u;
45   MDNode *Var;
46   MDNode *Expr;
47   uint64_t Offset;
48   DebugLoc DL;
49   unsigned Order;
50   enum DbgValueKind kind;
51   bool IsIndirect;
52   bool Invalid = false;
53 
54 public:
55   // Constructor for non-constants.
56   SDDbgValue(MDNode *Var, MDNode *Expr, SDNode *N, unsigned R, bool indir,
57              uint64_t off, DebugLoc dl, unsigned O)
58       : Var(Var), Expr(Expr), Offset(off), DL(dl), Order(O), IsIndirect(indir) {
59     kind = SDNODE;
60     u.s.Node = N;
61     u.s.ResNo = R;
62   }
63 
64   // Constructor for constants.
65   SDDbgValue(MDNode *Var, MDNode *Expr, const Value *C, uint64_t off,
66              DebugLoc dl, unsigned O)
67       : Var(Var), Expr(Expr), Offset(off), DL(dl), Order(O), IsIndirect(false) {
68     kind = CONST;
69     u.Const = C;
70   }
71 
72   // Constructor for frame indices.
73   SDDbgValue(MDNode *Var, MDNode *Expr, unsigned FI, uint64_t off, DebugLoc dl,
74              unsigned O)
75       : Var(Var), Expr(Expr), Offset(off), DL(dl), Order(O), IsIndirect(false) {
76     kind = FRAMEIX;
77     u.FrameIx = FI;
78   }
79 
80   // Returns the kind.
81   DbgValueKind getKind() const { return kind; }
82 
83   // Returns the MDNode pointer for the variable.
84   MDNode *getVariable() const { return Var; }
85 
86   // Returns the MDNode pointer for the expression.
87   MDNode *getExpression() const { return Expr; }
88 
89   // Returns the SDNode* for a register ref
90   SDNode *getSDNode() const { assert (kind==SDNODE); return u.s.Node; }
91 
92   // Returns the ResNo for a register ref
93   unsigned getResNo() const { assert (kind==SDNODE); return u.s.ResNo; }
94 
95   // Returns the Value* for a constant
96   const Value *getConst() const { assert (kind==CONST); return u.Const; }
97 
98   // Returns the FrameIx for a stack object
99   unsigned getFrameIx() const { assert (kind==FRAMEIX); return u.FrameIx; }
100 
101   // Returns whether this is an indirect value.
102   bool isIndirect() const { return IsIndirect; }
103 
104   // Returns the offset.
105   uint64_t getOffset() const { return Offset; }
106 
107   // Returns the DebugLoc.
108   DebugLoc getDebugLoc() const { return DL; }
109 
110   // Returns the SDNodeOrder.  This is the order of the preceding node in the
111   // input.
112   unsigned getOrder() const { return Order; }
113 
114   // setIsInvalidated / isInvalidated - Setter / getter of the "Invalidated"
115   // property. A SDDbgValue is invalid if the SDNode that produces the value is
116   // deleted.
117   void setIsInvalidated() { Invalid = true; }
118   bool isInvalidated() const { return Invalid; }
119 };
120 
121 } // end llvm namespace
122 
123 #endif
124