blob: cf92907a8b5f97626d4efe18569cb856fd41256a [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;
27
Adrian Prantl93a37772017-10-24 17:23:40 +000028/// Holds the information from a dbg_value node through SDISel.
Dale Johannesen10a77ad2010-03-06 00:03:23 +000029/// We do not use SDValue here to avoid including its header.
Benjamin Kramer079b96e2013-09-11 18:05:11 +000030class SDDbgValue {
Dale Johannesen49de0602010-03-10 22:13:47 +000031public:
32 enum DbgValueKind {
Adrian Prantl93a37772017-10-24 17:23:40 +000033 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.
Dale Johannesen49de0602010-03-10 22:13:47 +000036 };
37private:
Dale Johannesen49de0602010-03-10 22:13:47 +000038 union {
39 struct {
Adrian Prantl93a37772017-10-24 17:23:40 +000040 SDNode *Node; ///< Valid for expressions.
41 unsigned ResNo; ///< Valid for expressions.
Dale Johannesen49de0602010-03-10 22:13:47 +000042 } s;
Adrian Prantl93a37772017-10-24 17:23:40 +000043 const Value *Const; ///< Valid for constants.
44 unsigned FrameIx; ///< Valid for stack objects.
Dale Johannesen49de0602010-03-10 22:13:47 +000045 } u;
Jonas Devliegheree101b072017-08-18 18:07:00 +000046 DIVariable *Var;
47 DIExpression *Expr;
Dale Johannesen10a77ad2010-03-06 00:03:23 +000048 DebugLoc DL;
Dale Johannesen30488c62010-03-08 05:39:50 +000049 unsigned Order;
Duncan P. N. Exon Smith1f0c1c42015-05-22 05:35:53 +000050 enum DbgValueKind kind;
51 bool IsIndirect;
52 bool Invalid = false;
53
Dale Johannesen10a77ad2010-03-06 00:03:23 +000054public:
Adrian Prantl93a37772017-10-24 17:23:40 +000055 /// Constructor for non-constants.
Jonas Devliegheree101b072017-08-18 18:07:00 +000056 SDDbgValue(DIVariable *Var, DIExpression *Expr, SDNode *N, unsigned R,
57 bool indir, DebugLoc dl, unsigned O)
Adrian Prantla6175762017-07-28 21:27:35 +000058 : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(indir) {
Dale Johannesen29108f02010-03-10 23:37:24 +000059 kind = SDNODE;
Dale Johannesen49de0602010-03-10 22:13:47 +000060 u.s.Node = N;
61 u.s.ResNo = R;
62 }
Dale Johannesen10a77ad2010-03-06 00:03:23 +000063
Adrian Prantl93a37772017-10-24 17:23:40 +000064 /// Constructor for constants.
Jonas Devliegheree101b072017-08-18 18:07:00 +000065 SDDbgValue(DIVariable *Var, DIExpression *Expr, const Value *C, DebugLoc dl,
66 unsigned O)
Adrian Prantla6175762017-07-28 21:27:35 +000067 : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(false) {
Dale Johannesen29108f02010-03-10 23:37:24 +000068 kind = CONST;
Dale Johannesen49de0602010-03-10 22:13:47 +000069 u.Const = C;
70 }
71
Adrian Prantl93a37772017-10-24 17:23:40 +000072 /// Constructor for frame indices.
Jonas Devliegheree101b072017-08-18 18:07:00 +000073 SDDbgValue(DIVariable *Var, DIExpression *Expr, unsigned FI, DebugLoc dl,
74 unsigned O)
Adrian Prantla6175762017-07-28 21:27:35 +000075 : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(false) {
Dale Johannesen29108f02010-03-10 23:37:24 +000076 kind = FRAMEIX;
Dale Johannesen49de0602010-03-10 22:13:47 +000077 u.FrameIx = FI;
78 }
79
Adrian Prantl93a37772017-10-24 17:23:40 +000080 /// Returns the kind.
Adrian Prantl13c58822014-10-13 20:43:47 +000081 DbgValueKind getKind() const { return kind; }
Dale Johannesen10a77ad2010-03-06 00:03:23 +000082
Adrian Prantl93a37772017-10-24 17:23:40 +000083 /// Returns the DIVariable pointer for the variable.
Jonas Devliegheree101b072017-08-18 18:07:00 +000084 DIVariable *getVariable() const { return Var; }
Adrian Prantl87b7eb92014-10-01 18:55:02 +000085
Adrian Prantl93a37772017-10-24 17:23:40 +000086 /// Returns the DIExpression pointer for the expression.
Jonas Devliegheree101b072017-08-18 18:07:00 +000087 DIExpression *getExpression() const { return Expr; }
Dale Johannesen10a77ad2010-03-06 00:03:23 +000088
Adrian Prantl93a37772017-10-24 17:23:40 +000089 /// Returns the SDNode* for a register ref
Adrian Prantl13c58822014-10-13 20:43:47 +000090 SDNode *getSDNode() const { assert (kind==SDNODE); return u.s.Node; }
Dale Johannesen10a77ad2010-03-06 00:03:23 +000091
Adrian Prantl93a37772017-10-24 17:23:40 +000092 /// Returns the ResNo for a register ref
Adrian Prantl13c58822014-10-13 20:43:47 +000093 unsigned getResNo() const { assert (kind==SDNODE); return u.s.ResNo; }
Dale Johannesen10a77ad2010-03-06 00:03:23 +000094
Adrian Prantl93a37772017-10-24 17:23:40 +000095 /// Returns the Value* for a constant
Adrian Prantl13c58822014-10-13 20:43:47 +000096 const Value *getConst() const { assert (kind==CONST); return u.Const; }
Dale Johannesen49de0602010-03-10 22:13:47 +000097
Adrian Prantl93a37772017-10-24 17:23:40 +000098 /// Returns the FrameIx for a stack object
Adrian Prantl13c58822014-10-13 20:43:47 +000099 unsigned getFrameIx() const { assert (kind==FRAMEIX); return u.FrameIx; }
Dale Johannesen10a77ad2010-03-06 00:03:23 +0000100
Adrian Prantl93a37772017-10-24 17:23:40 +0000101 /// Returns whether this is an indirect value.
Adrian Prantl13c58822014-10-13 20:43:47 +0000102 bool isIndirect() const { return IsIndirect; }
Adrian Prantl32da8892014-04-25 20:49:25 +0000103
Adrian Prantl93a37772017-10-24 17:23:40 +0000104 /// Returns the DebugLoc.
Adrian Prantl13c58822014-10-13 20:43:47 +0000105 DebugLoc getDebugLoc() const { return DL; }
Dale Johannesen30488c62010-03-08 05:39:50 +0000106
Adrian Prantl93a37772017-10-24 17:23:40 +0000107 /// Returns the SDNodeOrder. This is the order of the preceding node in the
108 /// input.
Adrian Prantl13c58822014-10-13 20:43:47 +0000109 unsigned getOrder() const { return Order; }
Evan Cheng563fe3c2010-03-25 01:38:16 +0000110
Adrian Prantl93a37772017-10-24 17:23:40 +0000111 /// setIsInvalidated / isInvalidated - Setter / getter of the "Invalidated"
112 /// property. A SDDbgValue is invalid if the SDNode that produces the value is
113 /// deleted.
Evan Cheng563fe3c2010-03-25 01:38:16 +0000114 void setIsInvalidated() { Invalid = true; }
Adrian Prantl13c58822014-10-13 20:43:47 +0000115 bool isInvalidated() const { return Invalid; }
Dale Johannesen10a77ad2010-03-06 00:03:23 +0000116};
117
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000118} // end llvm namespace
Dale Johannesen10a77ad2010-03-06 00:03:23 +0000119
120#endif