Skip to content

Commit c9ceb9b

Browse files
authored
[DebugInfo] Remove intrinsic-flavours of findDbgUsers (#149816)
This is one of the final remaining debug-intrinsic specific codepaths out there, and pieces of cross-LLVM infrastructure to do with debug intrinsics.
1 parent 0823f4f commit c9ceb9b

File tree

22 files changed

+64
-232
lines changed

22 files changed

+64
-232
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6062,11 +6062,10 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy &Builder,
60626062
// ptr, in this case its debug info may not match the actual type of object
60636063
// being used as in the next instruction, so we will need to emit a pseudo
60646064
// variable for type-casted value.
6065-
auto DeclareTypeMatches = [&](auto *DbgDeclare) {
6065+
auto DeclareTypeMatches = [&](llvm::DbgVariableRecord *DbgDeclare) {
60666066
return DbgDeclare->getVariable()->getType() == Type;
60676067
};
6068-
if (any_of(llvm::findDbgDeclares(Var), DeclareTypeMatches) ||
6069-
any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches))
6068+
if (any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches))
60706069
return;
60716070
}
60726071

llvm/include/llvm/IR/DebugInfo.h

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,26 @@ class DbgVariableRecord;
3939
class Instruction;
4040
class Module;
4141

42-
/// Finds dbg.declare intrinsics declaring local variables as living in the
42+
/// Finds dbg.declare records declaring local variables as living in the
4343
/// memory that 'V' points to.
44-
LLVM_ABI TinyPtrVector<DbgDeclareInst *> findDbgDeclares(Value *V);
45-
/// As above, for DVRDeclares.
4644
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRDeclares(Value *V);
4745
/// As above, for DVRValues.
4846
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRValues(Value *V);
4947

50-
/// Finds the llvm.dbg.value intrinsics describing a value.
51-
LLVM_ABI void findDbgValues(
52-
SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V,
53-
SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords = nullptr);
54-
55-
/// Finds the debug info intrinsics describing a value.
56-
LLVM_ABI void findDbgUsers(
57-
SmallVectorImpl<DbgVariableIntrinsic *> &DbgInsts, Value *V,
58-
SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords = nullptr);
48+
/// Finds the debug info records describing a value.
49+
LLVM_ABI void
50+
findDbgUsers(Value *V,
51+
SmallVectorImpl<DbgVariableRecord *> &DbgVariableRecords);
52+
/// Finds the dbg.values describing a value.
53+
LLVM_ABI void
54+
findDbgValues(Value *V,
55+
SmallVectorImpl<DbgVariableRecord *> &DbgVariableRecords);
5956

6057
/// Find subprogram that is enclosing this scope.
6158
LLVM_ABI DISubprogram *getDISubprogram(const MDNode *Scope);
6259

6360
/// Produce a DebugLoc to use for each dbg.declare that is promoted to a
6461
/// dbg.value.
65-
LLVM_ABI DebugLoc getDebugValueLoc(DbgVariableIntrinsic *DII);
6662
LLVM_ABI DebugLoc getDebugValueLoc(DbgVariableRecord *DVR);
6763

6864
/// Strip debug info in the module if it exists.
@@ -192,13 +188,6 @@ using AssignmentInstRange =
192188
/// Iterators invalidated by adding or removing DIAssignID metadata to/from any
193189
/// instruction (including by deleting or cloning instructions).
194190
LLVM_ABI AssignmentInstRange getAssignmentInsts(DIAssignID *ID);
195-
/// Return a range of instructions (typically just one) that perform the
196-
/// assignment that \p DAI encodes.
197-
/// Iterators invalidated by adding or removing DIAssignID metadata to/from any
198-
/// instruction (including by deleting or cloning instructions).
199-
inline AssignmentInstRange getAssignmentInsts(const DbgAssignIntrinsic *DAI) {
200-
return getAssignmentInsts(DAI->getAssignID());
201-
}
202191

