Skip to content

Commit 4f57e20

Browse files
authored
[RemoveDIs][DebugInfo] Create overloads of debug intrinsic utilities for DPValues (#78313)
In preparation for the major chunk of the assignment tracking implementation, this patch adds a new set of overloaded versions of existing functions that take DbgVariableIntrinsics, with the overloads taking DPValues. This is used specifically to allow us to use generic code to handle both DbgVariableIntrinsics and DPValues, reducing code duplication. This patch doesn't actually add the uses of these functions.
1 parent 59cdf41 commit 4f57e20

File tree

4 files changed

+104
-28
lines changed

4 files changed

+104
-28
lines changed

llvm/include/llvm/IR/DebugInfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ DISubprogram *getDISubprogram(const MDNode *Scope);
5858
/// Produce a DebugLoc to use for each dbg.declare that is promoted to a
5959
/// dbg.value.
6060
DebugLoc getDebugValueLoc(DbgVariableIntrinsic *DII);
61+
DebugLoc getDebugValueLoc(DPValue *DPV);
6162

6263
/// Strip debug info in the module if it exists.
6364
///
@@ -191,6 +192,11 @@ AssignmentInstRange getAssignmentInsts(DIAssignID *ID);
191192
inline AssignmentInstRange getAssignmentInsts(const DbgAssignIntrinsic *DAI) {
192193
return getAssignmentInsts(DAI->getAssignID());
193194
}
195+
inline AssignmentInstRange getAssignmentInsts(const DPValue *DPV) {
196+
assert(DPV->isDbgAssign() &&
197+
"Can't get assignment instructions for non-assign DPV!");
198+
return getAssignmentInsts(DPV->getAssignID());
199+
}
194200

195201
//
196202
// Utilities for enumerating llvm.dbg.assign intrinsic from an assignment ID.

llvm/include/llvm/IR/IntrinsicInst.h

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -396,19 +396,6 @@ class DbgVariableIntrinsic : public DbgInfoIntrinsic {
396396
return getExpression()->getFragmentInfo();
397397
}
398398

399-
/// Get the FragmentInfo for the variable if it exists, otherwise return a
400-
/// FragmentInfo that covers the entire variable if the variable size is
401-
/// known, otherwise return a zero-sized fragment.
402-
DIExpression::FragmentInfo getFragmentOrEntireVariable() const {
403-
DIExpression::FragmentInfo VariableSlice(0, 0);
404-
// Get the fragment or variable size, or zero.
405-
if (auto Sz = getFragmentSizeInBits())
406-
VariableSlice.SizeInBits = *Sz;
407-
if (auto Frag = getExpression()->getFragmentInfo())
408-
VariableSlice.OffsetInBits = Frag->OffsetInBits;
409-
return VariableSlice;
410-
}
411-
412399
/// \name Casting methods
413400
/// @{
414401
static bool classof(const IntrinsicInst *I) {
@@ -547,6 +534,66 @@ class DbgLabelInst : public DbgInfoIntrinsic {
547534
/// @}
548535
};
549536

537+
/// This set of functions allow us to write type-generic code that operates on
538+
/// DPValues and DbgVariableIntrinsics, reducing the necessary amount of code
539+
/// duplication for the temporary period in which we support both debug info
540+
/// models.
541+
/// @{
542+
inline bool IsaDbgValue(DPValue *DPV) { return DPV->isDbgValue(); }
543+
inline bool IsaDbgDeclare(DPValue *DPV) { return DPV->isDbgDeclare(); }
544+
inline bool IsaDbgAssign(DPValue *DPV) { return DPV->isDbgAssign(); }
545+
546+
inline bool IsaDbgValue(DbgVariableIntrinsic *DVI) {
547+
return isa<DbgValueInst>(DVI);
548+
}
549+
inline bool IsaDbgDeclare(DbgVariableIntrinsic *DVI) {
550+
return isa<DbgDeclareInst>(DVI);
551+
}
552+
inline bool IsaDbgAssign(DbgVariableIntrinsic *DVI) {
553+
return isa<DbgAssignIntrinsic>(DVI);
554+
}
555+
556+
inline DPValue *CastToDbgValue(DPValue *DPV) { return DPV; }
557+
inline DPValue *CastToDbgDeclare(DPValue *DPV) { return DPV; }
558+
inline DPValue *CastToDbgAssign(DPValue *DPV) { return DPV; }
559+
560+
inline DbgValueInst *CastToDbgValue(DbgVariableIntrinsic *DVI) {
561+
return cast<DbgValueInst>(DVI);
562+
}
563+
inline DbgDeclareInst *CastToDbgDeclare(DbgVariableIntrinsic *DVI) {
564+
return cast<DbgDeclareInst>(DVI);
565+
}
566+
inline DbgAssignIntrinsic *CastToDbgAssign(DbgVariableIntrinsic *DVI) {
567+
return cast<DbgAssignIntrinsic>(DVI);
568+
}
569+
570+
inline DPValue *DynCastToDbgValue(DPValue *DPV) {
571+
if (!DPV->isDbgValue())
572+
return nullptr;
573+
return DPV;
574+
}
575+
inline DPValue *DynCastToDbgDeclare(DPValue *DPV) {
576+
if (!DPV->isDbgDeclare())
577+
return nullptr;
578+
return DPV;
579+
}
580+
inline DPValue *DynCastToDbgAssign(DPValue *DPV) {
581+
if (!DPV->isDbgAssign())
582+
return nullptr;
583+
return DPV;
584+
}
585+
586+
inline DbgValueInst *DynCastToDbgValue(DbgVariableIntrinsic *DVI) {
587+
return dyn_cast<DbgValueInst>(DVI);
588+
}
589+
inline DbgDeclareInst *DynCastToDbgDeclare(DbgVariableIntrinsic *DVI) {
590+
return dyn_cast<DbgDeclareInst>(DVI);
591+
}
592+
inline DbgAssignIntrinsic *DynCastToDbgAssign(DbgVariableIntrinsic *DVI) {
593+
return dyn_cast<DbgAssignIntrinsic>(DVI);
594+
}
595+
/// @}
596+
550597
/// This is the common base class for vector predication intrinsics.
551598
class VPIntrinsic : public IntrinsicInst {
552599
public:

llvm/lib/IR/DebugInfo.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@ DebugLoc llvm::getDebugValueLoc(DbgVariableIntrinsic *DII) {
163163
return DILocation::get(DII->getContext(), 0, 0, Scope, InlinedAt);
164164
}
165165

166+
DebugLoc llvm::getDebugValueLoc(DPValue *DPV) {
167+
// Original dbg.declare must have a location.
168+
const DebugLoc &DeclareLoc = DPV->getDebugLoc();
169+
MDNode *Scope = DeclareLoc.getScope();
170+
DILocation *InlinedAt = DeclareLoc.getInlinedAt();
171+
// Because no machine insts can come from debug intrinsics, only the scope
172+
// and inlinedAt is significant. Zero line numbers are used in case this
173+
// DebugLoc leaks into any adjacent instructions. Produce an unknown location
174+
// with the correct scope / inlinedAt fields.
175+
return DILocation::get(DPV->getContext(), 0, 0, Scope, InlinedAt);
176+
}
177+
166178
//===----------------------------------------------------------------------===//
167179
// DebugInfoFinder implementations.
168180
//===----------------------------------------------------------------------===//
@@ -1813,6 +1825,31 @@ void at::deleteAll(Function *F) {
18131825
DAI->eraseFromParent();
18141826
}
18151827

1828+
/// Get the FragmentInfo for the variable if it exists, otherwise return a
1829+
/// FragmentInfo that covers the entire variable if the variable size is
1830+
/// known, otherwise return a zero-sized fragment.
1831+
static DIExpression::FragmentInfo
1832+
getFragmentOrEntireVariable(const DPValue *DPV) {
1833+
DIExpression::FragmentInfo VariableSlice(0, 0);
1834+
// Get the fragment or variable size, or zero.
1835+
if (auto Sz = DPV->getFragmentSizeInBits())
1836+
VariableSlice.SizeInBits = *Sz;
1837+
if (auto Frag = DPV->getExpression()->getFragmentInfo())
1838+
VariableSlice.OffsetInBits = Frag->OffsetInBits;
1839+
return VariableSlice;
1840+
}
1841+
1842+
static DIExpression::FragmentInfo
1843+
getFragmentOrEntireVariable(const DbgVariableIntrinsic *DVI) {
1844+
DIExpression::FragmentInfo VariableSlice(0, 0);
1845+
// Get the fragment or variable size, or zero.
1846+
if (auto Sz = DVI->getFragmentSizeInBits())
1847+
VariableSlice.SizeInBits = *Sz;
1848+
if (auto Frag = DVI->getExpression()->getFragmentInfo())
1849+
VariableSlice.OffsetInBits = Frag->OffsetInBits;
1850+
return VariableSlice;
1851+
}
1852+
18161853
bool at::calculateFragmentIntersect(
18171854
const DataLayout &DL, const Value *Dest, uint64_t SliceOffsetInBits,
18181855
uint64_t SliceSizeInBits, const DbgAssignIntrinsic *DAI,
@@ -1910,7 +1947,7 @@ bool at::calculateFragmentIntersect(
19101947
if (DAI->isKillAddress())
19111948
return false;
19121949

1913-
DIExpression::FragmentInfo VarFrag = DAI->getFragmentOrEntireVariable();
1950+
DIExpression::FragmentInfo VarFrag = getFragmentOrEntireVariable(DAI);
19141951
if (VarFrag.SizeInBits == 0)
19151952
return false; // Variable size is unknown.
19161953

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,20 +1724,6 @@ void llvm::ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
17241724
SI->getIterator());
17251725
}
17261726

1727-
namespace llvm {
1728-
// RemoveDIs: duplicate the getDebugValueLoc method using DPValues instead of
1729-
// dbg.value intrinsics. In llvm namespace so that it overloads the
1730-
// DbgVariableIntrinsic version.
1731-
static DebugLoc getDebugValueLoc(DPValue *DPV) {
1732-
// Original dbg.declare must have a location.
1733-
const DebugLoc &DeclareLoc = DPV->getDebugLoc();
1734-
MDNode *Scope = DeclareLoc.getScope();
1735-
DILocation *InlinedAt = DeclareLoc.getInlinedAt();
1736-
// Produce an unknown location with the correct scope / inlinedAt fields.
1737-
return DILocation::get(DPV->getContext(), 0, 0, Scope, InlinedAt);
1738-
}
1739-
} // namespace llvm
1740-
17411727
/// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
17421728
/// that has an associated llvm.dbg.declare intrinsic.
17431729
void llvm::ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,

0 commit comments

Comments
 (0)