blob: f7566b246f323d13aa606026d04e507d03069922 [file] [log] [blame]
Evan Cheng00fd0b62010-03-14 19:56:39 +00001//===-- llvm/CodeGen/SDNodeDbgValue.h - SelectionDAG dbg_value --*- C++ -*-===//
Dale Johannesen10a77ad2010-03-06 00:03:23 +00002//
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
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_SDNODEDBGVALUE_H
15#define LLVM_LIB_CODEGEN_SELECTIONDAG_SDNODEDBGVALUE_H
Dale Johannesen10a77ad2010-03-06 00:03:23 +000016
Chandler Carruth92051402014-03-05 10:30:38 +000017#include "llvm/IR/DebugLoc.h"
Michael J. Spencer447762d2010-11-29 18:16:10 +000018#include "llvm/Support/DataTypes.h"
Benjamin Kramer82de7d32016-05-27 14:27:24 +000019#include <utility>
Dale Johannesen10a77ad2010-03-06 00:03:23 +000020
21namespace llvm {
22
Jonas Devliegheree101b072017-08-18 18:07:00 +000023class DIVariable;
24class DIExpression;
Dale Johannesen10a77ad2010-03-06 00:03:23 +000025class SDNode;
26class Value;
Adrian Prantl55b8756b2018-09-14 17:08:02 +000027class raw_ostream;
Dale Johannesen10a77ad2010-03-06 00:03:23 +000028
Adrian Prantl93a37772017-10-24 17:23:40 +000029/// Holds the information from a dbg_value node through SDISel.
Dale Johannesen10a77ad2010-03-06 00:03:23 +000030/// We do not use SDValue here to avoid including its header.
Benjamin Kramer079b96e2013-09-11 18:05:11 +000031class SDDbgValue {
Dale Johannesen49de0602010-03-10 22:13:47 +000032public:
33 enum DbgValueKind {
Adrian Prantl93a37772017-10-24 17:23:40 +000034 SDNODE = 0, ///< Value is the result of an expression.
35 CONST = 1, ///< Value is a constant.
Bjorn Petterssonabafca62018-04-30 14:37:39 +000036 FRAMEIX = 2, ///< Value is contents of a stack location.
37 VREG = 3 ///< Value is a virtual register.
Dale Johannesen49de0602010-03-10 22:13:47 +000038 };
39private:
Dale Johannesen49de0602010-03-10 22:13:47 +000040 union {
41 struct {
Adrian Prantl93a37772017-10-24 17:23:40 +000042 SDNode *Node; ///< Valid for expressions.
43 unsigned ResNo; ///< Valid for expressions.
Dale Johannesen49de0602010-03-10 22:13:47 +000044 } s;
Adrian Prantl93a37772017-10-24 17:23:40 +000045 const Value *Const; ///< Valid for constants.
46 unsigned FrameIx; ///< Valid for stack objects.
Bjorn Petterssonabafca62018-04-30 14:37:39 +000047 unsigned VReg; ///< Valid for registers.
Dale Johannesen49de0602010-03-10 22:13:47 +000048 } u;
Jonas Devliegheree101b072017-08-18 18:07:00 +000049 DIVariable *Var;
50 DIExpression *Expr;
Dale Johannesen10a77ad2010-03-06 00:03:23 +000051 DebugLoc DL;
Dale Johannesen30488c62010-03-08 05:39:50 +000052 unsigned Order;
Duncan P. N. Exon Smith1f0c1c42015-05-22 05:35:53 +000053 enum DbgValueKind kind;
54 bool IsIndirect;
55 bool Invalid = false;
Jeremy Morse045c6772018-12-10 11:20:47 +000056 bool Emitted = false;
Duncan P. N. Exon Smith1f0c1c42015-05-22 05:35:53 +000057
Dale Johannesen10a77ad2010-03-06 00:03:23 +000058public:
Adrian Prantl93a37772017-10-24 17:23:40 +000059 /// Constructor for non-constants.
Jonas Devliegheree101b072017-08-18 18:07:00 +000060 SDDbgValue(DIVariable *Var, DIExpression *Expr, SDNode *N, unsigned R,
61 bool indir, DebugLoc dl, unsigned O)
Adrian Prantla6175762017-07-28 21:27:35 +000062 : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(indir) {
Dale Johannesen29108f02010-03-10 23:37:24 +000063 kind = SDNODE;
Dale Johannesen49de0602010-03-10 22:13:47 +000064 u.s.Node = N;
65 u.s.ResNo = R;
66 }
Dale Johannesen10a77ad2010-03-06 00:03:23 +000067
Adrian Prantl93a37772017-10-24 17:23:40 +000068 /// Constructor for constants.
Jonas Devliegheree101b072017-08-18 18:07:00 +000069 SDDbgValue(DIVariable *Var, DIExpression *Expr, const Value *C, DebugLoc dl,
70 unsigned O)
Adrian Prantla6175762017-07-28 21:27:35 +000071 : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(false) {
Dale Johannesen29108f02010-03-10 23:37:24 +000072 kind = CONST;
Dale Johannesen49de0602010-03-10 22:13:47 +000073 u.Const = C;
74 }
75
Vedant Kumarb572f642018-07-26 20:56:53 +000076 /// Constructor for virtual registers and frame indices.
77 SDDbgValue(DIVariable *Var, DIExpression *Expr, unsigned VRegOrFrameIdx,
78 bool IsIndirect, DebugLoc DL, unsigned Order,
79 enum DbgValueKind Kind)
80 : Var(Var), Expr(Expr), DL(DL), Order(Order), IsIndirect(IsIndirect) {
81 assert((Kind == VREG || Kind == FRAMEIX) &&
82 "Invalid SDDbgValue constructor");
83 kind = Kind;
84 if (kind == VREG)
85 u.VReg = VRegOrFrameIdx;
86 else
87 u.FrameIx = VRegOrFrameIdx;
Bjorn Petterssonabafca62018-04-30 14:37:39 +000088 }
89
Adrian Prantl93a37772017-10-24 17:23:40 +000090 /// Returns the kind.
Adrian Prantl13c58822014-10-13 20:43:47 +000091 DbgValueKind getKind() const { return kind; }
Dale Johannesen10a77ad2010-03-06 00:03:23 +000092
Adrian Prantl93a37772017-10-24 17:23:40 +000093 /// Returns the DIVariable pointer for the variable.
Jonas Devliegheree101b072017-08-18 18:07:00 +000094 DIVariable *getVariable() const { return Var; }
Adrian Prantl87b7eb92014-10-01 18:55:02 +000095
Adrian Prantl93a37772017-10-24 17:23:40 +000096 /// Returns the DIExpression pointer for the expression.
Jonas Devliegheree101b072017-08-18 18:07:00 +000097 DIExpression *getExpression() const { return Expr; }
Dale Johannesen10a77ad2010-03-06 00:03:23 +000098
Adrian Prantl93a37772017-10-24 17:23:40 +000099 /// Returns the SDNode* for a register ref
Adrian Prantl13c58822014-10-13 20:43:47 +0000100 SDNode *getSDNode() const { assert (kind==SDNODE); return u.s.Node; }
Dale Johannesen10a77ad2010-03-06 00:03:23 +0000101
Adrian Prantl93a37772017-10-24 17:23:40 +0000102 /// Returns the ResNo for a register ref
Adrian Prantl13c58822014-10-13 20:43:47 +0000103 unsigned getResNo() const { assert (kind==SDNODE); return u.s.ResNo; }
Dale Johannesen10a77ad2010-03-06 00:03:23 +0000104
Adrian Prantl93a37772017-10-24 17:23:40 +0000105 /// Returns the Value* for a constant
Adrian Prantl13c58822014-10-13 20:43:47 +0000106 const Value *getConst() const { assert (kind==CONST); return u.Const; }
Dale Johannesen49de0602010-03-10 22:13:47 +0000107
Adrian Prantl93a37772017-10-24 17:23:40 +0000108 /// Returns the FrameIx for a stack object
Adrian Prantl13c58822014-10-13 20:43:47 +0000109 unsigned getFrameIx() const { assert (kind==FRAMEIX); return u.FrameIx; }
Dale Johannesen10a77ad2010-03-06 00:03:23 +0000110
Bjorn Petterssonabafca62018-04-30 14:37:39 +0000111 /// Returns the Virtual Register for a VReg
112 unsigned getVReg() const { assert (kind==VREG); return u.VReg; }
113
Adrian Prantl93a37772017-10-24 17:23:40 +0000114 /// Returns whether this is an indirect value.
Adrian Prantl13c58822014-10-13 20:43:47 +0000115 bool isIndirect() const { return IsIndirect; }
Adrian Prantl32da8892014-04-25 20:49:25 +0000116
Adrian Prantl93a37772017-10-24 17:23:40 +0000117 /// Returns the DebugLoc.
Adrian Prantl13c58822014-10-13 20:43:47 +0000118 DebugLoc getDebugLoc() const { return DL; }
Dale Johannesen30488c62010-03-08 05:39:50 +0000119
Adrian Prantl93a37772017-10-24 17:23:40 +0000120 /// Returns the SDNodeOrder. This is the order of the preceding node in the
121 /// input.
Adrian Prantl13c58822014-10-13 20:43:47 +0000122 unsigned getOrder() const { return Order; }
Evan Cheng563fe3c2010-03-25 01:38:16 +0000123
Adrian Prantl93a37772017-10-24 17:23:40 +0000124 /// setIsInvalidated / isInvalidated - Setter / getter of the "Invalidated"
125 /// property. A SDDbgValue is invalid if the SDNode that produces the value is
126 /// deleted.
Evan Cheng563fe3c2010-03-25 01:38:16 +0000127 void setIsInvalidated() { Invalid = true; }
Adrian Prantl13c58822014-10-13 20:43:47 +0000128 bool isInvalidated() const { return Invalid; }
Adrian Prantl55b8756b2018-09-14 17:08:02 +0000129
Jeremy Morse045c6772018-12-10 11:20:47 +0000130 /// setIsEmitted / isEmitted - Getter/Setter for flag indicating that this
131 /// SDDbgValue has been emitted to an MBB.
132 void setIsEmitted() { Emitted = true; }
133 bool isEmitted() const { return Emitted; }
134
135 /// clearIsEmitted - Reset Emitted flag, for certain special cases where
136 /// dbg.addr is emitted twice.
137 void clearIsEmitted() { Emitted = false; }
138
Adrian Prantl55b8756b2018-09-14 17:08:02 +0000139 LLVM_DUMP_METHOD void dump(raw_ostream &OS) const;
Dale Johannesen10a77ad2010-03-06 00:03:23 +0000140};
141
Shiva Chencd070cd2018-05-09 02:41:08 +0000142/// Holds the information from a dbg_label node through SDISel.
143/// We do not use SDValue here to avoid including its header.
144class SDDbgLabel {
145 MDNode *Label;
146 DebugLoc DL;
147 unsigned Order;
148
149public:
150 SDDbgLabel(MDNode *Label, DebugLoc dl, unsigned O)
151 : Label(Label), DL(std::move(dl)), Order(O) {}
152
153 /// Returns the MDNode pointer for the label.
154 MDNode *getLabel() const { return Label; }
155
156 /// Returns the DebugLoc.
157 DebugLoc getDebugLoc() const { return DL; }
158
159 /// Returns the SDNodeOrder. This is the order of the preceding node in the
160 /// input.
161 unsigned getOrder() const { return Order; }
162};
163
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000164} // end llvm namespace
Dale Johannesen10a77ad2010-03-06 00:03:23 +0000165
166#endif