blob: 1b7ba18afeacc04e1901a41449878c5b52addd6f [file] [log] [blame]
Dale Johannesen06a26632010-03-06 00:03:23 +00001//===-- llvm/CodeGen/SDDbgValue.h - SD dbg_value handling--------*- 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_SDDBGVALUE_H
15#define LLVM_CODEGEN_SDDBGVALUE_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/// Either Const or Node is nonzero, but not both.
28/// We do not use SDValue here to avoid including its header.
29
30class SDDbgValue {
Dale Johannesenbfdf7f32010-03-10 22:13:47 +000031public:
32 enum DbgValueKind {
33 SD = 0,
34 CNST = 1,
35 FX = 2
36 };
37private:
38 enum DbgValueKind kind;
39 union {
40 struct {
41 SDNode *Node; // valid for non-constants
42 unsigned ResNo; // valid for non-constants
43 } s;
44 Value *Const; // valid for constants
45 unsigned FrameIx; // valid for stack objects
46 } u;
Dale Johannesen06a26632010-03-06 00:03:23 +000047 MDNode *mdPtr;
48 uint64_t Offset;
49 DebugLoc DL;
Dale Johannesenfab4a252010-03-08 05:39:50 +000050 unsigned Order;
Dale Johannesen06a26632010-03-06 00:03:23 +000051public:
52 // Constructor for non-constants.
Dale Johannesenfab4a252010-03-08 05:39:50 +000053 SDDbgValue(MDNode *mdP, SDNode *N, unsigned R, uint64_t off, DebugLoc dl,
Dale Johannesenbfdf7f32010-03-10 22:13:47 +000054 unsigned O) : mdPtr(mdP), Offset(off), DL(dl), Order(O) {
55 kind = SD;
56 u.s.Node = N;
57 u.s.ResNo = R;
58 }
Dale Johannesen06a26632010-03-06 00:03:23 +000059
60 // Constructor for constants.
Dale Johannesenfab4a252010-03-08 05:39:50 +000061 SDDbgValue(MDNode *mdP, Value *C, uint64_t off, DebugLoc dl, unsigned O) :
Dale Johannesenbfdf7f32010-03-10 22:13:47 +000062 mdPtr(mdP), Offset(off), DL(dl), Order(O) {
63 kind = CNST;
64 u.Const = C;
65 }
66
67 // Constructor for frame indices.
68 SDDbgValue(MDNode *mdP, unsigned FI, uint64_t off, DebugLoc dl, unsigned O) :
69 mdPtr(mdP), Offset(off), DL(dl), Order(O) {
70 kind = FX;
71 u.FrameIx = FI;
72 }
73
74 // Returns the kind.
75 DbgValueKind getKind() { return kind; }
Dale Johannesen06a26632010-03-06 00:03:23 +000076
77 // Returns the MDNode pointer.
78 MDNode *getMDPtr() { return mdPtr; }
79
Dale Johannesenbfdf7f32010-03-10 22:13:47 +000080 // Returns the SDNode* for a register ref
81 SDNode *getSDNode() { assert (kind==SD); return u.s.Node; }
Dale Johannesen06a26632010-03-06 00:03:23 +000082
Dale Johannesenbfdf7f32010-03-10 22:13:47 +000083 // Returns the ResNo for a register ref
84 unsigned getResNo() { assert (kind==SD); return u.s.ResNo; }
Dale Johannesen06a26632010-03-06 00:03:23 +000085
Dale Johannesenbfdf7f32010-03-10 22:13:47 +000086 // Returns the Value* for a constant
87 Value *getConst() { assert (kind==CNST); return u.Const; }
88
89 // Returns the FrameIx for a stack object
90 unsigned getFrameIx() { assert (kind==FX); return u.FrameIx; }
Dale Johannesen06a26632010-03-06 00:03:23 +000091
92 // Returns the offset.
93 uint64_t getOffset() { return Offset; }
94
95 // Returns the DebugLoc.
96 DebugLoc getDebugLoc() { return DL; }
Dale Johannesenfab4a252010-03-08 05:39:50 +000097
98 // Returns the SDNodeOrder. This is the order of the preceding node in the
99 // input.
100 unsigned getOrder() { return Order; }
Dale Johannesen06a26632010-03-06 00:03:23 +0000101};
102
103} // end llvm namespace
104
105#endif