Skip to content

Commit 19b3d8a

Browse files
committed
[RemoveDIs][NFC] Find DPValues using findDbgDeclares
This change doesn't change any call sites.
1 parent 6ab663b commit 19b3d8a

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

llvm/include/llvm/IR/DebugInfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class Module;
4040

4141
/// Finds dbg.declare intrinsics declaring local variables as living in the
4242
/// memory that 'V' points to.
43-
void findDbgDeclares(SmallVectorImpl<DbgDeclareInst *> &DbgUsers, Value *V);
43+
void findDbgDeclares(SmallVectorImpl<DbgDeclareInst *> &DbgUsers, Value *V,
44+
SmallVectorImpl<DPValue *> *DPValues = nullptr);
4445

4546
/// Finds the llvm.dbg.value intrinsics describing a value.
4647
void findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues,

llvm/lib/IR/DebugInfo.cpp

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,11 @@ using namespace llvm;
4444
using namespace llvm::at;
4545
using namespace llvm::dwarf;
4646

47-
void llvm::findDbgDeclares(SmallVectorImpl<DbgDeclareInst *> &DbgUsers,
48-
Value *V) {
49-
// This function is hot. Check whether the value has any metadata to avoid a
50-
// DenseMap lookup.
51-
if (!V->isUsedByMetadata())
52-
return;
53-
auto *L = LocalAsMetadata::getIfExists(V);
54-
if (!L)
55-
return;
56-
auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L);
57-
if (!MDV)
58-
return;
59-
60-
for (User *U : MDV->users()) {
61-
if (auto *DDI = dyn_cast<DbgDeclareInst>(U))
62-
DbgUsers.push_back(DDI);
63-
}
64-
}
65-
66-
template <typename IntrinsicT>
67-
static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result,
68-
Value *V, SmallVectorImpl<DPValue *> *DPValues) {
47+
template <typename IntrinsicT, bool AnyType,
48+
DPValue::LocationType Type = DPValue::LocationType(-1)>
49+
static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result, Value *V,
50+
SmallVectorImpl<DPValue *> *DPValues) {
51+
static_assert(AnyType || (int)Type >= 0);
6952
// This function is hot. Check whether the value has any metadata to avoid a
7053
// DenseMap lookup.
7154
if (!V->isUsedByMetadata())
@@ -94,7 +77,7 @@ static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result,
9477
// Get DPValues that use this as a single value.
9578
if (LocalAsMetadata *L = dyn_cast<LocalAsMetadata>(MD)) {
9679
for (DPValue *DPV : L->getAllDPValueUsers()) {
97-
if (DPV->getType() == DPValue::LocationType::Value)
80+
if (AnyType || DPV->getType() == Type)
9881
DPValues->push_back(DPV);
9982
}
10083
}
@@ -108,21 +91,28 @@ static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result,
10891
continue;
10992
DIArgList *DI = cast<DIArgList>(AL);
11093
for (DPValue *DPV : DI->getAllDPValueUsers())
111-
if (DPV->getType() == DPValue::LocationType::Value)
94+
if (AnyType || DPV->getType() == Type)
11295
if (EncounteredDPValues.insert(DPV).second)
11396
DPValues->push_back(DPV);
11497
}
11598
}
11699
}
117100

101+
void llvm::findDbgDeclares(SmallVectorImpl<DbgDeclareInst *> &DbgUsers,
102+
Value *V, SmallVectorImpl<DPValue *> *DPValues) {
103+
findDbgIntrinsics<DbgDeclareInst, false, DPValue::LocationType::Declare>(
104+
DbgUsers, V, DPValues);
105+
}
106+
118107
void llvm::findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues,
119108
Value *V, SmallVectorImpl<DPValue *> *DPValues) {
120-
findDbgIntrinsics<DbgValueInst>(DbgValues, V, DPValues);
109+
findDbgIntrinsics<DbgValueInst, false, DPValue::LocationType::Value>(
110+
DbgValues, V, DPValues);
121111
}
122112

123113
void llvm::findDbgUsers(SmallVectorImpl<DbgVariableIntrinsic *> &DbgUsers,
124114
Value *V, SmallVectorImpl<DPValue *> *DPValues) {
125-
findDbgIntrinsics<DbgVariableIntrinsic>(DbgUsers, V, DPValues);
115+
findDbgIntrinsics<DbgVariableIntrinsic, true>(DbgUsers, V, DPValues);
126116
}
127117

128118
DISubprogram *llvm::getDISubprogram(const MDNode *Scope) {

0 commit comments

Comments
 (0)