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