diff --git a/llvm/include/llvm/IR/DebugInfo.h b/llvm/include/llvm/IR/DebugInfo.h index 77cee875f16e7..f8241a3cdf160 100644 --- a/llvm/include/llvm/IR/DebugInfo.h +++ b/llvm/include/llvm/IR/DebugInfo.h @@ -115,8 +115,7 @@ class DebugInfoFinder { LLVM_ABI void processVariable(DILocalVariable *DVI); /// Process debug info location. LLVM_ABI void processLocation(const Module &M, const DILocation *Loc); - /// Process a DbgRecord (e.g, treat a DbgVariableRecord like a - /// DbgVariableIntrinsic). + /// Process a DbgRecord. LLVM_ABI void processDbgRecord(const Module &M, const DbgRecord &DR); /// Process subprogram. @@ -290,8 +289,6 @@ struct VarRecord { DILocalVariable *Var; DILocation *DL; - VarRecord(DbgVariableIntrinsic *DVI) - : Var(DVI->getVariable()), DL(getDebugValueLoc(DVI)) {} VarRecord(DbgVariableRecord *DVR) : Var(DVR->getVariable()), DL(getDebugValueLoc(DVR)) {} VarRecord(DILocalVariable *Var, DILocation *DL) : Var(Var), DL(DL) {} diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h index 9345f95015301..f1f0c18949c35 100644 --- a/llvm/include/llvm/IR/DebugInfoMetadata.h +++ b/llvm/include/llvm/IR/DebugInfoMetadata.h @@ -66,7 +66,6 @@ namespace dwarf { enum Tag : uint16_t; } -class DbgVariableIntrinsic; class DbgVariableRecord; LLVM_ABI extern cl::opt EnableFSDiscriminator; @@ -4613,7 +4612,6 @@ class DebugVariable { LLVM_ABI static const FragmentInfo DefaultFragment; public: - LLVM_ABI DebugVariable(const DbgVariableIntrinsic *DII); LLVM_ABI DebugVariable(const DbgVariableRecord *DVR); DebugVariable(const DILocalVariable *Var, @@ -4681,7 +4679,6 @@ template <> struct DenseMapInfo { /// information). class DebugVariableAggregate : public DebugVariable { public: - LLVM_ABI DebugVariableAggregate(const DbgVariableIntrinsic *DVI); DebugVariableAggregate(const DebugVariable &V) : DebugVariable(V.getVariable(), std::nullopt, V.getInlinedAt()) {} }; diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 84a56058de834..8fb33c30e5cac 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -2288,39 +2288,36 @@ bool AssignmentTrackingPass::runOnFunction(Function &F) { // Collect a map of {backing storage : dbg.declares} (currently "backing // storage" is limited to Allocas). We'll use this to find dbg.declares to // delete after running `trackAssignments`. - DenseMap> DbgDeclares; DenseMap> DVRDeclares; // Create another similar map of {storage : variables} that we'll pass to // trackAssignments. StorageToVarsMap Vars; - auto ProcessDeclare = [&](auto *Declare, auto &DeclareList) { + auto ProcessDeclare = [&](DbgVariableRecord &Declare) { // FIXME: trackAssignments doesn't let you specify any modifiers to the // variable (e.g. fragment) or location (e.g. offset), so we have to // leave dbg.declares with non-empty expressions in place. - if (Declare->getExpression()->getNumElements() != 0) + if (Declare.getExpression()->getNumElements() != 0) return; - if (!Declare->getAddress()) + if (!Declare.getAddress()) return; if (AllocaInst *Alloca = - dyn_cast(Declare->getAddress()->stripPointerCasts())) { + dyn_cast(Declare.getAddress()->stripPointerCasts())) { // FIXME: Skip VLAs for now (let these variables use dbg.declares). if (!Alloca->isStaticAlloca()) return; // Similarly, skip scalable vectors (use dbg.declares instead). if (auto Sz = Alloca->getAllocationSize(*DL); Sz && Sz->isScalable()) return; - DeclareList[Alloca].insert(Declare); - Vars[Alloca].insert(VarRecord(Declare)); + DVRDeclares[Alloca].insert(&Declare); + Vars[Alloca].insert(VarRecord(&Declare)); } }; for (auto &BB : F) { for (auto &I : BB) { for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) { if (DVR.isDbgDeclare()) - ProcessDeclare(&DVR, DVRDeclares); + ProcessDeclare(DVR); } - if (DbgDeclareInst *DDI = dyn_cast(&I)) - ProcessDeclare(DDI, DbgDeclares); } } @@ -2336,8 +2333,8 @@ bool AssignmentTrackingPass::runOnFunction(Function &F) { trackAssignments(F.begin(), F.end(), Vars, *DL); // Delete dbg.declares for variables now tracked with assignment tracking. - auto DeleteSubsumedDeclare = [&](const auto &Markers, auto &Declares) { - (void)Markers; + for (auto &[Insts, Declares] : DVRDeclares) { + auto Markers = at::getDVRAssignmentMarkers(Insts); for (auto *Declare : Declares) { // Assert that the alloca that Declare uses is now linked to a dbg.assign // describing the same variable (i.e. check that this dbg.declare has @@ -2356,10 +2353,6 @@ bool AssignmentTrackingPass::runOnFunction(Function &F) { Changed = true; } }; - for (auto &P : DbgDeclares) - DeleteSubsumedDeclare(at::getAssignmentMarkers(P.first), P.second); - for (auto &P : DVRDeclares) - DeleteSubsumedDeclare(at::getDVRAssignmentMarkers(P.first), P.second); return Changed; } diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp index 2270923bd3719..f16963dce56e1 100644 --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -49,20 +49,11 @@ uint32_t DIType::getAlignInBits() const { const DIExpression::FragmentInfo DebugVariable::DefaultFragment = { std::numeric_limits::max(), std::numeric_limits::min()}; -DebugVariable::DebugVariable(const DbgVariableIntrinsic *DII) - : Variable(DII->getVariable()), - Fragment(DII->getExpression()->getFragmentInfo()), - InlinedAt(DII->getDebugLoc().getInlinedAt()) {} - DebugVariable::DebugVariable(const DbgVariableRecord *DVR) : Variable(DVR->getVariable()), Fragment(DVR->getExpression()->getFragmentInfo()), InlinedAt(DVR->getDebugLoc().getInlinedAt()) {} -DebugVariableAggregate::DebugVariableAggregate(const DbgVariableIntrinsic *DVI) - : DebugVariable(DVI->getVariable(), std::nullopt, - DVI->getDebugLoc()->getInlinedAt()) {} - DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line, unsigned Column, uint64_t AtomGroup, uint8_t AtomRank, ArrayRef MDs, bool ImplicitCode) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index 9d7c025ccff86..f7fbf0815df03 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -825,9 +825,6 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final Value *EvaluateInDifferentType(Value *V, Type *Ty, bool isSigned); bool tryToSinkInstruction(Instruction *I, BasicBlock *DestBlock); - void tryToSinkInstructionDbgValues( - Instruction *I, BasicBlock::iterator InsertPos, BasicBlock *SrcBlock, - BasicBlock *DestBlock, SmallVectorImpl &DbgUsers); void tryToSinkInstructionDbgVariableRecords( Instruction *I, BasicBlock::iterator InsertPos, BasicBlock *SrcBlock, BasicBlock *DestBlock, SmallVectorImpl &DPUsers); diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 684b9a1f90161..a8bfd8c072d2f 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -3575,6 +3575,7 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) { std::unique_ptr DIB; if (isa(MI)) { findDbgUsers(DVIs, &MI, &DVRs); + assert(DVIs.empty()); DIB.reset(new DIBuilder(*MI.getModule(), /*AllowUnresolved=*/false)); } @@ -5253,8 +5254,7 @@ bool InstCombinerImpl::tryToSinkInstruction(Instruction *I, SmallVector DbgUsers; SmallVector DbgVariableRecords; findDbgUsers(DbgUsers, I, &DbgVariableRecords); - if (!DbgUsers.empty()) - tryToSinkInstructionDbgValues(I, InsertPos, SrcBlock, DestBlock, DbgUsers); + assert(DbgUsers.empty()); if (!DbgVariableRecords.empty()) tryToSinkInstructionDbgVariableRecords(I, InsertPos, SrcBlock, DestBlock, DbgVariableRecords); @@ -5271,71 +5271,12 @@ bool InstCombinerImpl::tryToSinkInstruction(Instruction *I, return true; } -void InstCombinerImpl::tryToSinkInstructionDbgValues( - Instruction *I, BasicBlock::iterator InsertPos, BasicBlock *SrcBlock, - BasicBlock *DestBlock, SmallVectorImpl &DbgUsers) { - // For all debug values in the destination block, the sunk instruction - // will still be available, so they do not need to be dropped. - SmallVector DbgUsersToSalvage; - for (auto &DbgUser : DbgUsers) - if (DbgUser->getParent() != DestBlock) - DbgUsersToSalvage.push_back(DbgUser); - - // Process the sinking DbgUsersToSalvage in reverse order, as we only want - // to clone the last appearing debug intrinsic for each given variable. - SmallVector DbgUsersToSink; - for (DbgVariableIntrinsic *DVI : DbgUsersToSalvage) - if (DVI->getParent() == SrcBlock) - DbgUsersToSink.push_back(DVI); - llvm::sort(DbgUsersToSink, - [](auto *A, auto *B) { return B->comesBefore(A); }); - - SmallVector DIIClones; - SmallSet SunkVariables; - for (auto *User : DbgUsersToSink) { - // A dbg.declare instruction should not be cloned, since there can only be - // one per variable fragment. It should be left in the original place - // because the sunk instruction is not an alloca (otherwise we could not be - // here). - if (isa(User)) - continue; - - DebugVariable DbgUserVariable = - DebugVariable(User->getVariable(), User->getExpression(), - User->getDebugLoc()->getInlinedAt()); - - if (!SunkVariables.insert(DbgUserVariable).second) - continue; - - // Leave dbg.assign intrinsics in their original positions and there should - // be no need to insert a clone. - if (isa(User)) - continue; - - DIIClones.emplace_back(cast(User->clone())); - if (isa(User) && isa(I)) - DIIClones.back()->replaceVariableLocationOp(I, I->getOperand(0)); - LLVM_DEBUG(dbgs() << "CLONE: " << *DIIClones.back() << '\n'); - } - - // Perform salvaging without the clones, then sink the clones. - if (!DIIClones.empty()) { - salvageDebugInfoForDbgValues(*I, DbgUsersToSalvage, {}); - // The clones are in reverse order of original appearance, reverse again to - // maintain the original order. - for (auto &DIIClone : llvm::reverse(DIIClones)) { - DIIClone->insertBefore(InsertPos); - LLVM_DEBUG(dbgs() << "SINK: " << *DIIClone << '\n'); - } - } -} - void InstCombinerImpl::tryToSinkInstructionDbgVariableRecords( Instruction *I, BasicBlock::iterator InsertPos, BasicBlock *SrcBlock, BasicBlock *DestBlock, SmallVectorImpl &DbgVariableRecords) { - // Implementation of tryToSinkInstructionDbgValues, but for the - // DbgVariableRecord of variable assignments rather than dbg.values. + // For all debug values in the destination block, the sunk instruction + // will still be available, so they do not need to be dropped. // Fetch all DbgVariableRecords not already in the destination. SmallVector DbgVariableRecordsToSalvage; diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp index 2786d81773ed9..df3160233c510 100644 --- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp +++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp @@ -1489,6 +1489,7 @@ static bool checkAndReplaceCondition( SmallVector DbgUsers; SmallVector DVRUsers; findDbgUsers(DbgUsers, Cmp, &DVRUsers); + assert(DbgUsers.empty()); for (auto *DVR : DVRUsers) { auto *DTN = DT.getNode(DVR->getParent()); diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp index eacaf42e4e8ba..1d1af42153325 100644 --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -1222,9 +1222,7 @@ static void eraseDebugIntrinsicsWithNonLocalRefs(Function &F) { SmallVector DbgUsers; SmallVector DbgVariableRecords; findDbgUsers(DbgUsers, &I, &DbgVariableRecords); - for (DbgVariableIntrinsic *DVI : DbgUsers) - if (DVI->getFunction() != &F) - DVI->eraseFromParent(); + assert(DbgUsers.empty()); for (DbgVariableRecord *DVR : DbgVariableRecords) if (DVR->getFunction() != &F) DVR->eraseFromParent(); @@ -1289,14 +1287,12 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc, SmallVector DbgUsers; SmallVector DPUsers; findDbgUsers(DbgUsers, Input, &DPUsers); + assert(DbgUsers.empty()); DIExpression *Expr = DIB.createExpression(); // Iterate the debud users of the Input values. If they are in the extracted // function then update their location with the new value. If they are in // the parent function then create a similar debug record. - for (auto *DVI : DbgUsers) - UpdateOrInsertDebugRecord(DVI, Input, NewVal, Expr, - isa(DVI)); for (auto *DVR : DPUsers) UpdateOrInsertDebugRecord(DVR, Input, NewVal, Expr, DVR->isDbgDeclare()); } diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index 6929d14bc56ea..ed3dca2f7c307 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1978,14 +1978,13 @@ static at::StorageToVarsMap collectEscapedLocals(const DataLayout &DL, continue; // Find all local variables associated with the backing storage. - auto CollectAssignsForStorage = [&](auto *DbgAssign) { + auto CollectAssignsForStorage = [&](DbgVariableRecord *DbgAssign) { // Skip variables from inlined functions - they are not local variables. if (DbgAssign->getDebugLoc().getInlinedAt()) return; LLVM_DEBUG(errs() << " > DEF : " << *DbgAssign << "\n"); EscapedLocals[Base].insert(at::VarRecord(DbgAssign)); }; - for_each(at::getAssignmentMarkers(Base), CollectAssignsForStorage); for_each(at::getDVRAssignmentMarkers(Base), CollectAssignsForStorage); } return EscapedLocals; diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index b14bbeac97675..ee3e56c3c6db9 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -613,11 +613,10 @@ bool llvm::replaceDbgUsesWithUndef(Instruction *I) { SmallVector DbgUsers; SmallVector DPUsers; findDbgUsers(DbgUsers, I, &DPUsers); - for (auto *DII : DbgUsers) - DII->setKillLocation(); + assert(DbgUsers.empty()); for (auto *DVR : DPUsers) DVR->setKillLocation(); - return !DbgUsers.empty() || !DPUsers.empty(); + return !DPUsers.empty(); } /// areAllUsesEqual - Check whether the uses of a value are all the same. @@ -2022,6 +2021,7 @@ void llvm::salvageDebugInfo(Instruction &I) { SmallVector DbgUsers; SmallVector DPUsers; findDbgUsers(DbgUsers, &I, &DPUsers); + assert(DbgUsers.empty()); salvageDebugInfoForDbgValues(I, DbgUsers, DPUsers); } @@ -2070,66 +2070,9 @@ void llvm::salvageDebugInfoForDbgValues( const unsigned MaxExpressionSize = 128; bool Salvaged = false; - for (auto *DII : DbgUsers) { - if (auto *DAI = dyn_cast(DII)) { - if (DAI->getAddress() == &I) { - salvageDbgAssignAddress(DAI); - Salvaged = true; - } - if (DAI->getValue() != &I) - continue; - } - - // Do not add DW_OP_stack_value for DbgDeclare, because they are implicitly - // pointing out the value as a DWARF memory location description. - bool StackValue = isa(DII); - auto DIILocation = DII->location_ops(); - assert( - is_contained(DIILocation, &I) && - "DbgVariableIntrinsic must use salvaged instruction as its location"); - SmallVector AdditionalValues; - // `I` may appear more than once in DII's location ops, and each use of `I` - // must be updated in the DIExpression and potentially have additional - // values added; thus we call salvageDebugInfoImpl for each `I` instance in - // DIILocation. - Value *Op0 = nullptr; - DIExpression *SalvagedExpr = DII->getExpression(); - auto LocItr = find(DIILocation, &I); - while (SalvagedExpr && LocItr != DIILocation.end()) { - SmallVector Ops; - unsigned LocNo = std::distance(DIILocation.begin(), LocItr); - uint64_t CurrentLocOps = SalvagedExpr->getNumLocationOperands(); - Op0 = salvageDebugInfoImpl(I, CurrentLocOps, Ops, AdditionalValues); - if (!Op0) - break; - SalvagedExpr = - DIExpression::appendOpsToArg(SalvagedExpr, Ops, LocNo, StackValue); - LocItr = std::find(++LocItr, DIILocation.end(), &I); - } - // salvageDebugInfoImpl should fail on examining the first element of - // DbgUsers, or none of them. - if (!Op0) - break; + // We should never see debug intrinsics nowadays. + assert(DbgUsers.empty()); - SalvagedExpr = SalvagedExpr->foldConstantMath(); - DII->replaceVariableLocationOp(&I, Op0); - bool IsValidSalvageExpr = SalvagedExpr->getNumElements() <= MaxExpressionSize; - if (AdditionalValues.empty() && IsValidSalvageExpr) { - DII->setExpression(SalvagedExpr); - } else if (isa(DII) && IsValidSalvageExpr && - DII->getNumVariableLocationOps() + AdditionalValues.size() <= - MaxDebugArgs) { - DII->addVariableLocationOps(AdditionalValues, SalvagedExpr); - } else { - // Do not salvage using DIArgList for dbg.declare, as it is not currently - // supported in those instructions. Also do not salvage if the resulting - // DIArgList would contain an unreasonably large number of values. - DII->setKillLocation(); - } - LLVM_DEBUG(dbgs() << "SALVAGE: " << *DII << '\n'); - Salvaged = true; - } - // Duplicate of above block for DbgVariableRecords. for (auto *DVR : DPUsers) { if (DVR->isDbgAssign()) { if (DVR->getAddress() == &I) { @@ -2198,9 +2141,6 @@ void llvm::salvageDebugInfoForDbgValues( if (Salvaged) return; - for (auto *DII : DbgUsers) - DII->setKillLocation(); - for (auto *DVR : DPUsers) DVR->setKillLocation(); } @@ -3429,8 +3369,7 @@ void llvm::dropDebugUsers(Instruction &I) { SmallVector DbgUsers; SmallVector DPUsers; findDbgUsers(DbgUsers, &I, &DPUsers); - for (auto *DII : DbgUsers) - DII->eraseFromParent(); + assert(DbgUsers.empty()); for (auto *DVR : DPUsers) DVR->eraseFromParent(); } diff --git a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp index ccd7ee360e014..73b5f48796b7a 100644 --- a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -190,7 +190,6 @@ class AssignmentTrackingInfo { }; struct AllocaInfo { - using DbgUserVec = SmallVector; using DPUserVec = SmallVector; SmallVector DefiningBlocks; @@ -201,7 +200,6 @@ struct AllocaInfo { bool OnlyUsedInOneBlock; /// Debug users of the alloca - does not include dbg.assign intrinsics. - DbgUserVec DbgUsers; DPUserVec DPUsers; /// Helper to update assignment tracking debug info. AssignmentTrackingInfo AssignmentTracking; @@ -212,7 +210,6 @@ struct AllocaInfo { OnlyStore = nullptr; OnlyBlock = nullptr; OnlyUsedInOneBlock = true; - DbgUsers.clear(); DPUsers.clear(); AssignmentTracking.clear(); } @@ -246,13 +243,10 @@ struct AllocaInfo { OnlyUsedInOneBlock = false; } } - DbgUserVec AllDbgUsers; + SmallVector AllDbgUsers; SmallVector AllDPUsers; findDbgUsers(AllDbgUsers, AI, &AllDPUsers); - std::copy_if(AllDbgUsers.begin(), AllDbgUsers.end(), - std::back_inserter(DbgUsers), [](DbgVariableIntrinsic *DII) { - return !isa(DII); - }); + assert(AllDbgUsers.empty()); std::copy_if(AllDPUsers.begin(), AllDPUsers.end(), std::back_inserter(DPUsers), [](DbgVariableRecord *DVR) { return !DVR->isDbgAssign(); }); @@ -380,10 +374,9 @@ struct PromoteMem2Reg { /// to. DenseMap PhiToAllocaMap; - /// For each alloca, we keep track of the dbg.declare intrinsic that + /// For each alloca, we keep track of the dbg.declare record that /// describes it, if any, so that we can convert it to a dbg.value - /// intrinsic if the alloca gets promoted. - SmallVector AllocaDbgUsers; + /// record if the alloca gets promoted. SmallVector AllocaDPUsers; /// For each alloca, keep an instance of a helper class that gives us an easy @@ -741,14 +734,11 @@ promoteSingleBlockAlloca(AllocaInst *AI, const AllocaInfo &Info, AI->eraseFromParent(); // The alloca's debuginfo can be removed as well. - auto DbgUpdateForAlloca = [&](auto &Container) { - for (auto *DbgItem : Container) - if (DbgItem->isAddressOfVariable() || - DbgItem->getExpression()->startsWithDeref()) - DbgItem->eraseFromParent(); - }; - DbgUpdateForAlloca(Info.DbgUsers); - DbgUpdateForAlloca(Info.DPUsers); + for (DbgVariableRecord *DbgItem : Info.DPUsers) { + if (DbgItem->isAddressOfVariable() || + DbgItem->getExpression()->startsWithDeref()) + DbgItem->eraseFromParent(); + } ++NumLocalPromoted; return true; @@ -757,7 +747,6 @@ promoteSingleBlockAlloca(AllocaInst *AI, const AllocaInfo &Info, void PromoteMem2Reg::run() { Function &F = *DT.getRoot()->getParent(); - AllocaDbgUsers.resize(Allocas.size()); AllocaATInfo.resize(Allocas.size()); AllocaDPUsers.resize(Allocas.size()); @@ -816,9 +805,7 @@ void PromoteMem2Reg::run() { if (BBNumPreds.empty()) BBNumPreds.resize(F.getMaxBlockNumber()); - // Remember the dbg.declare intrinsic describing this alloca, if any. - if (!Info.DbgUsers.empty()) - AllocaDbgUsers[AllocaNum] = Info.DbgUsers; + // Remember the dbg.declare record describing this alloca, if any. if (!Info.AssignmentTracking.empty()) AllocaATInfo[AllocaNum] = Info.AssignmentTracking; if (!Info.DPUsers.empty()) @@ -894,16 +881,12 @@ void PromoteMem2Reg::run() { } // Remove alloca's dbg.declare intrinsics from the function. - auto RemoveDbgDeclares = [&](auto &Container) { - for (auto &DbgUsers : Container) { - for (auto *DbgItem : DbgUsers) - if (DbgItem->isAddressOfVariable() || - DbgItem->getExpression()->startsWithDeref()) - DbgItem->eraseFromParent(); - } - }; - RemoveDbgDeclares(AllocaDbgUsers); - RemoveDbgDeclares(AllocaDPUsers); + for (auto &DbgUsers : AllocaDPUsers) { + for (DbgVariableRecord *DbgItem : DbgUsers) + if (DbgItem->isAddressOfVariable() || + DbgItem->getExpression()->startsWithDeref()) + DbgItem->eraseFromParent(); + } // Loop over all of the PHI nodes and see if there are any that we can get // rid of because they merge all of the same incoming values. This can diff --git a/llvm/unittests/Transforms/Utils/DebugifyTest.cpp b/llvm/unittests/Transforms/Utils/DebugifyTest.cpp index 0b00734fc4d75..1daf381ee2862 100644 --- a/llvm/unittests/Transforms/Utils/DebugifyTest.cpp +++ b/llvm/unittests/Transforms/Utils/DebugifyTest.cpp @@ -54,20 +54,13 @@ struct DebugInfoDrop : public FunctionPass { struct DebugValueDrop : public FunctionPass { static char ID; bool runOnFunction(Function &F) override { - SmallVector Dbgs; for (BasicBlock &BB : F) { - // Remove dbg var intrinsics. for (Instruction &I : BB) { - if (auto *DVI = dyn_cast(&I)) - Dbgs.push_back(DVI); - // If there are any non-intrinsic records (DbgRecords), drop those too. + // If there are any debug records, drop them. I.dropDbgRecords(); } } - for (auto &I : Dbgs) - I->eraseFromParent(); - return true; } diff --git a/llvm/unittests/Transforms/Utils/LocalTest.cpp b/llvm/unittests/Transforms/Utils/LocalTest.cpp index b922216ef8893..dd2a6249c7cf9 100644 --- a/llvm/unittests/Transforms/Utils/LocalTest.cpp +++ b/llvm/unittests/Transforms/Utils/LocalTest.cpp @@ -633,62 +633,6 @@ TEST(Local, ChangeToUnreachable) { EXPECT_EQ(DLA, DLB); } -TEST(Local, FindDbgUsers) { - LLVMContext Ctx; - std::unique_ptr M = parseIR(Ctx, - R"( - define dso_local void @fun(ptr %a) #0 !dbg !11 { - entry: - #dbg_assign(ptr %a, !16, !DIExpression(), !15, ptr %a, !DIExpression(), !19) - ret void - } - - !llvm.dbg.cu = !{!0} - !llvm.module.flags = !{!2, !3, !9} - !llvm.ident = !{!10} - - !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 17.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) - !1 = !DIFile(filename: "test.cpp", directory: "/") - !2 = !{i32 7, !"Dwarf Version", i32 5} - !3 = !{i32 2, !"Debug Info Version", i32 3} - !4 = !{i32 1, !"wchar_size", i32 4} - !9 = !{i32 7, !"debug-info-assignment-tracking", i1 true} - !10 = !{!"clang version 17.0.0"} - !11 = distinct !DISubprogram(name: "fun", linkageName: "fun", scope: !1, file: !1, line: 1, type: !12, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !14) - !12 = !DISubroutineType(types: !13) - !13 = !{null} - !14 = !{} - !15 = distinct !DIAssignID() - !16 = !DILocalVariable(name: "x", scope: !11, file: !1, line: 2, type: !17) - !17 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !18, size: 64) - !18 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) - !19 = !DILocation(line: 0, scope: !11) - )"); - - bool BrokenDebugInfo = true; - verifyModule(*M, &errs(), &BrokenDebugInfo); - ASSERT_FALSE(BrokenDebugInfo); - - // Convert to debug intrinsics as we want to test findDbgUsers and - // findDbgValue's debug-intrinsic-finding code here. - // TODO: Remove this test when debug intrinsics are removed. - M->convertFromNewDbgValues(); - - 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); - - 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); -} - TEST(Local, FindDbgRecords) { // DbgRecord copy of the FindDbgUsers test above. LLVMContext Ctx;