SDNodeDbgValue.h revision c388ace6f9012c503630eb633e3977e0fc42bb00
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_CODEGEN_SDNODEDBGVALUE_H
15#define LLVM_CODEGEN_SDNODEDBGVALUE_H
16
17#include "llvm/ADT/SmallVector.h"
18#include "llvm/Support/DebugLoc.h"
19
20namespace llvm {
21
22class MDNode;
23class SDNode;
24class 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
29class SDDbgValue {
30public:
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  };
36private:
37  enum DbgValueKind kind;
38  union {
39    struct {
40      SDNode *Node;         // valid for expressions
41      unsigned ResNo;       // valid for expressions
42    } s;
43    Value *Const;           // valid for constants
44    unsigned FrameIx;       // valid for stack objects
45  } u;
46  MDNode *mdPtr;
47  uint64_t Offset;
48  DebugLoc DL;
49  unsigned Order;
50  bool Invalid;
51public:
52  // Constructor for non-constants.
53  SDDbgValue(MDNode *mdP, SDNode *N, unsigned R, uint64_t off, DebugLoc dl,
54             unsigned O) : mdPtr(mdP), Offset(off), DL(dl), Order(O),
55                           Invalid(false) {
56    kind = SDNODE;
57    u.s.Node = N;
58    u.s.ResNo = R;
59  }
60
61  // Constructor for constants.
62  SDDbgValue(MDNode *mdP, Value *C, uint64_t off, DebugLoc dl, unsigned O) :
63    mdPtr(mdP), Offset(off), DL(dl), Order(O), Invalid(false) {
64    kind = CONST;
65    u.Const = C;
66  }
67
68  // Constructor for frame indices.
69  SDDbgValue(MDNode *mdP, unsigned FI, uint64_t off, DebugLoc dl, unsigned O) :
70    mdPtr(mdP), Offset(off), DL(dl), Order(O), Invalid(false) {
71    kind = FRAMEIX;
72    u.FrameIx = FI;
73  }
74
75  // Returns the kind.
76  DbgValueKind getKind() { return kind; }
77
78  // Returns the MDNode pointer.
79  MDNode *getMDPtr() { return mdPtr; }
80
81  // Returns the SDNode* for a register ref
82  SDNode *getSDNode() { assert (kind==SDNODE); return u.s.Node; }
83
84  // Returns the ResNo for a register ref
85  unsigned getResNo() { assert (kind==SDNODE); return u.s.ResNo; }
86
87  // Returns the Value* for a constant
88  Value *getConst() { assert (kind==CONST); return u.Const; }
89
90  // Returns the FrameIx for a stack object
91  unsigned getFrameIx() { assert (kind==FRAMEIX); return u.FrameIx; }
92
93  // Returns the offset.
94  uint64_t getOffset() { return Offset; }
95
96  // Returns the DebugLoc.
97  DebugLoc getDebugLoc() { return DL; }
98
99  // Returns the SDNodeOrder.  This is the order of the preceding node in the
100  // input.
101  unsigned getOrder() { return Order; }
102
103  // setIsInvalidated / isInvalidated - Setter / getter of the "Invalidated"
104  // property. A SDDbgValue is invalid if the SDNode that produces the value is
105  // deleted.
106  void setIsInvalidated() { Invalid = true; }
107  bool isInvalidated() { return Invalid; }
108};
109
110} // end llvm namespace
111
112#endif
113