]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h
MFV: r335802
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / CodeGen / SelectionDAG / SDNodeDbgValue.h
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   };
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   DIVariable *Var;
47   DIExpression *Expr;
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(DIVariable *Var, DIExpression *Expr, SDNode *N, unsigned R,
57              bool indir, DebugLoc dl, unsigned O)
58       : Var(Var), Expr(Expr), DL(std::move(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(DIVariable *Var, DIExpression *Expr, const Value *C, DebugLoc dl,
66              unsigned O)
67       : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(false) {
68     kind = CONST;
69     u.Const = C;
70   }
71
72   /// Constructor for frame indices.
73   SDDbgValue(DIVariable *Var, DIExpression *Expr, unsigned FI, DebugLoc dl,
74              unsigned O)
75       : Var(Var), Expr(Expr), DL(std::move(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 DIVariable pointer for the variable.
84   DIVariable *getVariable() const { return Var; }
85
86   /// Returns the DIExpression pointer for the expression.
87   DIExpression *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 DebugLoc.
105   DebugLoc getDebugLoc() const { return DL; }
106
107   /// Returns the SDNodeOrder.  This is the order of the preceding node in the
108   /// input.
109   unsigned getOrder() const { return Order; }
110
111   /// setIsInvalidated / isInvalidated - Setter / getter of the "Invalidated"
112   /// property. A SDDbgValue is invalid if the SDNode that produces the value is
113   /// deleted.
114   void setIsInvalidated() { Invalid = true; }
115   bool isInvalidated() const { return Invalid; }
116 };
117
118 } // end llvm namespace
119
120 #endif