[llvm] [DebugInfo] Remove intrinsic-flavours of findDbgUsers (PR #149816)
Jeremy Morse via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 21 06:46:02 PDT 2025
https://github.com/jmorse created https://github.com/llvm/llvm-project/pull/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.
>From 43916ffb25936a4a9d38ea39e354e9ddfda333a1 Mon Sep 17 00:00:00 2001
From: Jeremy Morse <jeremy.morse at sony.com>
Date: Fri, 18 Jul 2025 12:07:13 +0100
Subject: [PATCH] [DebugInfo] Remove intrinsic-flavours of findDbgUsers
This is one of the final remaining debug-intrinsic specific codepaths out
there, and pieces of cross-LLVM infrastructure to do with debug intrinsics.
---
llvm/include/llvm/IR/DebugInfo.h | 27 ++----
llvm/include/llvm/Transforms/Utils/Local.h | 1 -
llvm/lib/CodeGen/CodeGenPrepare.cpp | 4 +-
llvm/lib/IR/DebugInfo.cpp | 90 ++++---------------
llvm/lib/IR/Value.cpp | 9 +-
.../AMDGPU/AMDGPULowerBufferFatPointers.cpp | 3 +-
llvm/lib/Transforms/Coroutines/CoroFrame.cpp | 5 +-
llvm/lib/Transforms/Coroutines/SpillUtils.cpp | 4 +-
.../InstCombine/InstructionCombining.cpp | 17 +---
.../Scalar/ConstraintElimination.cpp | 4 +-
llvm/lib/Transforms/Scalar/JumpThreading.cpp | 5 +-
llvm/lib/Transforms/Scalar/NewGVN.cpp | 5 +-
llvm/lib/Transforms/Utils/CodeExtractor.cpp | 8 +-
llvm/lib/Transforms/Utils/LCSSA.cpp | 18 +---
llvm/lib/Transforms/Utils/Local.cpp | 37 ++------
.../Transforms/Utils/LoopRotationUtils.cpp | 4 +-
llvm/lib/Transforms/Utils/MemoryOpRemark.cpp | 5 +-
.../Utils/PromoteMemoryToRegister.cpp | 4 +-
llvm/lib/Transforms/Utils/SSAUpdater.cpp | 4 +-
llvm/unittests/IR/DebugInfoTest.cpp | 13 +--
llvm/unittests/Transforms/Utils/LocalTest.cpp | 23 ++---
21 files changed, 61 insertions(+), 229 deletions(-)
diff --git a/llvm/include/llvm/IR/DebugInfo.h b/llvm/include/llvm/IR/DebugInfo.h
index f8241a3cdf160..00f6648481f1d 100644
--- a/llvm/include/llvm/IR/DebugInfo.h
+++ b/llvm/include/llvm/IR/DebugInfo.h
@@ -39,30 +39,24 @@ class DbgVariableRecord;
class Instruction;
class Module;
-/// Finds dbg.declare intrinsics declaring local variables as living in the
+/// Finds dbg.declare records declaring local variables as living in the
/// memory that 'V' points to.
-LLVM_ABI TinyPtrVector<DbgDeclareInst *> findDbgDeclares(Value *V);
-/// As above, for DVRDeclares.
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRDeclares(Value *V);
/// As above, for DVRValues.
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRValues(Value *V);
-/// Finds the llvm.dbg.value intrinsics describing a value.
-LLVM_ABI void findDbgValues(
- SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V,
- SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords = nullptr);
-
-/// Finds the debug info intrinsics describing a value.
-LLVM_ABI void findDbgUsers(
- SmallVectorImpl<DbgVariableIntrinsic *> &DbgInsts, Value *V,
- SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords = nullptr);
+/// Finds the debug info records describing a value.
+LLVM_ABI void findDbgUsers(Value *V,
+ SmallVectorImpl<DbgVariableRecord *> &DbgVariableRecords);
+/// Finds the dbg.values describing a value.
+LLVM_ABI void findDbgValues(Value *V,
+ SmallVectorImpl<DbgVariableRecord *> &DbgVariableRecords);
/// Find subprogram that is enclosing this scope.
LLVM_ABI DISubprogram *getDISubprogram(const MDNode *Scope);
/// Produce a DebugLoc to use for each dbg.declare that is promoted to a
/// dbg.value.
-LLVM_ABI DebugLoc getDebugValueLoc(DbgVariableIntrinsic *DII);
LLVM_ABI DebugLoc getDebugValueLoc(DbgVariableRecord *DVR);
/// Strip debug info in the module if it exists.
@@ -192,13 +186,6 @@ using AssignmentInstRange =
/// Iterators invalidated by adding or removing DIAssignID metadata to/from any
/// instruction (including by deleting or cloning instructions).
LLVM_ABI AssignmentInstRange getAssignmentInsts(DIAssignID *ID);
-/// Return a range of instructions (typically just one) that perform the
-/// assignment that \p DAI encodes.
-/// Iterators invalidated by adding or removing DIAssignID metadata to/from any
-/// instruction (including by deleting or cloning instructions).
-inline AssignmentInstRange getAssignmentInsts(const DbgAssignIntrinsic *DAI) {
- return getAssignmentInsts(DAI->getAssignID());
-}
inline AssignmentInstRange getAssignmentInsts(const DbgVariableRecord *DVR) {
assert(DVR->isDbgAssign() &&
diff --git a/llvm/include/llvm/Transforms/Utils/Local.h b/llvm/include/llvm/Transforms/Utils/Local.h
index bb79d2568fca0..3f5f4278a2766 100644
--- a/llvm/include/llvm/Transforms/Utils/Local.h
+++ b/llvm/include/llvm/Transforms/Utils/Local.h
@@ -325,7 +325,6 @@ LLVM_ABI void salvageDebugInfo(Instruction &I);
/// Mark undef if salvaging cannot be completed.
LLVM_ABI void
salvageDebugInfoForDbgValues(Instruction &I,
- ArrayRef<DbgVariableIntrinsic *> Insns,
ArrayRef<DbgVariableRecord *> DPInsns);
/// Given an instruction \p I and DIExpression \p DIExpr operating on
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index dc8184394f74d..c21058ca51344 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -3571,9 +3571,7 @@ class TypePromotionTransaction {
}
// Record the debug uses separately. They are not in the instruction's
// use list, but they are replaced by RAUW.
- SmallVector<DbgValueInst *> DbgValues;
- findDbgValues(DbgValues, Inst, &DbgVariableRecords);
- assert(DbgValues.empty());
+ findDbgValues(Inst, DbgVariableRecords);
// Now, we can replace the uses.
Inst->replaceAllUsesWith(New);
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 8fb33c30e5cac..857174ed61cd7 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -45,25 +45,6 @@ using namespace llvm;
using namespace llvm::at;
using namespace llvm::dwarf;
-TinyPtrVector<DbgDeclareInst *> llvm::findDbgDeclares(Value *V) {
- // This function is hot. Check whether the value has any metadata to avoid a
- // DenseMap lookup. This check is a bitfield datamember lookup.
- if (!V->isUsedByMetadata())
- return {};
- auto *L = ValueAsMetadata::getIfExists(V);
- if (!L)
- return {};
- auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L);
- if (!MDV)
- return {};
-
- TinyPtrVector<DbgDeclareInst *> Declares;
- for (User *U : MDV->users())
- if (auto *DDI = dyn_cast<DbgDeclareInst>(U))
- Declares.push_back(DDI);
-
- return Declares;
-}
TinyPtrVector<DbgVariableRecord *> llvm::findDVRDeclares(Value *V) {
// This function is hot. Check whether the value has any metadata to avoid a
// DenseMap lookup. This check is a bitfield datamember lookup.
@@ -98,10 +79,10 @@ TinyPtrVector<DbgVariableRecord *> llvm::findDVRValues(Value *V) {
return Values;
}
-template <typename IntrinsicT, bool DbgAssignAndValuesOnly>
+template <bool DbgAssignAndValuesOnly>
static void
-findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result, Value *V,
- SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords) {
+findDbgIntrinsics(Value *V,
+ SmallVectorImpl<DbgVariableRecord *> &DbgVariableRecords) {
// This function is hot. Check whether the value has any metadata to avoid a
// DenseMap lookup.
if (!V->isUsedByMetadata())
@@ -109,31 +90,21 @@ findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result, Value *V,
LLVMContext &Ctx = V->getContext();
// TODO: If this value appears multiple times in a DIArgList, we should still
- // only add the owning DbgValueInst once; use this set to track ArgListUsers.
+ // only add the owning dbg.value once; use this set to track ArgListUsers.
// This behaviour can be removed when we can automatically remove duplicates.
// V will also appear twice in a dbg.assign if its used in the both the value
// and address components.
- SmallPtrSet<IntrinsicT *, 4> EncounteredIntrinsics;
SmallPtrSet<DbgVariableRecord *, 4> EncounteredDbgVariableRecords;
- /// Append IntrinsicT users of MetadataAsValue(MD).
- auto AppendUsers = [&Ctx, &EncounteredIntrinsics,
- &EncounteredDbgVariableRecords, &Result,
- DbgVariableRecords](Metadata *MD) {
- if (auto *MDV = MetadataAsValue::getIfExists(Ctx, MD)) {
- for (User *U : MDV->users())
- if (IntrinsicT *DVI = dyn_cast<IntrinsicT>(U))
- if (EncounteredIntrinsics.insert(DVI).second)
- Result.push_back(DVI);
- }
- if (!DbgVariableRecords)
- return;
+ /// Append users of MetadataAsValue(MD).
+ auto AppendUsers = [&EncounteredDbgVariableRecords,
+ &DbgVariableRecords](Metadata *MD) {
// Get DbgVariableRecords that use this as a single value.
if (LocalAsMetadata *L = dyn_cast<LocalAsMetadata>(MD)) {
for (DbgVariableRecord *DVR : L->getAllDbgVariableRecordUsers()) {
if (!DbgAssignAndValuesOnly || DVR->isDbgValue() || DVR->isDbgAssign())
if (EncounteredDbgVariableRecords.insert(DVR).second)
- DbgVariableRecords->push_back(DVR);
+ DbgVariableRecords.push_back(DVR);
}
}
};
@@ -142,29 +113,23 @@ findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result, Value *V,
AppendUsers(L);
for (Metadata *AL : L->getAllArgListUsers()) {
AppendUsers(AL);
- if (!DbgVariableRecords)
- continue;
DIArgList *DI = cast<DIArgList>(AL);
for (DbgVariableRecord *DVR : DI->getAllDbgVariableRecordUsers())
if (!DbgAssignAndValuesOnly || DVR->isDbgValue() || DVR->isDbgAssign())
if (EncounteredDbgVariableRecords.insert(DVR).second)
- DbgVariableRecords->push_back(DVR);
+ DbgVariableRecords.push_back(DVR);
}
}
}
-void llvm::findDbgValues(
- SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V,
- SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords) {
- findDbgIntrinsics<DbgValueInst, /*DbgAssignAndValuesOnly=*/true>(
- DbgValues, V, DbgVariableRecords);
+void llvm::findDbgValues(Value *V,
+ SmallVectorImpl<DbgVariableRecord *> &DbgVariableRecords) {
+ findDbgIntrinsics</*DbgAssignAndValuesOnly=*/true>(V, DbgVariableRecords);
}
-void llvm::findDbgUsers(
- SmallVectorImpl<DbgVariableIntrinsic *> &DbgUsers, Value *V,
- SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords) {
- findDbgIntrinsics<DbgVariableIntrinsic, /*DbgAssignAndValuesOnly=*/false>(
- DbgUsers, V, DbgVariableRecords);
+void llvm::findDbgUsers(Value *V,
+ SmallVectorImpl<DbgVariableRecord *> &DbgVariableRecords) {
+ findDbgIntrinsics</*DbgAssignAndValuesOnly=*/false>(V, DbgVariableRecords);
}
DISubprogram *llvm::getDISubprogram(const MDNode *Scope) {
@@ -173,18 +138,6 @@ DISubprogram *llvm::getDISubprogram(const MDNode *Scope) {
return nullptr;
}
-DebugLoc llvm::getDebugValueLoc(DbgVariableIntrinsic *DII) {
- // Original dbg.declare must have a location.
- const DebugLoc &DeclareLoc = DII->getDebugLoc();
- MDNode *Scope = DeclareLoc.getScope();
- DILocation *InlinedAt = DeclareLoc.getInlinedAt();
- // Because no machine insts can come from debug intrinsics, only the scope
- // and inlinedAt is significant. Zero line numbers are used in case this
- // DebugLoc leaks into any adjacent instructions. Produce an unknown location
- // with the correct scope / inlinedAt fields.
- return DILocation::get(DII->getContext(), 0, 0, Scope, InlinedAt);
-}
-
DebugLoc llvm::getDebugValueLoc(DbgVariableRecord *DVR) {
// Original dbg.declare must have a location.
const DebugLoc &DeclareLoc = DVR->getDebugLoc();
@@ -852,19 +805,6 @@ void DebugTypeInfoRemoval::traverse(MDNode *N) {
bool llvm::stripNonLineTableDebugInfo(Module &M) {
bool Changed = false;
- // First off, delete the debug intrinsics.
- auto RemoveUses = [&](StringRef Name) {
- if (auto *DbgVal = M.getFunction(Name)) {
- while (!DbgVal->use_empty())
- cast<Instruction>(DbgVal->user_back())->eraseFromParent();
- DbgVal->eraseFromParent();
- Changed = true;
- }
- };
- RemoveUses("llvm.dbg.declare");
- RemoveUses("llvm.dbg.label");
- RemoveUses("llvm.dbg.value");
-
// Delete non-CU debug info named metadata nodes.
for (auto NMI = M.named_metadata_begin(), NME = M.named_metadata_end();
NMI != NME;) {
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index 02c16e201abe2..5928c89029b87 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -582,16 +582,11 @@ void Value::replaceUsesWithIf(Value *New,
}
}
-/// Replace llvm.dbg.* uses of MetadataAsValue(ValueAsMetadata(V)) outside BB
+/// Replace debug record uses of MetadataAsValue(ValueAsMetadata(V)) outside BB
/// with New.
static void replaceDbgUsesOutsideBlock(Value *V, Value *New, BasicBlock *BB) {
- SmallVector<DbgVariableIntrinsic *> DbgUsers;
SmallVector<DbgVariableRecord *> DPUsers;
- findDbgUsers(DbgUsers, V, &DPUsers);
- for (auto *DVI : DbgUsers) {
- if (DVI->getParent() != BB)
- DVI->replaceVariableLocationOp(V, New);
- }
+ findDbgUsers(V, DPUsers);
for (auto *DVR : DPUsers) {
DbgMarker *Marker = DVR->getMarker();
if (Marker->getParent() != BB)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
index 359e992d61580..304e91ec184f1 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
@@ -1583,9 +1583,8 @@ void SplitPtrStructs::killAndReplaceSplitInstructions(
if (!SplitUsers.contains(I))
continue;
- SmallVector<DbgValueInst *> DIs;
SmallVector<DbgVariableRecord *> Dbgs;
- findDbgValues(DIs, I, &Dbgs);
+ findDbgValues(I, Dbgs);
for (DbgVariableRecord *Dbg : Dbgs) {
auto &DL = I->getDataLayout();
assert(isSplitFatPtr(I->getType()) &&
diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
index a65d0fb54c212..332050860e05b 100644
--- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
@@ -553,7 +553,6 @@ static void cacheDIVar(FrameDataInfo &FrameData,
if (I != Container.end())
DIVarCache.insert({V, (*I)->getVariable()});
};
- CacheIt(findDbgDeclares(V));
CacheIt(findDVRDeclares(V));
}
}
@@ -1219,10 +1218,8 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
auto *G = GetFramePointer(Alloca);
G->setName(Alloca->getName() + Twine(".reload.addr"));
- SmallVector<DbgVariableIntrinsic *, 4> DIs;
SmallVector<DbgVariableRecord *> DbgVariableRecords;
- findDbgUsers(DIs, Alloca, &DbgVariableRecords);
- assert(DIs.empty() && "Should never see debug-intrinsics");
+ findDbgUsers(Alloca, DbgVariableRecords);
for (auto *DVR : DbgVariableRecords)
DVR->replaceVariableLocationOp(Alloca, G);
diff --git a/llvm/lib/Transforms/Coroutines/SpillUtils.cpp b/llvm/lib/Transforms/Coroutines/SpillUtils.cpp
index 5fd5f7d9dad09..4e717685555b5 100644
--- a/llvm/lib/Transforms/Coroutines/SpillUtils.cpp
+++ b/llvm/lib/Transforms/Coroutines/SpillUtils.cpp
@@ -519,10 +519,8 @@ void collectSpillsFromDbgInfo(SpillInfo &Spills, Function &F,
// We would handle the dbg.values for allocas specially
for (auto &Iter : Spills) {
auto *V = Iter.first;
- SmallVector<DbgValueInst *, 16> DVIs;
SmallVector<DbgVariableRecord *, 16> DVRs;
- findDbgValues(DVIs, V, &DVRs);
- assert(DVIs.empty());
+ findDbgValues(V, DVRs);
// Add the instructions which carry debug info that is in the frame.
for (DbgVariableRecord *DVR : DVRs)
if (Checker.isDefinitionAcrossSuspend(*V, DVR->Marker->MarkedInstr))
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 98ba367954066..e2a9255ca9c6e 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1463,10 +1463,8 @@ void InstCombinerImpl::freelyInvertAllUsersOf(Value *I, Value *IgnoredUser) {
}
// Update pre-existing debug value uses.
- SmallVector<DbgValueInst *, 4> DbgValues;
SmallVector<DbgVariableRecord *, 4> DbgVariableRecords;
- llvm::findDbgValues(DbgValues, I, &DbgVariableRecords);
- assert(DbgValues.empty());
+ llvm::findDbgValues(I, DbgVariableRecords);
for (DbgVariableRecord *DbgVal : DbgVariableRecords) {
SmallVector<uint64_t, 1> Ops = {dwarf::DW_OP_not};
@@ -3611,12 +3609,10 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
// If we are removing an alloca with a dbg.declare, insert dbg.value calls
// before each store.
- SmallVector<DbgVariableIntrinsic *, 8> DVIs;
SmallVector<DbgVariableRecord *, 8> DVRs;
std::unique_ptr<DIBuilder> DIB;
if (isa<AllocaInst>(MI)) {
- findDbgUsers(DVIs, &MI, &DVRs);
- assert(DVIs.empty());
+ findDbgUsers(&MI, DVRs);
DIB.reset(new DIBuilder(*MI.getModule(), /*AllowUnresolved=*/false));
}
@@ -3738,9 +3734,6 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
//
// FIXME: the Assignment Tracking project has now likely made this
// redundant (and it's sometimes harmful).
- for (auto *DVI : DVIs)
- if (DVI->isAddressOfVariable() || DVI->getExpression()->startsWithDeref())
- DVI->eraseFromParent();
for (auto *DVR : DVRs)
if (DVR->isAddressOfVariable() || DVR->getExpression()->startsWithDeref())
DVR->eraseFromParent();
@@ -5292,10 +5285,8 @@ bool InstCombinerImpl::tryToSinkInstruction(Instruction *I,
// maximise the range variables have location for. If we cannot salvage, then
// mark the location undef: we know it was supposed to receive a new location
// here, but that computation has been sunk.
- SmallVector<DbgVariableIntrinsic *, 2> DbgUsers;
SmallVector<DbgVariableRecord *, 2> DbgVariableRecords;
- findDbgUsers(DbgUsers, I, &DbgVariableRecords);
- assert(DbgUsers.empty());
+ findDbgUsers(I, DbgVariableRecords);
if (!DbgVariableRecords.empty())
tryToSinkInstructionDbgVariableRecords(I, InsertPos, SrcBlock, DestBlock,
DbgVariableRecords);
@@ -5422,7 +5413,7 @@ void InstCombinerImpl::tryToSinkInstructionDbgVariableRecords(
if (DVRClones.empty())
return;
- salvageDebugInfoForDbgValues(*I, {}, DbgVariableRecordsToSalvage);
+ salvageDebugInfoForDbgValues(*I, DbgVariableRecordsToSalvage);
// The clones are in reverse order of original appearance. Assert that the
// head bit is set on the iterator as we _should_ have received it via
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index df3160233c510..1ddb8ae9518fc 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -1486,10 +1486,8 @@ static bool checkAndReplaceCondition(
// Update the debug value records that satisfy the same condition used
// in replaceUsesWithIf.
- SmallVector<DbgVariableIntrinsic *> DbgUsers;
SmallVector<DbgVariableRecord *> DVRUsers;
- findDbgUsers(DbgUsers, Cmp, &DVRUsers);
- assert(DbgUsers.empty());
+ findDbgUsers(Cmp, DVRUsers);
for (auto *DVR : DVRUsers) {
auto *DTN = DT.getNode(DVR->getParent());
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index 4d1f44076db7e..c2a737d8f9a4a 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -1960,7 +1960,6 @@ void JumpThreadingPass::updateSSA(BasicBlock *BB, BasicBlock *NewBB,
// PHI insertion, of which we are prepared to do, clean these up now.
SSAUpdater SSAUpdate;
SmallVector<Use *, 16> UsesToRename;
- SmallVector<DbgValueInst *, 4> DbgValues;
SmallVector<DbgVariableRecord *, 4> DbgVariableRecords;
for (Instruction &I : *BB) {
@@ -1978,8 +1977,7 @@ void JumpThreadingPass::updateSSA(BasicBlock *BB, BasicBlock *NewBB,
}
// Find debug values outside of the block
- findDbgValues(DbgValues, &I, &DbgVariableRecords);
- assert(DbgValues.empty());
+ findDbgValues(&I, DbgVariableRecords);
llvm::erase_if(DbgVariableRecords, [&](const DbgVariableRecord *DbgVarRec) {
return DbgVarRec->getParent() == BB;
});
@@ -2000,7 +1998,6 @@ void JumpThreadingPass::updateSSA(BasicBlock *BB, BasicBlock *NewBB,
SSAUpdate.RewriteUse(*UsesToRename.pop_back_val());
if (!DbgVariableRecords.empty()) {
SSAUpdate.UpdateDebugValues(&I, DbgVariableRecords);
- DbgValues.clear();
DbgVariableRecords.clear();
}
diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp
index 323bd74fb625d..6a3f65614d310 100644
--- a/llvm/lib/Transforms/Scalar/NewGVN.cpp
+++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp
@@ -4078,12 +4078,9 @@ bool NewGVN::eliminateInstructions(Function &F) {
if (!match(DefI, m_Intrinsic<Intrinsic::ssa_copy>()))
patchReplacementInstruction(DefI, DominatingLeader);
- SmallVector<DbgVariableIntrinsic *> DbgUsers;
SmallVector<DbgVariableRecord *> DVRUsers;
- findDbgUsers(DbgUsers, DefI, &DVRUsers);
+ findDbgUsers(DefI, DVRUsers);
- for (auto *DVI : DbgUsers)
- DVI->replaceVariableLocationOp(DefI, DominatingLeader);
for (auto *DVR : DVRUsers)
DVR->replaceVariableLocationOp(DefI, DominatingLeader);
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index 1d1af42153325..7a9dd37b72205 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -1219,10 +1219,8 @@ void CodeExtractor::calculateNewCallTerminatorWeights(
/// \p F.
static void eraseDebugIntrinsicsWithNonLocalRefs(Function &F) {
for (Instruction &I : instructions(F)) {
- SmallVector<DbgVariableIntrinsic *, 4> DbgUsers;
SmallVector<DbgVariableRecord *, 4> DbgVariableRecords;
- findDbgUsers(DbgUsers, &I, &DbgVariableRecords);
- assert(DbgUsers.empty());
+ findDbgUsers(&I, DbgVariableRecords);
for (DbgVariableRecord *DVR : DbgVariableRecords)
if (DVR->getFunction() != &F)
DVR->eraseFromParent();
@@ -1284,10 +1282,8 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
NewFunc.getEntryBlock().getTerminator()->getIterator());
};
for (auto [Input, NewVal] : zip_equal(Inputs, NewValues)) {
- SmallVector<DbgVariableIntrinsic *, 1> DbgUsers;
SmallVector<DbgVariableRecord *, 1> DPUsers;
- findDbgUsers(DbgUsers, Input, &DPUsers);
- assert(DbgUsers.empty());
+ findDbgUsers(Input, DPUsers);
DIExpression *Expr = DIB.createExpression();
// Iterate the debud users of the Input values. If they are in the extracted
diff --git a/llvm/lib/Transforms/Utils/LCSSA.cpp b/llvm/lib/Transforms/Utils/LCSSA.cpp
index c3c3cdf50a985..8d18c755d04c4 100644
--- a/llvm/lib/Transforms/Utils/LCSSA.cpp
+++ b/llvm/lib/Transforms/Utils/LCSSA.cpp
@@ -243,26 +243,10 @@ formLCSSAForInstructionsImpl(SmallVectorImpl<Instruction *> &Worklist,
SSAUpdate.RewriteUse(*UseToRewrite);
}
- SmallVector<DbgValueInst *, 4> DbgValues;
SmallVector<DbgVariableRecord *, 4> DbgVariableRecords;
- llvm::findDbgValues(DbgValues, I, &DbgVariableRecords);
+ llvm::findDbgValues(I, DbgVariableRecords);
// Update pre-existing debug value uses that reside outside the loop.
- for (auto *DVI : DbgValues) {
- BasicBlock *UserBB = DVI->getParent();
- if (InstBB == UserBB || L->contains(UserBB))
- continue;
- // We currently only handle debug values residing in blocks that were
- // traversed while rewriting the uses. If we inserted just a single PHI,
- // we will handle all relevant debug values.
- Value *V = AddedPHIs.size() == 1 ? AddedPHIs[0]
- : SSAUpdate.FindValueForBlock(UserBB);
- if (V)
- DVI->replaceVariableLocationOp(I, V);
- }
-
- // RemoveDIs: copy-paste of block above, using non-instruction debug-info
- // records.
for (DbgVariableRecord *DVR : DbgVariableRecords) {
BasicBlock *UserBB = DVR->getMarker()->getParent();
if (InstBB == UserBB || L->contains(UserBB))
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 7f0c23bd24efb..4414341942418 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -610,10 +610,8 @@ void llvm::RecursivelyDeleteTriviallyDeadInstructions(
}
bool llvm::replaceDbgUsesWithUndef(Instruction *I) {
- SmallVector<DbgVariableIntrinsic *, 1> DbgUsers;
SmallVector<DbgVariableRecord *, 1> DPUsers;
- findDbgUsers(DbgUsers, I, &DPUsers);
- assert(DbgUsers.empty());
+ findDbgUsers(I, DPUsers);
for (auto *DVR : DPUsers)
DVR->setKillLocation();
return !DPUsers.empty();
@@ -1603,10 +1601,8 @@ static bool PhiHasDebugValue(DILocalVariable *DIVar,
// Since we can't guarantee that the original dbg.declare intrinsic
// is removed by LowerDbgDeclare(), we need to make sure that we are
// not inserting the same dbg.value intrinsic over and over.
- SmallVector<DbgValueInst *, 1> DbgValues;
SmallVector<DbgVariableRecord *, 1> DbgVariableRecords;
- findDbgValues(DbgValues, APN, &DbgVariableRecords);
- assert(DbgValues.empty());
+ findDbgValues(APN, DbgVariableRecords);
for (DbgVariableRecord *DVR : DbgVariableRecords) {
assert(is_contained(DVR->location_ops(), APN));
if ((DVR->getVariable() == DIVar) && (DVR->getExpression() == DIExpr))
@@ -1987,10 +1983,8 @@ static void updateOneDbgValueForAlloca(const DebugLoc &Loc,
void llvm::replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
DIBuilder &Builder, int Offset) {
- SmallVector<DbgValueInst *, 1> DbgUsers;
SmallVector<DbgVariableRecord *, 1> DPUsers;
- findDbgValues(DbgUsers, AI, &DPUsers);
- assert(DbgUsers.empty());
+ findDbgValues(AI, DPUsers);
// Replace any DbgVariableRecords that use this alloca.
for (DbgVariableRecord *DVR : DPUsers)
@@ -2002,11 +1996,9 @@ void llvm::replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
/// Where possible to salvage debug information for \p I do so.
/// If not possible mark undef.
void llvm::salvageDebugInfo(Instruction &I) {
- SmallVector<DbgVariableIntrinsic *, 1> DbgUsers;
SmallVector<DbgVariableRecord *, 1> DPUsers;
- findDbgUsers(DbgUsers, &I, &DPUsers);
- assert(DbgUsers.empty());
- salvageDebugInfoForDbgValues(I, DbgUsers, DPUsers);
+ findDbgUsers(&I, DPUsers);
+ salvageDebugInfoForDbgValues(I, DPUsers);
}
template <typename T> static void salvageDbgAssignAddress(T *Assign) {
@@ -2045,8 +2037,7 @@ template <typename T> static void salvageDbgAssignAddress(T *Assign) {
}
void llvm::salvageDebugInfoForDbgValues(
- Instruction &I, ArrayRef<DbgVariableIntrinsic *> DbgUsers,
- ArrayRef<DbgVariableRecord *> DPUsers) {
+ Instruction &I, ArrayRef<DbgVariableRecord *> DPUsers) {
// These are arbitrary chosen limits on the maximum number of values and the
// maximum size of a debug expression we can salvage up to, used for
// performance reasons.
@@ -2054,9 +2045,6 @@ void llvm::salvageDebugInfoForDbgValues(
const unsigned MaxExpressionSize = 128;
bool Salvaged = false;
- // We should never see debug intrinsics nowadays.
- assert(DbgUsers.empty());
-
for (auto *DVR : DPUsers) {
if (DVR->isDbgAssign()) {
if (DVR->getAddress() == &I) {
@@ -2343,16 +2331,11 @@ static bool rewriteDebugUsers(
Instruction &From, Value &To, Instruction &DomPoint, DominatorTree &DT,
function_ref<DbgValReplacement(DbgVariableRecord &DVR)> RewriteDVRExpr) {
// Find debug users of From.
- SmallVector<DbgVariableIntrinsic *, 1> Users;
SmallVector<DbgVariableRecord *, 1> DPUsers;
- findDbgUsers(Users, &From, &DPUsers);
- if (Users.empty() && DPUsers.empty())
+ findDbgUsers(&From, DPUsers);
+ if (DPUsers.empty())
return false;
- // Ignore intrinsic-users: they are no longer supported and should never
- // appear.
- assert(Users.empty());
-
// Prevent use-before-def of To.
bool Changed = false;
@@ -3356,10 +3339,8 @@ void llvm::copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI,
}
void llvm::dropDebugUsers(Instruction &I) {
- SmallVector<DbgVariableIntrinsic *, 1> DbgUsers;
SmallVector<DbgVariableRecord *, 1> DPUsers;
- findDbgUsers(DbgUsers, &I, &DPUsers);
- assert(DbgUsers.empty());
+ findDbgUsers(&I, DPUsers);
for (auto *DVR : DPUsers)
DVR->eraseFromParent();
}
diff --git a/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp b/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
index 06115e0741ade..7cc9ff8b11139 100644
--- a/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
@@ -158,10 +158,8 @@ static void RewriteUsesOfClonedInstructions(BasicBlock *OrigHeader,
// Replace MetadataAsValue(ValueAsMetadata(OrigHeaderVal)) uses in debug
// intrinsics.
- SmallVector<DbgValueInst *, 1> DbgValues;
SmallVector<DbgVariableRecord *, 1> DbgVariableRecords;
- llvm::findDbgValues(DbgValues, OrigHeaderVal, &DbgVariableRecords);
- assert(DbgValues.empty());
+ llvm::findDbgValues(OrigHeaderVal, DbgVariableRecords);
for (DbgVariableRecord *DVR : DbgVariableRecords) {
// The original users in the OrigHeader are already using the original
diff --git a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
index 8f55d7bbd3182..27439319da147 100644
--- a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
+++ b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
@@ -319,9 +319,9 @@ void MemoryOpRemark::visitVariable(const Value *V,
// If we find some information in the debug info, take that.
bool FoundDI = false;
- // Try to get an llvm.dbg.declare, which has a DILocalVariable giving us the
+ // Try to get a dbg.declare, which has a DILocalVariable giving us the
// real debug info name and size of the variable.
- auto FindDI = [&](const auto *DVI) {
+ auto FindDI = [&](const DbgVariableRecord *DVI) {
if (DILocalVariable *DILV = DVI->getVariable()) {
std::optional<uint64_t> DISize = getSizeInBytes(DILV->getSizeInBits());
VariableInfo Var{DILV->getName(), DISize};
@@ -331,7 +331,6 @@ void MemoryOpRemark::visitVariable(const Value *V,
}
}
};
- for_each(findDbgDeclares(const_cast<Value *>(V)), FindDI);
for_each(findDVRDeclares(const_cast<Value *>(V)), FindDI);
if (FoundDI) {
diff --git a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index 73b5f48796b7a..d96f1d6c23d47 100644
--- a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -243,10 +243,8 @@ struct AllocaInfo {
OnlyUsedInOneBlock = false;
}
}
- SmallVector<DbgVariableIntrinsic *> AllDbgUsers;
SmallVector<DbgVariableRecord *> AllDPUsers;
- findDbgUsers(AllDbgUsers, AI, &AllDPUsers);
- assert(AllDbgUsers.empty());
+ findDbgUsers(AI, AllDPUsers);
std::copy_if(AllDPUsers.begin(), AllDPUsers.end(),
std::back_inserter(DPUsers),
[](DbgVariableRecord *DVR) { return !DVR->isDbgAssign(); });
diff --git a/llvm/lib/Transforms/Utils/SSAUpdater.cpp b/llvm/lib/Transforms/Utils/SSAUpdater.cpp
index 561c898ec55d8..49d0d9584347e 100644
--- a/llvm/lib/Transforms/Utils/SSAUpdater.cpp
+++ b/llvm/lib/Transforms/Utils/SSAUpdater.cpp
@@ -197,10 +197,8 @@ void SSAUpdater::RewriteUse(Use &U) {
}
void SSAUpdater::UpdateDebugValues(Instruction *I) {
- SmallVector<DbgValueInst *, 4> DbgValues;
SmallVector<DbgVariableRecord *, 4> DbgVariableRecords;
- llvm::findDbgValues(DbgValues, I, &DbgVariableRecords);
- assert(DbgValues.empty());
+ llvm::findDbgValues(I, DbgVariableRecords);
for (auto &DVR : DbgVariableRecords) {
if (DVR->getParent() == I->getParent())
continue;
diff --git a/llvm/unittests/IR/DebugInfoTest.cpp b/llvm/unittests/IR/DebugInfoTest.cpp
index baa13e1199eea..0065615cbfe13 100644
--- a/llvm/unittests/IR/DebugInfoTest.cpp
+++ b/llvm/unittests/IR/DebugInfoTest.cpp
@@ -185,10 +185,8 @@ TEST(MetadataTest, DeleteInstUsedByDbgRecord) {
Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHIIt();
// Find the dbg.value using %b.
- SmallVector<DbgValueInst *, 1> DVIs;
SmallVector<DbgVariableRecord *, 1> DVRs;
- findDbgValues(DVIs, &I, &DVRs);
- assert(DVIs.empty());
+ findDbgValues(&I, DVRs);
// Delete %b. The dbg.value should now point to undef.
I.eraseFromParent();
@@ -230,7 +228,6 @@ TEST(MetadataTest, GlobalConstantMetadataUsedByDbgRecord) {
Value *V = M->getNamedValue("x");
// Find the dbg.value
- auto DVIs = findDbgDeclares(V);
auto DVRs = findDVRDeclares(V);
auto DVRVs = findDVRValues(V);
@@ -312,10 +309,8 @@ TEST(MetadataTest, DeleteInstUsedByDbgVariableRecord) {
Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHIIt();
// Find the DbgVariableRecords using %b.
- SmallVector<DbgValueInst *, 2> DVIs;
SmallVector<DbgVariableRecord *, 2> DVRs;
- findDbgValues(DVIs, &I, &DVRs);
- assert(DVIs.empty());
+ findDbgValues(&I, DVRs);
ASSERT_EQ(DVRs.size(), 2u);
// Delete %b. The DbgVariableRecord should now point to undef.
@@ -359,11 +354,9 @@ TEST(MetadataTest, OrderingOfDbgVariableRecords) {
Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHIIt();
- SmallVector<DbgValueInst *, 2> DVIs;
SmallVector<DbgVariableRecord *, 2> DVRs;
- findDbgValues(DVIs, &I, &DVRs);
- ASSERT_EQ(DVIs.size(), 0u);
+ findDbgValues(&I, DVRs);
ASSERT_EQ(DVRs.size(), 2u);
// The correct order of dbg.values is given by their use-list, which becomes
diff --git a/llvm/unittests/Transforms/Utils/LocalTest.cpp b/llvm/unittests/Transforms/Utils/LocalTest.cpp
index dd2a6249c7cf9..0c70feb64e7e4 100644
--- a/llvm/unittests/Transforms/Utils/LocalTest.cpp
+++ b/llvm/unittests/Transforms/Utils/LocalTest.cpp
@@ -673,20 +673,17 @@ TEST(Local, FindDbgRecords) {
Function &Fun = *cast<Function>(M->getNamedValue("fun"));
Value *Arg = Fun.getArg(0);
- SmallVector<DbgVariableIntrinsic *> Users;
SmallVector<DbgVariableRecord *> Records;
// Arg (%a) is used twice by a single dbg_assign. Check findDbgUsers returns
// only 1 pointer to it rather than 2.
- findDbgUsers(Users, Arg, &Records);
- EXPECT_EQ(Users.size(), 0u);
+ findDbgUsers(Arg, Records);
EXPECT_EQ(Records.size(), 1u);
SmallVector<DbgValueInst *> Vals;
Records.clear();
// Arg (%a) is used twice by a single dbg_assign. Check findDbgValues returns
// only 1 pointer to it rather than 2.
- findDbgValues(Vals, Arg, &Records);
- EXPECT_EQ(Vals.size(), 0u);
+ findDbgValues(Arg, Records);
EXPECT_EQ(Records.size(), 1u);
}
@@ -787,20 +784,16 @@ TEST(Local, ReplaceAllDbgUsesWith) {
// Simulate i32* <-> i64* conversion.
EXPECT_TRUE(replaceAllDbgUsesWith(D, C, C, DT));
- SmallVector<DbgVariableIntrinsic *, 2> CDbgVals;
SmallVector<DbgVariableRecord *, 2> CDbgRecords;
- findDbgUsers(CDbgVals, &C, &CDbgRecords);
- EXPECT_EQ(0U, CDbgVals.size());
+ findDbgUsers(&C, CDbgRecords);
EXPECT_EQ(2U, CDbgRecords.size());
EXPECT_TRUE(all_of(
CDbgRecords, [](DbgVariableRecord *DVR) { return DVR->isDbgDeclare(); }));
EXPECT_TRUE(replaceAllDbgUsesWith(C, D, D, DT));
- SmallVector<DbgVariableIntrinsic *, 2> DDbgVals;
SmallVector<DbgVariableRecord *, 2> DDbgRecords;
- findDbgUsers(DDbgVals, &D, &DDbgRecords);
- EXPECT_EQ(0U, DDbgVals.size());
+ findDbgUsers(&D, DDbgRecords);
EXPECT_EQ(2U, DDbgRecords.size());
EXPECT_TRUE(all_of(
DDbgRecords, [](DbgVariableRecord *DVR) { return DVR->isDbgDeclare(); }));
@@ -824,10 +817,8 @@ TEST(Local, ReplaceAllDbgUsesWith) {
EXPECT_EQ(BarrierDbgVal->getNumVariableLocationOps(), 1u);
EXPECT_TRUE(BarrierDbgVal->isKillLocation());
- SmallVector<DbgValueInst *, 1> BarrierDbgVals;
SmallVector<DbgVariableRecord *, 8> BarrierDbgRecs;
- findDbgValues(BarrierDbgVals, &F_, &BarrierDbgRecs);
- EXPECT_EQ(0U, BarrierDbgVals.size());
+ findDbgValues(&F_, BarrierDbgRecs);
EXPECT_EQ(0U, BarrierDbgRecs.size());
// Simulate i32 -> i64 conversion to test sign-extension. Here are some
@@ -838,10 +829,8 @@ TEST(Local, ReplaceAllDbgUsesWith) {
// 4-6) like (1-3), but with a fragment
EXPECT_TRUE(replaceAllDbgUsesWith(B, A, A, DT));
- SmallVector<DbgValueInst *, 8> BDbgVals;
SmallVector<DbgVariableRecord *, 8> BDbgRecs;
- findDbgValues(BDbgVals, &A, &BDbgRecs);
- EXPECT_EQ(0U, BDbgVals.size());
+ findDbgValues(&A, BDbgRecs);
EXPECT_EQ(6U, BDbgRecs.size());
// Check that %a has a dbg.value with a DIExpression matching \p Ops.
More information about the llvm-commits
mailing list