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"
|
2022-03-10 05:29:31 +08:00
|
|
|
#include "llvm/Support/Allocator.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
|
|
|
|
2020-09-28 21:02:51 +08:00
|
|
|
/// Holds the information for a single machine location through SDISel; either
|
|
|
|
/// an SDNode, a constant, a stack location, or a virtual register.
|
|
|
|
class SDDbgOperand {
|
2010-03-11 06:13:47 +08:00
|
|
|
public:
|
2020-09-28 21:02:51 +08:00
|
|
|
enum Kind {
|
|
|
|
SDNODE = 0, ///< Value is the result of an expression.
|
|
|
|
CONST = 1, ///< Value is a constant.
|
|
|
|
FRAMEIX = 2, ///< Value is contents of a stack location.
|
|
|
|
VREG = 3 ///< Value is a virtual register.
|
2010-03-11 06:13:47 +08:00
|
|
|
};
|
2020-09-28 21:02:51 +08:00
|
|
|
Kind getKind() const { return kind; }
|
|
|
|
|
|
|
|
/// Returns the SDNode* for a register ref
|
|
|
|
SDNode *getSDNode() const {
|
|
|
|
assert(kind == SDNODE);
|
|
|
|
return u.s.Node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the ResNo for a register ref
|
|
|
|
unsigned getResNo() const {
|
|
|
|
assert(kind == SDNODE);
|
|
|
|
return u.s.ResNo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the Value* for a constant
|
|
|
|
const Value *getConst() const {
|
|
|
|
assert(kind == CONST);
|
|
|
|
return u.Const;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the FrameIx for a stack object
|
|
|
|
unsigned getFrameIx() const {
|
|
|
|
assert(kind == FRAMEIX);
|
|
|
|
return u.FrameIx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the Virtual Register for a VReg
|
|
|
|
unsigned getVReg() const {
|
|
|
|
assert(kind == VREG);
|
|
|
|
return u.VReg;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SDDbgOperand fromNode(SDNode *Node, unsigned ResNo) {
|
|
|
|
return SDDbgOperand(Node, ResNo);
|
|
|
|
}
|
|
|
|
static SDDbgOperand fromFrameIdx(unsigned FrameIdx) {
|
|
|
|
return SDDbgOperand(FrameIdx, FRAMEIX);
|
|
|
|
}
|
|
|
|
static SDDbgOperand fromVReg(unsigned VReg) {
|
|
|
|
return SDDbgOperand(VReg, VREG);
|
|
|
|
}
|
|
|
|
static SDDbgOperand fromConst(const Value *Const) {
|
|
|
|
return SDDbgOperand(Const);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const SDDbgOperand &Other) const { return !(*this == Other); }
|
|
|
|
bool operator==(const SDDbgOperand &Other) const {
|
|
|
|
if (kind != Other.kind)
|
|
|
|
return false;
|
|
|
|
switch (kind) {
|
|
|
|
case SDNODE:
|
|
|
|
return getSDNode() == Other.getSDNode() && getResNo() == Other.getResNo();
|
|
|
|
case CONST:
|
|
|
|
return getConst() == Other.getConst();
|
|
|
|
case VREG:
|
|
|
|
return getVReg() == Other.getVReg();
|
|
|
|
case FRAMEIX:
|
|
|
|
return getFrameIx() == Other.getFrameIx();
|
|
|
|
}
|
2020-09-29 22:43:21 +08:00
|
|
|
return false;
|
2020-09-28 21:02:51 +08:00
|
|
|
}
|
|
|
|
|
2010-03-11 06:13:47 +08:00
|
|
|
private:
|
2020-09-28 21:02:51 +08:00
|
|
|
Kind kind;
|
2010-03-11 06:13:47 +08:00
|
|
|
union {
|
|
|
|
struct {
|
2020-09-28 21:02:51 +08:00
|
|
|
SDNode *Node; ///< Valid for expressions.
|
|
|
|
unsigned ResNo; ///< Valid for expressions.
|
2010-03-11 06:13:47 +08:00
|
|
|
} s;
|
2020-09-28 21:02:51 +08:00
|
|
|
const Value *Const; ///< Valid for constants.
|
|
|
|
unsigned FrameIx; ///< Valid for stack objects.
|
|
|
|
unsigned VReg; ///< Valid for registers.
|
2010-03-11 06:13:47 +08:00
|
|
|
} u;
|
2015-05-22 13:35:53 +08:00
|
|
|
|
2017-10-25 01:23:40 +08:00
|
|
|
/// Constructor for non-constants.
|
2020-09-28 21:02:51 +08:00
|
|
|
SDDbgOperand(SDNode *N, unsigned R) : kind(SDNODE) {
|
2010-03-11 06:13:47 +08:00
|
|
|
u.s.Node = N;
|
|
|
|
u.s.ResNo = R;
|
|
|
|
}
|
2017-10-25 01:23:40 +08:00
|
|
|
/// Constructor for constants.
|
2020-09-28 21:02:51 +08:00
|
|
|
SDDbgOperand(const Value *C) : kind(CONST) { u.Const = C; }
|
2018-07-27 04:56:53 +08:00
|
|
|
/// Constructor for virtual registers and frame indices.
|
2020-09-28 21:02:51 +08:00
|
|
|
SDDbgOperand(unsigned VRegOrFrameIdx, Kind Kind) : kind(Kind) {
|
2018-07-27 04:56:53 +08:00
|
|
|
assert((Kind == VREG || Kind == FRAMEIX) &&
|
|
|
|
"Invalid SDDbgValue constructor");
|
|
|
|
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
|
|
|
}
|
2020-09-28 21:02:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Holds the information from a dbg_value node through SDISel.
|
|
|
|
/// We do not use SDValue here to avoid including its header.
|
|
|
|
class SDDbgValue {
|
|
|
|
public:
|
|
|
|
|
|
|
|
private:
|
2021-04-09 00:56:25 +08:00
|
|
|
// SDDbgValues are allocated by a BumpPtrAllocator, which means the destructor
|
|
|
|
// may not be called; therefore all member arrays must also be allocated by
|
|
|
|
// that BumpPtrAllocator, to ensure that they are correctly freed.
|
|
|
|
size_t NumLocationOps;
|
|
|
|
SDDbgOperand *LocationOps;
|
|
|
|
// SDNode dependencies will be calculated as SDNodes that appear in
|
|
|
|
// LocationOps plus these AdditionalDependencies.
|
|
|
|
size_t NumAdditionalDependencies;
|
|
|
|
SDNode **AdditionalDependencies;
|
2020-09-28 21:02:51 +08:00
|
|
|
DIVariable *Var;
|
|
|
|
DIExpression *Expr;
|
|
|
|
DebugLoc DL;
|
|
|
|
unsigned Order;
|
|
|
|
bool IsIndirect;
|
|
|
|
bool IsVariadic;
|
|
|
|
bool Invalid = false;
|
|
|
|
bool Emitted = false;
|
[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
|
|
|
|
2020-09-28 21:02:51 +08:00
|
|
|
public:
|
2021-04-09 00:56:25 +08:00
|
|
|
SDDbgValue(BumpPtrAllocator &Alloc, DIVariable *Var, DIExpression *Expr,
|
|
|
|
ArrayRef<SDDbgOperand> L, ArrayRef<SDNode *> Dependencies,
|
|
|
|
bool IsIndirect, DebugLoc DL, unsigned O, bool IsVariadic)
|
|
|
|
: NumLocationOps(L.size()),
|
|
|
|
LocationOps(Alloc.Allocate<SDDbgOperand>(L.size())),
|
|
|
|
NumAdditionalDependencies(Dependencies.size()),
|
|
|
|
AdditionalDependencies(Alloc.Allocate<SDNode *>(Dependencies.size())),
|
|
|
|
Var(Var), Expr(Expr), DL(DL), Order(O), IsIndirect(IsIndirect),
|
|
|
|
IsVariadic(IsVariadic) {
|
2020-09-28 21:02:51 +08:00
|
|
|
assert(IsVariadic || L.size() == 1);
|
|
|
|
assert(!(IsVariadic && IsIndirect));
|
2021-04-09 00:56:25 +08:00
|
|
|
std::copy(L.begin(), L.end(), LocationOps);
|
|
|
|
std::copy(Dependencies.begin(), Dependencies.end(), AdditionalDependencies);
|
2020-09-28 21:02:51 +08:00
|
|
|
}
|
2010-03-06 08:03:23 +08:00
|
|
|
|
2021-04-09 00:56:25 +08:00
|
|
|
// We allocate arrays with the BumpPtrAllocator and never free or copy them,
|
|
|
|
// for LocationOps and AdditionalDependencies, as we never expect to copy or
|
|
|
|
// destroy an SDDbgValue. If we ever start copying or destroying instances, we
|
|
|
|
// should manage the allocated memory appropriately.
|
|
|
|
SDDbgValue(const SDDbgValue &Other) = delete;
|
|
|
|
SDDbgValue &operator=(const SDDbgValue &Other) = delete;
|
|
|
|
~SDDbgValue() = delete;
|
|
|
|
|
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
|
|
|
|
2021-04-09 00:56:25 +08:00
|
|
|
ArrayRef<SDDbgOperand> getLocationOps() const {
|
|
|
|
return ArrayRef<SDDbgOperand>(LocationOps, NumLocationOps);
|
|
|
|
}
|
2010-03-11 06:13:47 +08:00
|
|
|
|
2021-04-09 00:56:25 +08:00
|
|
|
SmallVector<SDDbgOperand> copyLocationOps() const {
|
|
|
|
return SmallVector<SDDbgOperand>(LocationOps, LocationOps + NumLocationOps);
|
|
|
|
}
|
2010-03-06 08:03:23 +08:00
|
|
|
|
2020-09-28 21:02:51 +08:00
|
|
|
// Returns the SDNodes which this SDDbgValue depends on.
|
2021-04-09 00:56:25 +08:00
|
|
|
SmallVector<SDNode *> getSDNodes() const {
|
|
|
|
SmallVector<SDNode *> Dependencies;
|
2021-09-21 17:12:56 +08:00
|
|
|
for (const SDDbgOperand &DbgOp : getLocationOps())
|
2021-04-09 00:56:25 +08:00
|
|
|
if (DbgOp.getKind() == SDDbgOperand::SDNODE)
|
|
|
|
Dependencies.push_back(DbgOp.getSDNode());
|
|
|
|
for (SDNode *Node : getAdditionalDependencies())
|
|
|
|
Dependencies.push_back(Node);
|
|
|
|
return Dependencies;
|
|
|
|
}
|
2010-03-06 08:03:23 +08:00
|
|
|
|
2021-04-09 00:56:25 +08:00
|
|
|
ArrayRef<SDNode *> getAdditionalDependencies() const {
|
|
|
|
return ArrayRef<SDNode *>(AdditionalDependencies,
|
|
|
|
NumAdditionalDependencies);
|
|
|
|
}
|
[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 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
|
|
|
|
2020-09-28 21:02:51 +08:00
|
|
|
bool isVariadic() const { return IsVariadic; }
|
|
|
|
|
2017-10-25 01:23:40 +08:00
|
|
|
/// Returns the DebugLoc.
|
2021-05-07 20:43:10 +08:00
|
|
|
const 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.
|
2021-05-07 20:43:10 +08:00
|
|
|
const DebugLoc &getDebugLoc() const { return DL; }
|
2018-05-09 10:41:08 +08:00
|
|
|
|
|
|
|
/// 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
|