203192
inline AssignmentInstRange getAssignmentInsts(const DbgVariableRecord *DVR) {
204193
assert(DVR->isDbgAssign() &&

llvm/include/llvm/Transforms/Utils/Local.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ LLVM_ABI void salvageDebugInfo(Instruction &I);
325325
/// Mark undef if salvaging cannot be completed.
326326
LLVM_ABI void
327327
salvageDebugInfoForDbgValues(Instruction &I,
328-
ArrayRef<DbgVariableIntrinsic *> Insns,
329328
ArrayRef<DbgVariableRecord *> DPInsns);
330329

331330
/// Given an instruction \p I and DIExpression \p DIExpr operating on

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3571,9 +3571,7 @@ class TypePromotionTransaction {
35713571
}
35723572
// Record the debug uses separately. They are not in the instruction's
35733573
// use list, but they are replaced by RAUW.
3574-
SmallVector<DbgValueInst *> DbgValues;
3575-
findDbgValues(DbgValues, Inst, &DbgVariableRecords);
3576-
assert(DbgValues.empty());
3574+
findDbgValues(Inst, DbgVariableRecords);
35773575

35783576
// Now, we can replace the uses.
35793577
Inst->replaceAllUsesWith(New);

llvm/lib/IR/DebugInfo.cpp

Lines changed: 13 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,6 @@ using namespace llvm;
4545
using namespace llvm::at;
4646
using namespace llvm::dwarf;
4747

48-
TinyPtrVector<DbgDeclareInst *> llvm::findDbgDeclares(Value *V) {
49-
// This function is hot. Check whether the value has any metadata to avoid a
50-
// DenseMap lookup. This check is a bitfield datamember lookup.
51-
if (!V->isUsedByMetadata())
52-
return {};
53-
auto *L = ValueAsMetadata::getIfExists(V);
54-
if (!L)
55-
return {};
56-
auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L);
57-
if (!MDV)
58-
return {};
59-
60-
TinyPtrVector<DbgDeclareInst *> Declares;
61-
for (User *U : MDV->users())
62-
if (auto *DDI = dyn_cast<DbgDeclareInst>(U))
63-
Declares.push_back(DDI);
64-
65-
return Declares;
66-
}
6748
TinyPtrVector<DbgVariableRecord *> llvm::findDVRDeclares(Value *V) {
6849
// This function is hot. Check whether the value has any metadata to avoid a
6950
// DenseMap lookup. This check is a bitfield datamember lookup.
@@ -98,42 +79,31 @@ TinyPtrVector<DbgVariableRecord *> llvm::findDVRValues(Value *V) {
9879
return Values;
9980
}
10081

101-
template <typename IntrinsicT, bool DbgAssignAndValuesOnly>
82+
template <bool DbgAssignAndValuesOnly>
10283
static void
103-
findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result, Value *V,
104-
SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords) {
84+
findDbgIntrinsics(Value *V,
85+
SmallVectorImpl<DbgVariableRecord *> &DbgVariableRecords) {
10586
// This function is hot. Check whether the value has any metadata to avoid a
10687
// DenseMap lookup.
10788
if (!V->isUsedByMetadata())
10889
return;
10990

110-
LLVMContext &Ctx = V->getContext();
11191
// TODO: If this value appears multiple times in a DIArgList, we should still
112-
// only add the owning DbgValueInst once; use this set to track ArgListUsers.
92+
// only add the owning dbg.value once; use this set to track ArgListUsers.
11393
// This behaviour can be removed when we can automatically remove duplicates.
11494
// V will also appear twice in a dbg.assign if its used in the both the value
11595
// and address components.
116-
SmallPtrSet<IntrinsicT *, 4> EncounteredIntrinsics;
11796
SmallPtrSet<DbgVariableRecord *, 4> EncounteredDbgVariableRecords;
11897

119-
/// Append IntrinsicT users of MetadataAsValue(MD).
120-
auto AppendUsers = [&Ctx, &EncounteredIntrinsics,
121-
&EncounteredDbgVariableRecords, &Result,
122-
DbgVariableRecords](Metadata *MD) {
123-
if (auto *MDV = MetadataAsValue::getIfExists(Ctx, MD)) {
124-
for (User *U : MDV->users())
125-
if (IntrinsicT *DVI = dyn_cast<IntrinsicT>(U))
126-
if (EncounteredIntrinsics.insert(DVI).second)
127-
Result.push_back(DVI);
128-
}
129-
if (!DbgVariableRecords)
130-
return;
98+
/// Append users of MetadataAsValue(MD).
99+
auto AppendUsers = [&EncounteredDbgVariableRecords,
100+
&DbgVariableRecords](Metadata *MD) {
131101
// Get DbgVariableRecords that use this as a single value.
132102
if (LocalAsMetadata *L = dyn_cast<LocalAsMetadata>(MD)) {
133103
for (DbgVariableRecord *DVR : L->getAllDbgVariableRecordUsers()) {
134104
if (!DbgAssignAndValuesOnly || DVR->isDbgValue() || DVR->isDbgAssign())
135105
if (EncounteredDbgVariableRecords.insert(DVR).second)
136-
DbgVariableRecords->push_back(DVR);
106+
DbgVariableRecords.push_back(DVR);
137107
}
138108
}
139109
};
@@ -142,29 +112,23 @@ findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result, Value *V,
142112
AppendUsers(L);
143113
for (Metadata *AL : L->getAllArgListUsers()) {
144114
AppendUsers(AL);
145-
if (!DbgVariableRecords)
146-
continue;
147115
DIArgList *DI = cast<DIArgList>(AL);
148116
for (DbgVariableRecord *DVR : DI->getAllDbgVariableRecordUsers())
149117
if (!DbgAssignAndValuesOnly || DVR->isDbgValue() || DVR->isDbgAssign())
150118
if (EncounteredDbgVariableRecords.insert(DVR).second)
151-
DbgVariableRecords->push_back(DVR);
119+
DbgVariableRecords.push_back(DVR);
152120
}
153121
}
154122
}
155123

156124
void llvm::findDbgValues(
157-
SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V,
158-
SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords) {
159-
findDbgIntrinsics<DbgValueInst, /*DbgAssignAndValuesOnly=*/true>(
160-
DbgValues, V, DbgVariableRecords);
125+
Value *V, SmallVectorImpl<DbgVariableRecord *> &DbgVariableRecords) {
126+
findDbgIntrinsics</*DbgAssignAndValuesOnly=*/true>(V, DbgVariableRecords);
161127
}
162128

163129
void llvm::findDbgUsers(
164-
SmallVectorImpl<DbgVariableIntrinsic *> &DbgUsers, Value *V,
165-
SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords) {
166-
findDbgIntrinsics<DbgVariableIntrinsic, /*DbgAssignAndValuesOnly=*/false>(
167-
DbgUsers, V, DbgVariableRecords);
130+
Value *V, SmallVectorImpl<DbgVariableRecord *> &DbgVariableRecords) {
131+
findDbgIntrinsics</*DbgAssignAndValuesOnly=*/false>(V, DbgVariableRecords);
168132
}
169133

170134
DISubprogram *llvm::getDISubprogram(const MDNode *Scope) {
@@ -173,18 +137,6 @@ DISubprogram *llvm::getDISubprogram(const MDNode *Scope) {
173137
return nullptr;
174138
}
175139

176-
DebugLoc llvm::getDebugValueLoc(DbgVariableIntrinsic *DII) {
177-
// Original dbg.declare must have a location.
178-
const DebugLoc &DeclareLoc = DII->getDebugLoc();
179-
MDNode *Scope = DeclareLoc.getScope();
180-
DILocation *InlinedAt = DeclareLoc.getInlinedAt();
181-
// Because no machine insts can come from debug intrinsics, only the scope
182-
// and inlinedAt is significant. Zero line numbers are used in case this
183-
// DebugLoc leaks into any adjacent instructions. Produce an unknown location
184-
// with the correct scope / inlinedAt fields.
185-
return DILocation::get(DII->getContext(), 0, 0, Scope, InlinedAt);
186-
}
187-
188140
DebugLoc llvm::getDebugValueLoc(DbgVariableRecord *DVR) {
189141
// Original dbg.declare must have a location.
190142
const DebugLoc &DeclareLoc = DVR->getDebugLoc();
@@ -852,19 +804,6 @@ void DebugTypeInfoRemoval::traverse(MDNode *N) {
852804
bool llvm::stripNonLineTableDebugInfo(Module &M) {
853805
bool Changed = false;
854806

855-
// First off, delete the debug intrinsics.
856-
auto RemoveUses = [&](StringRef Name) {
857-
if (auto *DbgVal = M.getFunction(Name)) {
858-
while (!DbgVal->use_empty())
859-
cast<Instruction>(DbgVal->user_back())->eraseFromParent();
860-
DbgVal->eraseFromParent();
861-
Changed = true;
862-
}
863-
};
864-
RemoveUses("llvm.dbg.declare");
865-
RemoveUses("llvm.dbg.label");
866-
RemoveUses("llvm.dbg.value");
867-
868807
// Delete non-CU debug info named metadata nodes.
869808
for (auto NMI = M.named_metadata_begin(), NME = M.named_metadata_end();
870809
NMI != NME;) {

llvm/lib/IR/Value.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -582,16 +582,11 @@ void Value::replaceUsesWithIf(Value *New,
582582
}
583583
}
584584

585-
/// Replace llvm.dbg.* uses of MetadataAsValue(ValueAsMetadata(V)) outside BB
585+
/// Replace debug record uses of MetadataAsValue(ValueAsMetadata(V)) outside BB
586586
/// with New.
587587
static void replaceDbgUsesOutsideBlock(Value *V, Value *New, BasicBlock *BB) {
588-
SmallVector<DbgVariableIntrinsic *> DbgUsers;
589588
SmallVector<DbgVariableRecord *> DPUsers;
590-
findDbgUsers(DbgUsers, V, &DPUsers);
591-
for (auto *DVI : DbgUsers) {
592-
if (DVI->getParent() != BB)
593-
DVI->replaceVariableLocationOp(V, New);
594-
}
589+
findDbgUsers(V, DPUsers);
595590
for (auto *DVR : DPUsers) {
596591
DbgMarker *Marker = DVR->getMarker();
597592
if (Marker->getParent() != BB)

llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,9 +1583,8 @@ void SplitPtrStructs::killAndReplaceSplitInstructions(
15831583
if (!SplitUsers.contains(I))
15841584
continue;
15851585

1586-
SmallVector<DbgValueInst *> DIs;
15871586
SmallVector<DbgVariableRecord *> Dbgs;
1588-
findDbgValues(DIs, I, &Dbgs);
1587+
findDbgValues(I, Dbgs);
15891588
for (DbgVariableRecord *Dbg : Dbgs) {
15901589
auto &DL = I->getDataLayout();
15911590
assert(isSplitFatPtr(I->getType()) &&

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,6 @@ static void cacheDIVar(FrameDataInfo &FrameData,
553553
if (I != Container.end())
554554
DIVarCache.insert({V, (*I)->getVariable()});
555555
};
556-
CacheIt(findDbgDeclares(V));
557556
CacheIt(findDVRDeclares(V));
558557
}
559558
}
@@ -1219,10 +1218,8 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
12191218
auto *G = GetFramePointer(Alloca);
12201219
G->setName(Alloca->getName() + Twine(".reload.addr"));
12211220

1222-
SmallVector<DbgVariableIntrinsic *, 4> DIs;
12231221
SmallVector<DbgVariableRecord *> DbgVariableRecords;
1224-
findDbgUsers(DIs, Alloca, &DbgVariableRecords);
1225-
assert(DIs.empty() && "Should never see debug-intrinsics");
1222+
findDbgUsers(Alloca, DbgVariableRecords);
12261223
for (auto *DVR : DbgVariableRecords)
12271224
DVR->replaceVariableLocationOp(Alloca, G);
12281225

llvm/lib/Transforms/Coroutines/SpillUtils.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,8 @@ void collectSpillsFromDbgInfo(SpillInfo &Spills, Function &F,
519519
// We would handle the dbg.values for allocas specially
520520
for (auto &Iter : Spills) {
521521
auto *V = Iter.first;
522-
SmallVector<DbgValueInst *, 16> DVIs;
523522
SmallVector<DbgVariableRecord *, 16> DVRs;
524-
findDbgValues(DVIs, V, &DVRs);
525-
assert(DVIs.empty());
523+
findDbgValues(V, DVRs);
526524
// Add the instructions which carry debug info that is in the frame.
527525
for (DbgVariableRecord *DVR : DVRs)
528526
if (Checker.isDefinitionAcrossSuspend(*V, DVR->Marker->MarkedInstr))

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,10 +1463,8 @@ void InstCombinerImpl::freelyInvertAllUsersOf(Value *I, Value *IgnoredUser) {
14631463
}
14641464

14651465
// Update pre-existing debug value uses.
1466-
SmallVector<DbgValueInst *, 4> DbgValues;
14671466
SmallVector<DbgVariableRecord *, 4> DbgVariableRecords;
1468-
llvm::findDbgValues(DbgValues, I, &DbgVariableRecords);
1469-
assert(DbgValues.empty());
1467+
llvm::findDbgValues(I, DbgVariableRecords);
14701468

14711469
for (DbgVariableRecord *DbgVal : DbgVariableRecords) {
14721470
SmallVector<uint64_t, 1> Ops = {dwarf::DW_OP_not};
@@ -3611,12 +3609,10 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
36113609

36123610
// If we are removing an alloca with a dbg.declare, insert dbg.value calls
36133611
// before each store.
3614-
SmallVector<DbgVariableIntrinsic *, 8> DVIs;
36153612
SmallVector<DbgVariableRecord *, 8> DVRs;
36163613
std::unique_ptr<DIBuilder> DIB;
36173614
if (isa<AllocaInst>(MI)) {
3618-
findDbgUsers(DVIs, &MI, &DVRs);
3619-
assert(DVIs.empty());
3615+
findDbgUsers(&MI, DVRs);
36203616
DIB.reset(new DIBuilder(*MI.getModule(), /*AllowUnresolved=*/false));
36213617
}
36223618

@@ -3738,9 +3734,6 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
37383734
//
37393735
// FIXME: the Assignment Tracking project has now likely made this
37403736
// redundant (and it's sometimes harmful).
3741-
for (auto *DVI : DVIs)
3742-
if (DVI->isAddressOfVariable() || DVI->getExpression()->startsWithDeref())
3743-
DVI->eraseFromParent();
37443737
for (auto *DVR : DVRs)
37453738
if (DVR->isAddressOfVariable() || DVR->getExpression()->startsWithDeref())
37463739
DVR->eraseFromParent();
@@ -5292,10 +5285,8 @@ bool InstCombinerImpl::tryToSinkInstruction(Instruction *I,
52925285
// maximise the range variables have location for. If we cannot salvage, then
52935286
// mark the location undef: we know it was supposed to receive a new location
52945287
// here, but that computation has been sunk.
5295-
SmallVector<DbgVariableIntrinsic *, 2> DbgUsers;
52965288
SmallVector<DbgVariableRecord *, 2> DbgVariableRecords;
5297-
findDbgUsers(DbgUsers, I, &DbgVariableRecords);
5298-
assert(DbgUsers.empty());
5289+
findDbgUsers(I, DbgVariableRecords);
52995290
if (!DbgVariableRecords.empty())
53005291
tryToSinkInstructionDbgVariableRecords(I, InsertPos, SrcBlock, DestBlock,
53015292
DbgVariableRecords);
@@ -5422,7 +5413,7 @@ void InstCombinerImpl::tryToSinkInstructionDbgVariableRecords(
54225413
if (DVRClones.empty())
54235414
return;
54245415

5425-
salvageDebugInfoForDbgValues(*I, {}, DbgVariableRecordsToSalvage);
5416+
salvageDebugInfoForDbgValues(*I, DbgVariableRecordsToSalvage);
54265417

54275418
// The clones are in reverse order of original appearance. Assert that the
54285419
// head bit is set on the iterator as we _should_ have received it via

0 commit comments

Comments
 (0)