2010-03-15 03:56:39 +08:00
|
|
|
//===-- llvm/CodeGen/SDNodeDbgValue.h - SelectionDAG dbg_value --*- C++ -*-===//
|
2010-03-06 08:03:23 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-03-06 08:03:23 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares the SDDbgValue class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_SDNODEDBGVALUE_H
|
|
|
|
#define LLVM_LIB_CODEGEN_SELECTIONDAG_SDNODEDBGVALUE_H
|
2010-03-06 08:03:23 +08:00
|
|
|
|
2014-03-05 18:30:38 +08:00
|
|
|
#include "llvm/IR/DebugLoc.h"
|
2010-11-30 02:16:10 +08:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2016-05-27 22:27:24 +08:00
|
|
|
#include <utility>
|
2010-03-06 08:03:23 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2017-08-19 02:07:00 +08:00
|
|
|
class DIVariable;
|
|
|
|
class DIExpression;
|
2010-03-06 08:03:23 +08:00
|
|
|
class SDNode;
|
|
|
|
class Value;
|
2018-09-15 01:08:02 +08:00
|
|
|
class raw_ostream;
|
2010-03-06 08:03:23 +08:00
|
|
|
|
2017-10-25 01:23:40 +08:00
|
|
|
/// Holds the information from a dbg_value node through SDISel.
|
2010-03-06 08:03:23 +08:00
|
|
|
/// We do not use SDValue here to avoid including its header.
|
2013-09-12 02:05:11 +08:00
|
|
|
class SDDbgValue {
|
2010-03-11 06:13:47 +08:00
|
|
|
public:
|
|
|
|
enum DbgValueKind {
|
2017-10-25 01:23:40 +08:00
|
|
|
SDNODE = 0, ///< Value is the result of an expression.
|
|
|
|
CONST = 1, ///< Value is a constant.
|
[SelectionDAG] Improve selection of DBG_VALUE using a PHI node result
Summary:
When building the selection DAG at ISel all PHI nodes are
selected and lowered to Machine Instruction PHI nodes before
we start to create any SDNodes. So there are no SDNodes for
values produced by the PHI nodes.
In the past when selecting a dbg.value intrinsic that uses
the value produced by a PHI node we have been handling such
dbg.value intrinsics as "dangling debug info". I.e. we have
not created a SDDbgValue node directly, because there is
no existing SDNode for the PHI result, instead we deferred
the creationg of a SDDbgValue until we found the first use
of the PHI result.
The old solution had a couple of flaws. The position of the
selected DBG_VALUE instruction would end up quite late in a
basic block, and for example not directly after the PHI node
as in the LLVM IR input. And in case there were no use at all
in the basic block the dbg.value could be dropped completely.
This patch introduces a new VREG kind of SDDbgValue nodes.
It is similar to a SDNODE kind of node, but it refers directly
to a virtual register and not a SDNode. When we do selection
for a dbg.value that is using the result of a PHI node we
can do a lookup of the virtual register directly (as it already
is determined for the PHI node) and create a SDDbgValue node
immediately instead of delaying the selection until we find a
use.
This should fix a problem with losing debug info at ISel
as seen in PR37234 (https://bugs.llvm.org/show_bug.cgi?id=37234).
It does not resolve PR37234 completely, because the debug info
is dropped later on in the BranchFolder (see D46184).
Reviewers: #debug-info, aprantl
Reviewed By: #debug-info, aprantl
Subscribers: rnk, gbedwell, aprantl, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D46129
llvm-svn: 331182
2018-04-30 22:37:39 +08:00
|
|
|
FRAMEIX = 2, ///< Value is contents of a stack location.
|
|
|
|
VREG = 3 ///< Value is a virtual register.
|
2010-03-11 06:13:47 +08:00
|
|
|
};
|
|
|
|
private:
|
|
|
|
union {
|
|
|
|
struct {
|
2017-10-25 01:23:40 +08:00
|
|
|
SDNode *Node; ///< Valid for expressions.
|
|
|
|
unsigned ResNo; ///< Valid for expressions.
|
2010-03-11 06:13:47 +08:00
|
|
|
} s;
|
2017-10-25 01:23:40 +08:00
|
|
|
const Value *Const; ///< Valid for constants.
|
|
|
|
unsigned FrameIx; ///< Valid for stack objects.
|
[SelectionDAG] Improve selection of DBG_VALUE using a PHI node result
Summary:
When building the selection DAG at ISel all PHI nodes are
selected and lowered to Machine Instruction PHI nodes before
we start to create any SDNodes. So there are no SDNodes for
values produced by the PHI nodes.
In the past when selecting a dbg.value intrinsic that uses
the value produced by a PHI node we have been handling such
dbg.value intrinsics as "dangling debug info". I.e. we have
not created a SDDbgValue node directly, because there is
no existing SDNode for the PHI result, instead we deferred
the creationg of a SDDbgValue until we found the first use
of the PHI result.
The old solution had a couple of flaws. The position of the
selected DBG_VALUE instruction would end up quite late in a
basic block, and for example not directly after the PHI node
as in the LLVM IR input. And in case there were no use at all
in the basic block the dbg.value could be dropped completely.
This patch introduces a new VREG kind of SDDbgValue nodes.
It is similar to a SDNODE kind of node, but it refers directly
to a virtual register and not a SDNode. When we do selection
for a dbg.value that is using the result of a PHI node we
can do a lookup of the virtual register directly (as it already
is determined for the PHI node) and create a SDDbgValue node
immediately instead of delaying the selection until we find a
use.
This should fix a problem with losing debug info at ISel
as seen in PR37234 (https://bugs.llvm.org/show_bug.cgi?id=37234).
It does not resolve PR37234 completely, because the debug info
is dropped later on in the BranchFolder (see D46184).
Reviewers: #debug-info, aprantl
Reviewed By: #debug-info, aprantl
Subscribers: rnk, gbedwell, aprantl, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D46129
llvm-svn: 331182
2018-04-30 22:37:39 +08:00
|
|
|
unsigned VReg; ///< Valid for registers.
|
2010-03-11 06:13:47 +08:00
|
|
|
} u;
|
2017-08-19 02:07:00 +08:00
|
|
|
DIVariable *Var;
|
|
|
|
DIExpression *Expr;
|
2010-03-06 08:03:23 +08:00
|
|
|
DebugLoc DL;
|
2010-03-08 13:39:50 +08:00
|
|
|
unsigned Order;
|
2015-05-22 13:35:53 +08:00
|
|
|
enum DbgValueKind kind;
|
|
|
|
bool IsIndirect;
|
|
|
|
bool Invalid = false;
|
2018-12-10 19:20:47 +08:00
|
|
|
bool Emitted = false;
|
2015-05-22 13:35:53 +08:00
|
|
|
|
2010-03-06 08:03:23 +08:00
|
|
|
public:
|
2017-10-25 01:23:40 +08:00
|
|
|
/// Constructor for non-constants.
|
2017-08-19 02:07:00 +08:00
|
|
|
SDDbgValue(DIVariable *Var, DIExpression *Expr, SDNode *N, unsigned R,
|
|
|
|
bool indir, DebugLoc dl, unsigned O)
|
2017-07-29 05:27:35 +08:00
|
|
|
: Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(indir) {
|
2010-03-11 07:37:24 +08:00
|
|
|
kind = SDNODE;
|
2010-03-11 06:13:47 +08:00
|
|
|
u.s.Node = N;
|
|
|
|
u.s.ResNo = R;
|
|
|
|
}
|
2010-03-06 08:03:23 +08:00
|
|
|
|
2017-10-25 01:23:40 +08:00
|
|
|
/// Constructor for constants.
|
2017-08-19 02:07:00 +08:00
|
|
|
SDDbgValue(DIVariable *Var, DIExpression *Expr, const Value *C, DebugLoc dl,
|
|
|
|
unsigned O)
|
2017-07-29 05:27:35 +08:00
|
|
|
: Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(false) {
|
2010-03-11 07:37:24 +08:00
|
|
|
kind = CONST;
|
2010-03-11 06:13:47 +08:00
|
|
|
u.Const = C;
|
|
|
|
}
|
|
|
|
|
2018-07-27 04:56:53 +08:00
|
|
|
/// Constructor for virtual registers and frame indices.
|
|
|
|
SDDbgValue(DIVariable *Var, DIExpression *Expr, unsigned VRegOrFrameIdx,
|
|
|
|
bool IsIndirect, DebugLoc DL, unsigned Order,
|
|
|
|
enum DbgValueKind Kind)
|
|
|
|
: Var(Var), Expr(Expr), DL(DL), Order(Order), IsIndirect(IsIndirect) {
|
|
|
|
assert((Kind == VREG || Kind == FRAMEIX) &&
|
|
|
|
"Invalid SDDbgValue constructor");
|
|
|
|
kind = Kind;
|
|
|
|
if (kind == VREG)
|
|
|
|
u.VReg = VRegOrFrameIdx;
|
|
|
|
else
|
|
|
|
u.FrameIx = VRegOrFrameIdx;
|
[SelectionDAG] Improve selection of DBG_VALUE using a PHI node result
Summary:
When building the selection DAG at ISel all PHI nodes are
selected and lowered to Machine Instruction PHI nodes before
we start to create any SDNodes. So there are no SDNodes for
values produced by the PHI nodes.
In the past when selecting a dbg.value intrinsic that uses
the value produced by a PHI node we have been handling such
dbg.value intrinsics as "dangling debug info". I.e. we have
not created a SDDbgValue node directly, because there is
no existing SDNode for the PHI result, instead we deferred
the creationg of a SDDbgValue until we found the first use
of the PHI result.
The old solution had a couple of flaws. The position of the
selected DBG_VALUE instruction would end up quite late in a
basic block, and for example not directly after the PHI node
as in the LLVM IR input. And in case there were no use at all
in the basic block the dbg.value could be dropped completely.
This patch introduces a new VREG kind of SDDbgValue nodes.
It is similar to a SDNODE kind of node, but it refers directly
to a virtual register and not a SDNode. When we do selection
for a dbg.value that is using the result of a PHI node we
can do a lookup of the virtual register directly (as it already
is determined for the PHI node) and create a SDDbgValue node
immediately instead of delaying the selection until we find a
use.
This should fix a problem with losing debug info at ISel
as seen in PR37234 (https://bugs.llvm.org/show_bug.cgi?id=37234).
It does not resolve PR37234 completely, because the debug info
is dropped later on in the BranchFolder (see D46184).
Reviewers: #debug-info, aprantl
Reviewed By: #debug-info, aprantl
Subscribers: rnk, gbedwell, aprantl, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D46129
llvm-svn: 331182
2018-04-30 22:37:39 +08:00
|
|
|
}
|
|
|
|
|
2017-10-25 01:23:40 +08:00
|
|
|
/// Returns the kind.
|
2014-10-14 04:43:47 +08:00
|
|
|
DbgValueKind getKind() const { return kind; }
|
2010-03-06 08:03:23 +08:00
|
|
|
|
2017-10-25 01:23:40 +08:00
|
|
|
/// Returns the DIVariable pointer for the variable.
|
2017-08-19 02:07:00 +08:00
|
|
|
DIVariable *getVariable() const { return Var; }
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
|
2017-10-25 01:23:40 +08:00
|
|
|
/// Returns the DIExpression pointer for the expression.
|
2017-08-19 02:07:00 +08:00
|
|
|
DIExpression *getExpression() const { return Expr; }
|
2010-03-06 08:03:23 +08:00
|
|
|
|
2017-10-25 01:23:40 +08:00
|
|
|
/// Returns the SDNode* for a register ref
|
2014-10-14 04:43:47 +08:00
|
|
|
SDNode *getSDNode() const { assert (kind==SDNODE); return u.s.Node; }
|
2010-03-11 06:13:47 +08:00
|
|
|
|
2017-10-25 01:23:40 +08:00
|
|
|
/// Returns the ResNo for a register ref
|
2014-10-14 04:43:47 +08:00
|
|
|
unsigned getResNo() const { assert (kind==SDNODE); return u.s.ResNo; }
|
2010-03-06 08:03:23 +08:00
|
|
|
|
2017-10-25 01:23:40 +08:00
|
|
|
/// Returns the Value* for a constant
|
2014-10-14 04:43:47 +08:00
|
|
|
const Value *getConst() const { assert (kind==CONST); return u.Const; }
|
2010-03-06 08:03:23 +08:00
|
|
|
|
2017-10-25 01:23:40 +08:00
|
|
|
/// Returns the FrameIx for a stack object
|
2014-10-14 04:43:47 +08:00
|
|
|
unsigned getFrameIx() const { assert (kind==FRAMEIX); return u.FrameIx; }
|
2010-03-06 08:03:23 +08:00
|
|
|
|
[SelectionDAG] Improve selection of DBG_VALUE using a PHI node result
Summary:
When building the selection DAG at ISel all PHI nodes are
selected and lowered to Machine Instruction PHI nodes before
we start to create any SDNodes. So there are no SDNodes for
values produced by the PHI nodes.
In the past when selecting a dbg.value intrinsic that uses
the value produced by a PHI node we have been handling such
dbg.value intrinsics as "dangling debug info". I.e. we have
not created a SDDbgValue node directly, because there is
no existing SDNode for the PHI result, instead we deferred
the creationg of a SDDbgValue until we found the first use
of the PHI result.
The old solution had a couple of flaws. The position of the
selected DBG_VALUE instruction would end up quite late in a
basic block, and for example not directly after the PHI node
as in the LLVM IR input. And in case there were no use at all
in the basic block the dbg.value could be dropped completely.
This patch introduces a new VREG kind of SDDbgValue nodes.
It is similar to a SDNODE kind of node, but it refers directly
to a virtual register and not a SDNode. When we do selection
for a dbg.value that is using the result of a PHI node we
can do a lookup of the virtual register directly (as it already
is determined for the PHI node) and create a SDDbgValue node
immediately instead of delaying the selection until we find a
use.
This should fix a problem with losing debug info at ISel
as seen in PR37234 (https://bugs.llvm.org/show_bug.cgi?id=37234).
It does not resolve PR37234 completely, because the debug info
is dropped later on in the BranchFolder (see D46184).
Reviewers: #debug-info, aprantl
Reviewed By: #debug-info, aprantl
Subscribers: rnk, gbedwell, aprantl, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D46129
llvm-svn: 331182
2018-04-30 22:37:39 +08:00
|
|
|
/// Returns the Virtual Register for a VReg
|
|
|
|
unsigned getVReg() const { assert (kind==VREG); return u.VReg; }
|
|
|
|
|
2017-10-25 01:23:40 +08:00
|
|
|
/// Returns whether this is an indirect value.
|
2014-10-14 04:43:47 +08:00
|
|
|
bool isIndirect() const { return IsIndirect; }
|
2014-04-26 04:49:25 +08:00
|
|
|
|
2017-10-25 01:23:40 +08:00
|
|
|
/// Returns the DebugLoc.
|
2014-10-14 04:43:47 +08:00
|
|
|
DebugLoc getDebugLoc() const { return DL; }
|
2010-03-08 13:39:50 +08:00
|
|
|
|
2017-10-25 01:23:40 +08:00
|
|
|
/// Returns the SDNodeOrder. This is the order of the preceding node in the
|
|
|
|
/// input.
|
2014-10-14 04:43:47 +08:00
|
|
|
unsigned getOrder() const { return Order; }
|
2010-03-25 09:38:16 +08:00
|
|
|
|
2017-10-25 01:23:40 +08:00
|
|
|
/// setIsInvalidated / isInvalidated - Setter / getter of the "Invalidated"
|
|
|
|
/// property. A SDDbgValue is invalid if the SDNode that produces the value is
|
|
|
|
/// deleted.
|
2010-03-25 09:38:16 +08:00
|
|
|
void setIsInvalidated() { Invalid = true; }
|
2014-10-14 04:43:47 +08:00
|
|
|
bool isInvalidated() const { return Invalid; }
|
2018-09-15 01:08:02 +08:00
|
|
|
|
2018-12-10 19:20:47 +08:00
|
|
|
/// setIsEmitted / isEmitted - Getter/Setter for flag indicating that this
|
|
|
|
/// SDDbgValue has been emitted to an MBB.
|
|
|
|
void setIsEmitted() { Emitted = true; }
|
|
|
|
bool isEmitted() const { return Emitted; }
|
|
|
|
|
|
|
|
/// clearIsEmitted - Reset Emitted flag, for certain special cases where
|
|
|
|
/// dbg.addr is emitted twice.
|
|
|
|
void clearIsEmitted() { Emitted = false; }
|
|
|
|
|
2019-01-19 04:06:13 +08:00
|
|
|
LLVM_DUMP_METHOD void dump() const;
|
|
|
|
LLVM_DUMP_METHOD void print(raw_ostream &OS) const;
|
2010-03-06 08:03:23 +08:00
|
|
|
};
|
|
|
|
|
2018-05-09 10:41:08 +08:00
|
|
|
/// Holds the information from a dbg_label node through SDISel.
|
|
|
|
/// We do not use SDValue here to avoid including its header.
|
|
|
|
class SDDbgLabel {
|
|
|
|
MDNode *Label;
|
|
|
|
DebugLoc DL;
|
|
|
|
unsigned Order;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SDDbgLabel(MDNode *Label, DebugLoc dl, unsigned O)
|
|
|
|
: Label(Label), DL(std::move(dl)), Order(O) {}
|
|
|
|
|
|
|
|
/// Returns the MDNode pointer for the label.
|
|
|
|
MDNode *getLabel() const { return Label; }
|
|
|
|
|
|
|
|
/// Returns the DebugLoc.
|
|
|
|
DebugLoc getDebugLoc() const { return DL; }
|
|
|
|
|
|
|
|
/// Returns the SDNodeOrder. This is the order of the preceding node in the
|
|
|
|
/// input.
|
|
|
|
unsigned getOrder() const { return Order; }
|
|
|
|
};
|
|
|
|
|
2015-06-23 17:49:53 +08:00
|
|
|
} // end llvm namespace
|
2010-03-06 08:03:23 +08:00
|
|
|
|
|
|
|
#endif
|