Skip to content

Commit 2d9d9a1

Browse files
authored
[NFC] Change FindDbgDeclareUsers interface to match findDbgUsers/values (#73498)
This simplifies an upcoming patch to support the RemoveDIs project (tracking variable locations without using intrinsics). Next in this series is #73500.
1 parent 6111f5c commit 2d9d9a1

File tree

6 files changed

+30
-19
lines changed

6 files changed

+30
-19
lines changed

llvm/include/llvm/IR/DebugInfo.h

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

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

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

llvm/lib/IR/DebugInfo.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,23 @@ using namespace llvm;
4444
using namespace llvm::at;
4545
using namespace llvm::dwarf;
4646

47-
TinyPtrVector<DbgDeclareInst *> llvm::FindDbgDeclareUses(Value *V) {
47+
void llvm::findDbgDeclares(SmallVectorImpl<DbgDeclareInst *> &DbgUsers,
48+
Value *V) {
4849
// This function is hot. Check whether the value has any metadata to avoid a
4950
// DenseMap lookup.
5051
if (!V->isUsedByMetadata())
51-
return {};
52+
return;
5253
auto *L = LocalAsMetadata::getIfExists(V);
5354
if (!L)
54-
return {};
55+
return;
5556
auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L);
5657
if (!MDV)
57-
return {};
58+
return;
5859

59-
TinyPtrVector<DbgDeclareInst *> Declares;
6060
for (User *U : MDV->users()) {
6161
if (auto *DDI = dyn_cast<DbgDeclareInst>(U))
62-
Declares.push_back(DDI);
62+
DbgUsers.push_back(DDI);
6363
}
64-
65-
return Declares;
6664
}
6765

6866
template <typename IntrinsicT>

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,8 @@ static void cacheDIVar(FrameDataInfo &FrameData,
963963
if (DIVarCache.contains(V))
964964
continue;
965965

966-
auto DDIs = FindDbgDeclareUses(V);
966+
SmallVector<DbgDeclareInst *, 1> DDIs;
967+
findDbgDeclares(DDIs, V);
967968
auto *I = llvm::find_if(DDIs, [](DbgDeclareInst *DDI) {
968969
return DDI->getExpression()->getNumElements() == 0;
969970
});
@@ -1119,7 +1120,8 @@ static void buildFrameDebugInfo(Function &F, coro::Shape &Shape,
11191120
assert(PromiseAlloca &&
11201121
"Coroutine with switch ABI should own Promise alloca");
11211122

1122-
TinyPtrVector<DbgDeclareInst *> DIs = FindDbgDeclareUses(PromiseAlloca);
1123+
SmallVector<DbgDeclareInst *, 1> DIs;
1124+
findDbgDeclares(DIs, PromiseAlloca);
11231125
if (DIs.empty())
11241126
return;
11251127

@@ -1840,7 +1842,8 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
18401842
FrameTy->getElementType(FrameData.getFieldIndex(E.first)), GEP,
18411843
SpillAlignment, E.first->getName() + Twine(".reload"));
18421844

1843-
TinyPtrVector<DbgDeclareInst *> DIs = FindDbgDeclareUses(Def);
1845+
SmallVector<DbgDeclareInst *, 1> DIs;
1846+
findDbgDeclares(DIs, Def);
18441847
// Try best to find dbg.declare. If the spill is a temp, there may not
18451848
// be a direct dbg.declare. Walk up the load chain to find one from an
18461849
// alias.
@@ -1854,7 +1857,8 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
18541857
CurDef = LdInst->getPointerOperand();
18551858
if (!isa<AllocaInst, LoadInst>(CurDef))
18561859
break;
1857-
DIs = FindDbgDeclareUses(CurDef);
1860+
DIs.clear();
1861+
findDbgDeclares(DIs, CurDef);
18581862
}
18591863
}
18601864

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4940,10 +4940,13 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
49404940
// Migrate debug information from the old alloca to the new alloca(s)
49414941
// and the individual partitions.
49424942
TinyPtrVector<DbgVariableIntrinsic *> DbgVariables;
4943-
for (auto *DbgDeclare : FindDbgDeclareUses(&AI))
4943+
SmallVector<DbgDeclareInst *, 1> DbgDeclares;
4944+
findDbgDeclares(DbgDeclares, &AI);
4945+
for (auto *DbgDeclare : DbgDeclares)
49444946
DbgVariables.push_back(DbgDeclare);
49454947
for (auto *DbgAssign : at::getAssignmentMarkers(&AI))
49464948
DbgVariables.push_back(DbgAssign);
4949+
49474950
for (DbgVariableIntrinsic *DbgVariable : DbgVariables) {
49484951
auto *Expr = DbgVariable->getExpression();
49494952
DIBuilder DIB(*AI.getModule(), /*AllowUnresolved*/ false);
@@ -4997,7 +5000,9 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
49975000

49985001
// Remove any existing intrinsics on the new alloca describing
49995002
// the variable fragment.
5000-
for (DbgDeclareInst *OldDII : FindDbgDeclareUses(Fragment.Alloca)) {
5003+
SmallVector<DbgDeclareInst *, 1> FragDbgDeclares;
5004+
findDbgDeclares(FragDbgDeclares, Fragment.Alloca);
5005+
for (DbgDeclareInst *OldDII : FragDbgDeclares) {
50015006
auto SameVariableFragment = [](const DbgVariableIntrinsic *LHS,
50025007
const DbgVariableIntrinsic *RHS) {
50035008
return LHS->getVariable() == RHS->getVariable() &&
@@ -5147,7 +5152,9 @@ bool SROA::deleteDeadInstructions(
51475152
// not be able to find it.
51485153
if (AllocaInst *AI = dyn_cast<AllocaInst>(I)) {
51495154
DeletedAllocas.insert(AI);
5150-
for (DbgDeclareInst *OldDII : FindDbgDeclareUses(AI))
5155+
SmallVector<DbgDeclareInst *, 1> DbgDeclares;
5156+
findDbgDeclares(DbgDeclares, AI);
5157+
for (DbgDeclareInst *OldDII : DbgDeclares)
51515158
OldDII->eraseFromParent();
51525159
}
51535160

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2103,7 +2103,8 @@ void llvm::insertDebugValuesForPHIs(BasicBlock *BB,
21032103
bool llvm::replaceDbgDeclare(Value *Address, Value *NewAddress,
21042104
DIBuilder &Builder, uint8_t DIExprFlags,
21052105
int Offset) {
2106-
auto DbgDeclares = FindDbgDeclareUses(Address);
2106+
SmallVector<DbgDeclareInst *, 1> DbgDeclares;
2107+
findDbgDeclares(DbgDeclares, Address);
21072108
for (DbgVariableIntrinsic *DII : DbgDeclares) {
21082109
const DebugLoc &Loc = DII->getDebugLoc();
21092110
auto *DIVar = DII->getVariable();

llvm/lib/Transforms/Utils/MemoryOpRemark.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,9 @@ void MemoryOpRemark::visitVariable(const Value *V,
321321
bool FoundDI = false;
322322
// Try to get an llvm.dbg.declare, which has a DILocalVariable giving us the
323323
// real debug info name and size of the variable.
324-
for (const DbgVariableIntrinsic *DVI :
325-
FindDbgDeclareUses(const_cast<Value *>(V))) {
324+
SmallVector<DbgDeclareInst *, 1> DbgDeclares;
325+
findDbgDeclares(DbgDeclares, const_cast<Value *>(V));
326+
for (const DbgVariableIntrinsic *DVI : DbgDeclares) {
326327
if (DILocalVariable *DILV = DVI->getVariable()) {
327328
std::optional<uint64_t> DISize = getSizeInBytes(DILV->getSizeInBits());
328329
VariableInfo Var{DILV->getName(), DISize};

0 commit comments

Comments
 (0)