From 991fd0959c85723f6719a3a82fa358e1bff087d0 Mon Sep 17 00:00:00 2001 From: OCHyams Date: Mon, 11 Dec 2023 17:50:41 +0000 Subject: [PATCH] [NFC] Change findDbg interface Use return values rather than out-parameters, and rename FindDbgDeclareUses to findDbgDeclares. See #73498. --- llvm/include/llvm/IR/DebugInfo.h | 10 +-- llvm/lib/CodeGen/CodeGenPrepare.cpp | 3 +- llvm/lib/IR/DebugInfo.cpp | 65 +++++++++++-------- llvm/lib/IR/Value.cpp | 7 +- llvm/lib/Transforms/Coroutines/CoroFrame.cpp | 16 ++--- .../InstCombine/InstructionCombining.cpp | 6 +- llvm/lib/Transforms/Scalar/JumpThreading.cpp | 3 +- llvm/lib/Transforms/Scalar/SROA.cpp | 6 +- llvm/lib/Transforms/Utils/CodeExtractor.cpp | 7 +- llvm/lib/Transforms/Utils/LCSSA.cpp | 8 +-- llvm/lib/Transforms/Utils/Local.cpp | 43 ++++-------- .../Transforms/Utils/LoopRotationUtils.cpp | 7 +- llvm/lib/Transforms/Utils/MemoryOpRemark.cpp | 2 +- .../Utils/PromoteMemoryToRegister.cpp | 3 +- llvm/lib/Transforms/Utils/SSAUpdater.cpp | 7 +- llvm/unittests/IR/DebugInfoTest.cpp | 17 ++--- llvm/unittests/Transforms/Utils/LocalTest.cpp | 23 ++----- 17 files changed, 98 insertions(+), 135 deletions(-) diff --git a/llvm/include/llvm/IR/DebugInfo.h b/llvm/include/llvm/IR/DebugInfo.h index 2a581eb5f09d9..db5aaf0f7f26b 100644 --- a/llvm/include/llvm/IR/DebugInfo.h +++ b/llvm/include/llvm/IR/DebugInfo.h @@ -40,15 +40,15 @@ class Module; /// Finds dbg.declare intrinsics declaring local variables as living in the /// memory that 'V' points to. -TinyPtrVector FindDbgDeclareUses(Value *V); +TinyPtrVector findDbgDeclares(Value *V); /// Finds the llvm.dbg.value intrinsics describing a value. -void findDbgValues(SmallVectorImpl &DbgValues, - Value *V, SmallVectorImpl *DPValues = nullptr); +SmallVector findDbgValues(Value *V); +SmallVector findDPValues(Value *V); /// Finds the debug info intrinsics describing a value. -void findDbgUsers(SmallVectorImpl &DbgInsts, - Value *V, SmallVectorImpl *DPValues = nullptr); +SmallVector findDbgUsers(Value *V); +SmallVector findDPVUsers(Value *V); /// Find subprogram that is enclosing this scope. DISubprogram *getDISubprogram(const MDNode *Scope); diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index aa5cdd2e04a99..4e03b5a99939a 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -3098,7 +3098,8 @@ class TypePromotionTransaction { } // Record the debug uses separately. They are not in the instruction's // use list, but they are replaced by RAUW. - findDbgValues(DbgValues, Inst, &DPValues); + DbgValues = findDbgValues(Inst); + DPValues = findDPValues(Inst); // Now, we can replace the uses. Inst->replaceAllUsesWith(New); diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 3fe940e19295b..3f8578a3b1166 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -44,7 +44,7 @@ using namespace llvm; using namespace llvm::at; using namespace llvm::dwarf; -TinyPtrVector llvm::FindDbgDeclareUses(Value *V) { +TinyPtrVector llvm::findDbgDeclares(Value *V) { // This function is hot. Check whether the value has any metadata to avoid a // DenseMap lookup. if (!V->isUsedByMetadata()) @@ -66,12 +66,12 @@ TinyPtrVector llvm::FindDbgDeclareUses(Value *V) { } template -static void findDbgIntrinsics(SmallVectorImpl &Result, - Value *V, SmallVectorImpl *DPValues) { +static SmallVector findDbgIntrinsics(Value *V) { + SmallVector Result; // This function is hot. Check whether the value has any metadata to avoid a // DenseMap lookup. if (!V->isUsedByMetadata()) - return; + return Result; LLVMContext &Ctx = V->getContext(); // TODO: If this value appears multiple times in a DIArgList, we should still @@ -80,51 +80,62 @@ static void findDbgIntrinsics(SmallVectorImpl &Result, // V will also appear twice in a dbg.assign if its used in the both the value // and address components. SmallPtrSet EncounteredIntrinsics; - SmallPtrSet EncounteredDPValues; /// Append IntrinsicT users of MetadataAsValue(MD). - auto AppendUsers = [&Ctx, &EncounteredIntrinsics, &Result, - DPValues](Metadata *MD) { + auto AppendUsers = [&Ctx, &EncounteredIntrinsics, &Result](Metadata *MD) { if (auto *MDV = MetadataAsValue::getIfExists(Ctx, MD)) { for (User *U : MDV->users()) if (IntrinsicT *DVI = dyn_cast(U)) if (EncounteredIntrinsics.insert(DVI).second) Result.push_back(DVI); } - if (!DPValues) - return; - // Get DPValues that use this as a single value. - if (LocalAsMetadata *L = dyn_cast(MD)) { - for (DPValue *DPV : L->getAllDPValueUsers()) { - if (DPV->getType() == DPValue::LocationType::Value) - DPValues->push_back(DPV); - } - } }; if (auto *L = LocalAsMetadata::getIfExists(V)) { AppendUsers(L); for (Metadata *AL : L->getAllArgListUsers()) { AppendUsers(AL); - if (!DPValues) - continue; - DIArgList *DI = cast(AL); - for (DPValue *DPV : DI->getAllDPValueUsers()) + } + } + return Result; +} + +static SmallVector findDbgRecords(Value *V) { + SmallVector Result; + // This function is hot. Check whether the value has any metadata to avoid a + // DenseMap lookup. + if (!V->isUsedByMetadata()) + return Result; + + // 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. + // 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 EncounteredDPValues; + + if (auto *L = LocalAsMetadata::getIfExists(V)) { + for (DPValue *DPV : L->getAllDPValueUsers()) { + if (DPV->getType() == DPValue::LocationType::Value) + Result.push_back(DPV); + } + + for (Metadata *AL : L->getAllArgListUsers()) { + for (DPValue *DPV : cast(AL)->getAllDPValueUsers()) if (DPV->getType() == DPValue::LocationType::Value) if (EncounteredDPValues.insert(DPV).second) - DPValues->push_back(DPV); + Result.push_back(DPV); } } + return Result; } -void llvm::findDbgValues(SmallVectorImpl &DbgValues, - Value *V, SmallVectorImpl *DPValues) { - findDbgIntrinsics(DbgValues, V, DPValues); +SmallVector llvm::findDbgValues(Value *V) { + return findDbgIntrinsics(V); } -void llvm::findDbgUsers(SmallVectorImpl &DbgUsers, - Value *V, SmallVectorImpl *DPValues) { - findDbgIntrinsics(DbgUsers, V, DPValues); +SmallVector llvm::findDbgUsers(Value *V) { + return findDbgIntrinsics(V); } DISubprogram *llvm::getDISubprogram(const MDNode *Scope) { diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index b6e25c46b514d..be09daf170fb8 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -573,14 +573,11 @@ void Value::replaceUsesWithIf(Value *New, /// Replace llvm.dbg.* uses of MetadataAsValue(ValueAsMetadata(V)) outside BB /// with New. static void replaceDbgUsesOutsideBlock(Value *V, Value *New, BasicBlock *BB) { - SmallVector DbgUsers; - SmallVector DPUsers; - findDbgUsers(DbgUsers, V, &DPUsers); - for (auto *DVI : DbgUsers) { + for (auto *DVI : findDbgUsers(V)) { if (DVI->getParent() != BB) DVI->replaceVariableLocationOp(V, New); } - for (auto *DPV : DPUsers) { + for (DPValue *DPV : findDPVUsers(V)) { DPMarker *Marker = DPV->getMarker(); if (Marker->getParent() != BB) DPV->replaceVariableLocationOp(V, New); diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp index 1134b20880f18..71d15efe283b2 100644 --- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp @@ -963,7 +963,7 @@ static void cacheDIVar(FrameDataInfo &FrameData, if (DIVarCache.contains(V)) continue; - auto DDIs = FindDbgDeclareUses(V); + auto DDIs = findDbgDeclares(V); auto *I = llvm::find_if(DDIs, [](DbgDeclareInst *DDI) { return DDI->getExpression()->getNumElements() == 0; }); @@ -1119,7 +1119,7 @@ static void buildFrameDebugInfo(Function &F, coro::Shape &Shape, assert(PromiseAlloca && "Coroutine with switch ABI should own Promise alloca"); - TinyPtrVector DIs = FindDbgDeclareUses(PromiseAlloca); + TinyPtrVector DIs = findDbgDeclares(PromiseAlloca); if (DIs.empty()) return; @@ -1840,7 +1840,7 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) { FrameTy->getElementType(FrameData.getFieldIndex(E.first)), GEP, SpillAlignment, E.first->getName() + Twine(".reload")); - TinyPtrVector DIs = FindDbgDeclareUses(Def); + TinyPtrVector DIs = findDbgDeclares(Def); // Try best to find dbg.declare. If the spill is a temp, there may not // be a direct dbg.declare. Walk up the load chain to find one from an // alias. @@ -1854,7 +1854,7 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) { CurDef = LdInst->getPointerOperand(); if (!isa(CurDef)) break; - DIs = FindDbgDeclareUses(CurDef); + DIs = findDbgDeclares(CurDef); } } @@ -1938,9 +1938,7 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) { auto *G = GetFramePointer(Alloca); G->setName(Alloca->getName() + Twine(".reload.addr")); - SmallVector DIs; - findDbgUsers(DIs, Alloca); - for (auto *DVI : DIs) + for (auto *DVI : findDbgUsers(Alloca)) DVI->replaceUsesOfWith(Alloca, G); for (Instruction *I : UsersToUpdate) { @@ -3082,9 +3080,7 @@ void coro::buildCoroutineFrame( // We would handle the dbg.values for allocas specially for (auto &Iter : FrameData.Spills) { auto *V = Iter.first; - SmallVector DVIs; - findDbgValues(DVIs, V); - for (DbgValueInst *DVI : DVIs) + for (DbgValueInst *DVI : findDbgValues(V)) if (Checker.isDefinitionAcrossSuspend(*V, DVI)) FrameData.Spills[V].push_back(DVI); } diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index f072f5cec3094..4a1f799a4a21f 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2679,7 +2679,8 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) { SmallVector DPVs; std::unique_ptr DIB; if (isa(MI)) { - findDbgUsers(DVIs, &MI, &DPVs); + DVIs = findDbgUsers(&MI); + DPVs = findDPVUsers(&MI); DIB.reset(new DIBuilder(*MI.getModule(), /*AllowUnresolved=*/false)); } @@ -4076,8 +4077,7 @@ 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 DbgUsers; - findDbgUsers(DbgUsers, I); + SmallVector DbgUsers = findDbgUsers(I); // For all debug values in the destination block, the sunk instruction // will still be available, so they do not need to be dropped. diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index 8603c5cf9c022..61aa2da911d4d 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -1972,10 +1972,11 @@ void JumpThreadingPass::updateSSA( } // Find debug values outside of the block - findDbgValues(DbgValues, &I, &DPValues); + DbgValues = findDbgValues(&I); llvm::erase_if(DbgValues, [&](const DbgValueInst *DbgVal) { return DbgVal->getParent() == BB; }); + DPValues = findDPValues(&I); llvm::erase_if(DPValues, [&](const DPValue *DPVal) { return DPVal->getParent() == BB; }); diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp index f578762d2b497..d703d61c48354 100644 --- a/llvm/lib/Transforms/Scalar/SROA.cpp +++ b/llvm/lib/Transforms/Scalar/SROA.cpp @@ -4940,7 +4940,7 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) { // Migrate debug information from the old alloca to the new alloca(s) // and the individual partitions. TinyPtrVector DbgVariables; - for (auto *DbgDeclare : FindDbgDeclareUses(&AI)) + for (auto *DbgDeclare : findDbgDeclares(&AI)) DbgVariables.push_back(DbgDeclare); for (auto *DbgAssign : at::getAssignmentMarkers(&AI)) DbgVariables.push_back(DbgAssign); @@ -4997,7 +4997,7 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) { // Remove any existing intrinsics on the new alloca describing // the variable fragment. - for (DbgDeclareInst *OldDII : FindDbgDeclareUses(Fragment.Alloca)) { + for (DbgDeclareInst *OldDII : findDbgDeclares(Fragment.Alloca)) { auto SameVariableFragment = [](const DbgVariableIntrinsic *LHS, const DbgVariableIntrinsic *RHS) { return LHS->getVariable() == RHS->getVariable() && @@ -5147,7 +5147,7 @@ bool SROA::deleteDeadInstructions( // not be able to find it. if (AllocaInst *AI = dyn_cast(I)) { DeletedAllocas.insert(AI); - for (DbgDeclareInst *OldDII : FindDbgDeclareUses(AI)) + for (DbgDeclareInst *OldDII : findDbgDeclares(AI)) OldDII->eraseFromParent(); } diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp index 9c1186232e024..fa5b33ebbdd40 100644 --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -1506,13 +1506,10 @@ void CodeExtractor::calculateNewCallTerminatorWeights( /// \p F. static void eraseDebugIntrinsicsWithNonLocalRefs(Function &F) { for (Instruction &I : instructions(F)) { - SmallVector DbgUsers; - SmallVector DPValues; - findDbgUsers(DbgUsers, &I, &DPValues); - for (DbgVariableIntrinsic *DVI : DbgUsers) + for (DbgVariableIntrinsic *DVI : findDbgUsers(&I)) if (DVI->getFunction() != &F) DVI->eraseFromParent(); - for (DPValue *DPV : DPValues) + for (DPValue *DPV : findDPVUsers(&I)) if (DPV->getFunction() != &F) DPV->eraseFromParent(); } diff --git a/llvm/lib/Transforms/Utils/LCSSA.cpp b/llvm/lib/Transforms/Utils/LCSSA.cpp index 5e0c312fe149e..22bcaf36e54bb 100644 --- a/llvm/lib/Transforms/Utils/LCSSA.cpp +++ b/llvm/lib/Transforms/Utils/LCSSA.cpp @@ -241,12 +241,8 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl &Worklist, SSAUpdate.RewriteUse(*UseToRewrite); } - SmallVector DbgValues; - SmallVector DPValues; - llvm::findDbgValues(DbgValues, I, &DPValues); - // Update pre-existing debug value uses that reside outside the loop. - for (auto *DVI : DbgValues) { + for (auto *DVI : llvm::findDbgValues(I)) { BasicBlock *UserBB = DVI->getParent(); if (InstBB == UserBB || L->contains(UserBB)) continue; @@ -261,7 +257,7 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl &Worklist, // RemoveDIs: copy-paste of block above, using non-instruction debug-info // records. - for (DPValue *DPV : DPValues) { + for (DPValue *DPV : llvm::findDPValues(I)) { BasicBlock *UserBB = DPV->getMarker()->getParent(); if (InstBB == UserBB || L->contains(UserBB)) continue; diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 51f39e0ba0cce..d8438446cd8fc 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -608,12 +608,11 @@ void llvm::RecursivelyDeleteTriviallyDeadInstructions( } bool llvm::replaceDbgUsesWithUndef(Instruction *I) { - SmallVector DbgUsers; - SmallVector DPUsers; - findDbgUsers(DbgUsers, I, &DPUsers); - for (auto *DII : DbgUsers) + SmallVector DbgUsers = findDbgUsers(I); + SmallVector DPUsers = findDPVUsers(I); + for (auto *DII : findDbgUsers(I)) DII->setKillLocation(); - for (auto *DPV : DPUsers) + for (auto *DPV : findDPVUsers(I)) DPV->setKillLocation(); return !DbgUsers.empty() || !DPUsers.empty(); } @@ -1569,15 +1568,12 @@ 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 DbgValues; - SmallVector DPValues; - findDbgValues(DbgValues, APN, &DPValues); - for (auto *DVI : DbgValues) { + for (auto *DVI : findDbgValues(APN)) { assert(is_contained(DVI->getValues(), APN)); if ((DVI->getVariable() == DIVar) && (DVI->getExpression() == DIExpr)) return true; } - for (auto *DPV : DPValues) { + for (DPValue *DPV : findDPValues(APN)) { assert(is_contained(DPV->location_ops(), APN)); if ((DPV->getVariable() == DIVar) && (DPV->getExpression() == DIExpr)) return true; @@ -2103,7 +2099,7 @@ void llvm::insertDebugValuesForPHIs(BasicBlock *BB, bool llvm::replaceDbgDeclare(Value *Address, Value *NewAddress, DIBuilder &Builder, uint8_t DIExprFlags, int Offset) { - auto DbgDeclares = FindDbgDeclareUses(Address); + auto DbgDeclares = findDbgDeclares(Address); for (DbgVariableIntrinsic *DII : DbgDeclares) { const DebugLoc &Loc = DII->getDebugLoc(); auto *DIVar = DII->getVariable(); @@ -2148,18 +2144,14 @@ static void updateOneDbgValueForAlloca(const DebugLoc &Loc, void llvm::replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress, DIBuilder &Builder, int Offset) { - SmallVector DbgUsers; - SmallVector DPUsers; - findDbgValues(DbgUsers, AI, &DPUsers); - // Attempt to replace dbg.values that use this alloca. - for (auto *DVI : DbgUsers) + for (auto *DVI : findDbgValues(AI)) updateOneDbgValueForAlloca(DVI->getDebugLoc(), DVI->getVariable(), DVI->getExpression(), NewAllocaAddress, DVI, nullptr, Builder, Offset); // Replace any DPValues that use this alloca. - for (DPValue *DPV : DPUsers) + for (DPValue *DPV : findDPValues(AI)) updateOneDbgValueForAlloca(DPV->getDebugLoc(), DPV->getVariable(), DPV->getExpression(), NewAllocaAddress, nullptr, DPV, Builder, Offset); @@ -2168,10 +2160,7 @@ 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 DbgUsers; - SmallVector DPUsers; - findDbgUsers(DbgUsers, &I, &DPUsers); - salvageDebugInfoForDbgValues(I, DbgUsers, DPUsers); + salvageDebugInfoForDbgValues(I, findDbgUsers(&I), findDPVUsers(&I)); } /// Salvage the address component of \p DAI. @@ -2557,9 +2546,8 @@ static bool rewriteDebugUsers( function_ref RewriteExpr, function_ref RewriteDPVExpr) { // Find debug users of From. - SmallVector Users; - SmallVector DPUsers; - findDbgUsers(Users, &From, &DPUsers); + SmallVector Users = findDbgUsers(&From); + SmallVector DPUsers = findDPVUsers(&From); if (Users.empty() && DPUsers.empty()) return false; @@ -3497,12 +3485,9 @@ void llvm::copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, } void llvm::dropDebugUsers(Instruction &I) { - SmallVector DbgUsers; - SmallVector DPUsers; - findDbgUsers(DbgUsers, &I, &DPUsers); - for (auto *DII : DbgUsers) + for (auto *DII : findDbgUsers(&I)) DII->eraseFromParent(); - for (auto *DPV : DPUsers) + for (auto *DPV : findDPVUsers(&I)) DPV->eraseFromParent(); } diff --git a/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp b/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp index 76280ed492b3d..92a2e3ce64130 100644 --- a/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp @@ -158,10 +158,7 @@ static void RewriteUsesOfClonedInstructions(BasicBlock *OrigHeader, // Replace MetadataAsValue(ValueAsMetadata(OrigHeaderVal)) uses in debug // intrinsics. - SmallVector DbgValues; - SmallVector DPValues; - llvm::findDbgValues(DbgValues, OrigHeaderVal, &DPValues); - for (auto &DbgValue : DbgValues) { + for (auto &DbgValue : llvm::findDbgValues(OrigHeaderVal)) { // The original users in the OrigHeader are already using the original // definitions. BasicBlock *UserBB = DbgValue->getParent(); @@ -184,7 +181,7 @@ static void RewriteUsesOfClonedInstructions(BasicBlock *OrigHeader, // RemoveDIs: duplicate implementation for non-instruction debug-info // storage in DPValues. - for (DPValue *DPV : DPValues) { + for (DPValue *DPV : llvm::findDPValues(OrigHeaderVal)) { // The original users in the OrigHeader are already using the original // definitions. BasicBlock *UserBB = DPV->getMarker()->getParent(); diff --git a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp index 531b0a624dafa..f61bf43069726 100644 --- a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp +++ b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp @@ -322,7 +322,7 @@ void MemoryOpRemark::visitVariable(const Value *V, // Try to get an llvm.dbg.declare, which has a DILocalVariable giving us the // real debug info name and size of the variable. for (const DbgVariableIntrinsic *DVI : - FindDbgDeclareUses(const_cast(V))) { + findDbgDeclares(const_cast(V))) { if (DILocalVariable *DILV = DVI->getVariable()) { std::optional DISize = getSizeInBytes(DILV->getSizeInBits()); VariableInfo Var{DILV->getName(), DISize}; diff --git a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp index 717b6d301c8c9..2370b8980e201 100644 --- a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -228,8 +228,7 @@ struct AllocaInfo { OnlyUsedInOneBlock = false; } } - DbgUserVec AllDbgUsers; - findDbgUsers(AllDbgUsers, AI, &DPUsers); + DbgUserVec AllDbgUsers = findDbgUsers(AI); std::copy_if(AllDbgUsers.begin(), AllDbgUsers.end(), std::back_inserter(DbgUsers), [](DbgVariableIntrinsic *DII) { return !isa(DII); diff --git a/llvm/lib/Transforms/Utils/SSAUpdater.cpp b/llvm/lib/Transforms/Utils/SSAUpdater.cpp index fc21fb552137d..fd18102ad50e9 100644 --- a/llvm/lib/Transforms/Utils/SSAUpdater.cpp +++ b/llvm/lib/Transforms/Utils/SSAUpdater.cpp @@ -198,15 +198,12 @@ void SSAUpdater::RewriteUse(Use &U) { } void SSAUpdater::UpdateDebugValues(Instruction *I) { - SmallVector DbgValues; - SmallVector DPValues; - llvm::findDbgValues(DbgValues, I, &DPValues); - for (auto &DbgValue : DbgValues) { + for (auto *DbgValue : llvm::findDbgValues(I)) { if (DbgValue->getParent() == I->getParent()) continue; UpdateDebugValue(I, DbgValue); } - for (auto &DPV : DPValues) { + for (DPValue *DPV : llvm::findDPValues(I)) { if (DPV->getParent() == I->getParent()) continue; UpdateDebugValue(I, DPV); diff --git a/llvm/unittests/IR/DebugInfoTest.cpp b/llvm/unittests/IR/DebugInfoTest.cpp index be8f590a27eb4..61dda54aaab58 100644 --- a/llvm/unittests/IR/DebugInfoTest.cpp +++ b/llvm/unittests/IR/DebugInfoTest.cpp @@ -184,8 +184,7 @@ TEST(MetadataTest, DeleteInstUsedByDbgValue) { Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHI(); // Find the dbg.value using %b. - SmallVector DVIs; - findDbgValues(DVIs, &I); + SmallVector DVIs = findDbgValues(&I); // Delete %b. The dbg.value should now point to undef. I.eraseFromParent(); @@ -268,9 +267,7 @@ TEST(MetadataTest, DeleteInstUsedByDPValue) { M->convertToNewDbgValues(); // Find the DPValues using %b. - SmallVector DVIs; - SmallVector DPVs; - findDbgValues(DVIs, &I, &DPVs); + SmallVector DPVs = findDPValues(&I); ASSERT_EQ(DPVs.size(), 2u); // Delete %b. The DPValue should now point to undef. @@ -318,9 +315,8 @@ TEST(MetadataTest, OrderingOfDPValues) { UseNewDbgInfoFormat = true; Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHI(); - SmallVector DVIs; - SmallVector DPVs; - findDbgValues(DVIs, &I, &DPVs); + SmallVector DVIs = findDbgValues(&I); + SmallVector DPVs = findDPValues(&I); ASSERT_EQ(DVIs.size(), 2u); ASSERT_EQ(DPVs.size(), 0u); @@ -333,10 +329,9 @@ TEST(MetadataTest, OrderingOfDPValues) { EXPECT_TRUE(Var1->getName() == "foo"); // Now try again, but in DPValue form. - DVIs.clear(); - M->convertToNewDbgValues(); - findDbgValues(DVIs, &I, &DPVs); + DVIs = findDbgValues(&I); + DPVs = findDPValues(&I); ASSERT_EQ(DVIs.size(), 0u); ASSERT_EQ(DPVs.size(), 2u); diff --git a/llvm/unittests/Transforms/Utils/LocalTest.cpp b/llvm/unittests/Transforms/Utils/LocalTest.cpp index 8225774104575..dde29d78a4883 100644 --- a/llvm/unittests/Transforms/Utils/LocalTest.cpp +++ b/llvm/unittests/Transforms/Utils/LocalTest.cpp @@ -719,17 +719,13 @@ TEST(Local, FindDbgUsers) { Function &Fun = *cast(M->getNamedValue("fun")); Value *Arg = Fun.getArg(0); - SmallVector Users; // Arg (%a) is used twice by a single dbg.assign. Check findDbgUsers returns // only 1 pointer to it rather than 2. - findDbgUsers(Users, Arg); - EXPECT_EQ(Users.size(), 1u); + EXPECT_EQ(findDbgUsers(Arg).size(), 1u); - SmallVector Vals; // Arg (%a) is used twice by a single dbg.assign. Check findDbgValues returns // only 1 pointer to it rather than 2. - findDbgValues(Vals, Arg); - EXPECT_EQ(Vals.size(), 1u); + EXPECT_EQ(findDbgValues(Arg).size(), 1u); } TEST(Local, ReplaceAllDbgUsesWith) { @@ -833,8 +829,7 @@ TEST(Local, ReplaceAllDbgUsesWith) { // Simulate i32* <-> i64* conversion. EXPECT_TRUE(replaceAllDbgUsesWith(D, C, C, DT)); - SmallVector CDbgVals; - findDbgUsers(CDbgVals, &C); + SmallVector CDbgVals = findDbgUsers(&C); EXPECT_EQ(2U, CDbgVals.size()); EXPECT_TRUE(all_of(CDbgVals, [](DbgVariableIntrinsic *DII) { return isa(DII); @@ -842,8 +837,7 @@ TEST(Local, ReplaceAllDbgUsesWith) { EXPECT_TRUE(replaceAllDbgUsesWith(C, D, D, DT)); - SmallVector DDbgVals; - findDbgUsers(DDbgVals, &D); + SmallVector DDbgVals = findDbgUsers(&D); EXPECT_EQ(2U, DDbgVals.size()); EXPECT_TRUE(all_of(DDbgVals, [](DbgVariableIntrinsic *DII) { return isa(DII); @@ -863,9 +857,7 @@ TEST(Local, ReplaceAllDbgUsesWith) { EXPECT_EQ(FDbgVal->getNumVariableLocationOps(), 1u); EXPECT_TRUE(FDbgVal->isKillLocation()); - SmallVector FDbgVals; - findDbgValues(FDbgVals, &F_); - EXPECT_EQ(0U, FDbgVals.size()); + EXPECT_EQ(0U, findDbgValues(&F).size()); // Simulate i32 -> i64 conversion to test sign-extension. Here are some // interesting cases to handle: @@ -875,9 +867,8 @@ TEST(Local, ReplaceAllDbgUsesWith) { // 4-6) like (1-3), but with a fragment EXPECT_TRUE(replaceAllDbgUsesWith(B, A, A, DT)); - SmallVector ADbgVals; - findDbgValues(ADbgVals, &A); - EXPECT_EQ(6U, ADbgVals.size()); + SmallVector ADbgVals = findDbgValues(&A); + EXPECT_EQ(6U, findDbgValues(&A).size()); // Check that %a has a dbg.value with a DIExpression matching \p Ops. auto hasADbgVal = [&](ArrayRef Ops) {