Skip to content

Commit 5457fab

Browse files
committed
Reapply "[RemoveDIs][NFC] Find DPValues using findDbgDeclares (#73500)"
This patch doesn't change any call sites. Depends on #73498. Reverted in 87c6867.
1 parent c8655fc commit 5457fab

File tree

4 files changed

+25
-27
lines changed

4 files changed

+25
-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/include/llvm/IR/DebugProgramInstruction.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class DPValue : public ilist_node<DPValue>, private DebugValueUser {
9797
enum class LocationType {
9898
Declare,
9999
Value,
100+
101+
End, ///< Marks the end of the concrete types.
102+
Any, ///< To indicate all LocationTypes in searches.
100103
};
101104
/// Classification of the debug-info record that this DPValue represents.
102105
/// Essentially, "is this a dbg.value or dbg.declare?". dbg.declares are not

llvm/lib/IR/DebugInfo.cpp

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,10 @@ 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,
48+
DPValue::LocationType Type = DPValue::LocationType::Any>
49+
static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result, Value *V,
50+
SmallVectorImpl<DPValue *> *DPValues) {
6951
// This function is hot. Check whether the value has any metadata to avoid a
7052
// DenseMap lookup.
7153
if (!V->isUsedByMetadata())
@@ -94,7 +76,7 @@ static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result,
9476
// Get DPValues that use this as a single value.
9577
if (LocalAsMetadata *L = dyn_cast<LocalAsMetadata>(MD)) {
9678
for (DPValue *DPV : L->getAllDPValueUsers()) {
97-
if (DPV->getType() == DPValue::LocationType::Value)
79+
if (Type == DPValue::LocationType::Any || DPV->getType() == Type)
9880
DPValues->push_back(DPV);
9981
}
10082
}
@@ -108,21 +90,29 @@ static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result,
10890
continue;
10991
DIArgList *DI = cast<DIArgList>(AL);
11092
for (DPValue *DPV : DI->getAllDPValueUsers())
111-
if (DPV->getType() == DPValue::LocationType::Value)
93+
if (Type == DPValue::LocationType::Any || DPV->getType() == Type)
11294
if (EncounteredDPValues.insert(DPV).second)
11395
DPValues->push_back(DPV);
11496
}
11597
}
11698
}
11799

100+
void llvm::findDbgDeclares(SmallVectorImpl<DbgDeclareInst *> &DbgUsers,
101+
Value *V, SmallVectorImpl<DPValue *> *DPValues) {
102+
findDbgIntrinsics<DbgDeclareInst, DPValue::LocationType::Declare>(DbgUsers, V,
103+
DPValues);
104+
}
105+
118106
void llvm::findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues,
119107
Value *V, SmallVectorImpl<DPValue *> *DPValues) {
120-
findDbgIntrinsics<DbgValueInst>(DbgValues, V, DPValues);
108+
findDbgIntrinsics<DbgValueInst, DPValue::LocationType::Value>(DbgValues, V,
109+
DPValues);
121110
}
122111

123112
void llvm::findDbgUsers(SmallVectorImpl<DbgVariableIntrinsic *> &DbgUsers,
124113
Value *V, SmallVectorImpl<DPValue *> *DPValues) {
125-
findDbgIntrinsics<DbgVariableIntrinsic>(DbgUsers, V, DPValues);
114+
findDbgIntrinsics<DbgVariableIntrinsic, DPValue::LocationType::Any>(
115+
DbgUsers, V, DPValues);
126116
}
127117

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

llvm/lib/IR/DebugProgramInstruction.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ DPValue::createDebugIntrinsic(Module *M, Instruction *InsertBefore) const {
203203
case DPValue::LocationType::Value:
204204
IntrinsicFn = Intrinsic::getDeclaration(M, Intrinsic::dbg_value);
205205
break;
206+
case DPValue::LocationType::End:
207+
case DPValue::LocationType::Any:
208+
llvm_unreachable("Invalid LocationType");
209+
break;
206210
}
207211

208212
// Create the intrinsic from this DPValue's information, optionally insert

0 commit comments

Comments
 (0)