diff --git a/llvm/include/llvm/Transforms/Utils/SSAUpdater.h b/llvm/include/llvm/Transforms/Utils/SSAUpdater.h index 4e5da81a7e885..9500b1f160ea9 100644 --- a/llvm/include/llvm/Transforms/Utils/SSAUpdater.h +++ b/llvm/include/llvm/Transforms/Utils/SSAUpdater.h @@ -29,7 +29,6 @@ template class SSAUpdaterTraits; class Type; class Use; class Value; -class DbgValueInst; /// Helper class for SSA formation on a set of values defined in /// multiple blocks. @@ -122,8 +121,6 @@ class SSAUpdater { /// the instruction. Anything outside of its block will have its /// value set to the new SSA value if available, and undef if not. void UpdateDebugValues(Instruction *I); - void UpdateDebugValues(Instruction *I, - SmallVectorImpl &DbgValues); void UpdateDebugValues(Instruction *I, SmallVectorImpl &DbgValues); @@ -136,7 +133,6 @@ class SSAUpdater { private: Value *GetValueAtEndOfBlockInternal(BasicBlock *BB); - void UpdateDebugValue(Instruction *I, DbgValueInst *DbgValue); void UpdateDebugValue(Instruction *I, DbgVariableRecord *DbgValue); }; diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index 70a9788c76e1f..8a2a3b11c94cf 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -445,7 +445,6 @@ class CodeGenPrepare { bool optimizeSwitchInst(SwitchInst *SI); bool optimizeExtractElementInst(Instruction *Inst); bool dupRetToEnableTailCallOpts(BasicBlock *BB, ModifyDT &ModifiedDT); - bool fixupDbgValue(Instruction *I); bool fixupDbgVariableRecord(DbgVariableRecord &I); bool fixupDbgVariableRecordsOnInst(Instruction &I); bool placeDbgValues(Function &F); @@ -2762,9 +2761,6 @@ bool CodeGenPrepare::optimizeCallInst(CallInst *CI, ModifyDT &ModifiedDT) { case Intrinsic::fshl: case Intrinsic::fshr: return optimizeFunnelShift(II); - case Intrinsic::dbg_assign: - case Intrinsic::dbg_value: - return fixupDbgValue(II); case Intrinsic::masked_gather: return optimizeGatherScatterInst(II, II->getArgOperand(0)); case Intrinsic::masked_scatter: @@ -3554,8 +3550,6 @@ class TypePromotionTransaction { /// Keep track of the original uses (pair Instruction, Index). SmallVector OriginalUses; /// Keep track of the debug users. - SmallVector DbgValues; - /// And non-instruction debug-users too. SmallVector DbgVariableRecords; /// Keep track of the new value so that we can undo it by replacing @@ -3577,7 +3571,9 @@ class TypePromotionTransaction { } // Record the debug uses separately. They are not in the instruction's // use list, but they are replaced by RAUW. + SmallVector DbgValues; findDbgValues(DbgValues, Inst, &DbgVariableRecords); + assert(DbgValues.empty()); // Now, we can replace the uses. Inst->replaceAllUsesWith(New); @@ -3591,11 +3587,7 @@ class TypePromotionTransaction { // RAUW has replaced all original uses with references to the new value, // including the debug uses. Since we are undoing the replacements, // the original debug uses must also be reinstated to maintain the - // correctness and utility of debug value instructions. - for (auto *DVI : DbgValues) - DVI->replaceVariableLocationOp(New, Inst); - // Similar story with DbgVariableRecords, the non-instruction - // representation of dbg.values. + // correctness and utility of debug value records. for (DbgVariableRecord *DVR : DbgVariableRecords) DVR->replaceVariableLocationOp(New, Inst); } @@ -8933,32 +8925,6 @@ bool CodeGenPrepare::optimizeBlock(BasicBlock &BB, ModifyDT &ModifiedDT) { return MadeChange; } -// Some CGP optimizations may move or alter what's computed in a block. Check -// whether a dbg.value intrinsic could be pointed at a more appropriate operand. -bool CodeGenPrepare::fixupDbgValue(Instruction *I) { - assert(isa(I)); - DbgValueInst &DVI = *cast(I); - - // Does this dbg.value refer to a sunk address calculation? - bool AnyChange = false; - SmallDenseSet LocationOps(DVI.location_ops().begin(), - DVI.location_ops().end()); - for (Value *Location : LocationOps) { - WeakTrackingVH SunkAddrVH = SunkAddrs[Location]; - Value *SunkAddr = SunkAddrVH.pointsToAliveValue() ? SunkAddrVH : nullptr; - if (SunkAddr) { - // Point dbg.value at locally computed address, which should give the best - // opportunity to be accurately lowered. This update may change the type - // of pointer being referred to; however this makes no difference to - // debugging information, and we can't generate bitcasts that may affect - // codegen. - DVI.replaceVariableLocationOp(Location, SunkAddr); - AnyChange = true; - } - } - return AnyChange; -} - bool CodeGenPrepare::fixupDbgVariableRecordsOnInst(Instruction &I) { bool AnyChange = false; for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) @@ -8993,14 +8959,6 @@ bool CodeGenPrepare::fixupDbgVariableRecord(DbgVariableRecord &DVR) { return AnyChange; } -static void DbgInserterHelper(DbgValueInst *DVI, BasicBlock::iterator VI) { - DVI->removeFromParent(); - if (isa(VI)) - DVI->insertBefore(VI->getParent()->getFirstInsertionPt()); - else - DVI->insertAfter(VI); -} - static void DbgInserterHelper(DbgVariableRecord *DVR, BasicBlock::iterator VI) { DVR->removeFromParent(); BasicBlock *VIBB = VI->getParent(); @@ -9065,15 +9023,8 @@ bool CodeGenPrepare::placeDbgValues(Function &F) { for (BasicBlock &BB : F) { for (Instruction &Insn : llvm::make_early_inc_range(BB)) { - // Process dbg.value intrinsics. - DbgValueInst *DVI = dyn_cast(&Insn); - if (DVI) { - DbgProcessor(DVI, DVI); - continue; - } - - // If this isn't a dbg.value, process any attached DbgVariableRecord - // records attached to this instruction. + // Process any DbgVariableRecord records attached to this + // instruction. for (DbgVariableRecord &DVR : llvm::make_early_inc_range( filterDbgVars(Insn.getDbgRecordRange()))) { if (DVR.Type != DbgVariableRecord::LocationType::Value) diff --git a/llvm/lib/CodeGen/MachineDebugify.cpp b/llvm/lib/CodeGen/MachineDebugify.cpp index 9b9cebc74054d..1a20fe586e951 100644 --- a/llvm/lib/CodeGen/MachineDebugify.cpp +++ b/llvm/lib/CodeGen/MachineDebugify.cpp @@ -63,24 +63,9 @@ bool applyDebugifyMetadataToMachineFunction(MachineModuleInfo &MMI, // which cover a wide range of lines can help stress the debug info passes: // if we can't do that, fall back to using the local variable which precedes // all the others. - Function *DbgValF = M.getFunction("llvm.dbg.value"); - DbgValueInst *EarliestDVI = nullptr; DbgVariableRecord *EarliestDVR = nullptr; DenseMap Line2Var; DIExpression *Expr = nullptr; - if (DbgValF) { - for (const Use &U : DbgValF->uses()) { - auto *DVI = dyn_cast(U.getUser()); - if (!DVI || DVI->getFunction() != &F) - continue; - unsigned Line = DVI->getDebugLoc().getLine(); - assert(Line != 0 && "debugify should not insert line 0 locations"); - Line2Var[Line] = DVI->getVariable(); - if (!EarliestDVI || Line < EarliestDVI->getDebugLoc().getLine()) - EarliestDVI = DVI; - Expr = DVI->getExpression(); - } - } for (BasicBlock &BB : F) { for (Instruction &I : BB) { for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) { @@ -125,8 +110,7 @@ bool applyDebugifyMetadataToMachineFunction(MachineModuleInfo &MMI, unsigned Line = MI.getDebugLoc().getLine(); auto It = Line2Var.find(Line); if (It == Line2Var.end()) { - Line = EarliestDVI ? EarliestDVI->getDebugLoc().getLine() - : EarliestDVR->getDebugLoc().getLine(); + Line = EarliestDVR->getDebugLoc().getLine(); It = Line2Var.find(Line); assert(It != Line2Var.end()); } diff --git a/llvm/lib/Transforms/Coroutines/SpillUtils.cpp b/llvm/lib/Transforms/Coroutines/SpillUtils.cpp index 8017db1cfe146..5fd5f7d9dad09 100644 --- a/llvm/lib/Transforms/Coroutines/SpillUtils.cpp +++ b/llvm/lib/Transforms/Coroutines/SpillUtils.cpp @@ -514,7 +514,7 @@ void collectSpillsAndAllocasFromInsts( void collectSpillsFromDbgInfo(SpillInfo &Spills, Function &F, const SuspendCrossingInfo &Checker) { // We don't want the layout of coroutine frame to be affected - // by debug information. So we only choose to salvage DbgValueInst for + // by debug information. So we only choose to salvage dbg.values for // whose value is already in the frame. // We would handle the dbg.values for allocas specially for (auto &Iter : Spills) { @@ -522,9 +522,7 @@ void collectSpillsFromDbgInfo(SpillInfo &Spills, Function &F, SmallVector DVIs; SmallVector DVRs; findDbgValues(DVIs, V, &DVRs); - for (DbgValueInst *DVI : DVIs) - if (Checker.isDefinitionAcrossSuspend(*V, DVI)) - Spills[V].push_back(DVI); + assert(DVIs.empty()); // 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/IPO/MergeFunctions.cpp b/llvm/lib/Transforms/IPO/MergeFunctions.cpp index d4555e9435f1d..f5525deb0172f 100644 --- a/llvm/lib/Transforms/IPO/MergeFunctions.cpp +++ b/llvm/lib/Transforms/IPO/MergeFunctions.cpp @@ -572,7 +572,7 @@ void MergeFunctions::filterInstsUnrelatedToPDI( // Work out whether a dbg.value intrinsic or an equivalent DbgVariableRecord // is a parameter to be preserved. - auto ExamineDbgValue = [](auto *DbgVal, auto &Container) { + auto ExamineDbgValue = [&PDVRRelated](DbgVariableRecord *DbgVal) { LLVM_DEBUG(dbgs() << " Deciding: "); LLVM_DEBUG(DbgVal->print(dbgs())); LLVM_DEBUG(dbgs() << "\n"); @@ -581,7 +581,7 @@ void MergeFunctions::filterInstsUnrelatedToPDI( LLVM_DEBUG(dbgs() << " Include (parameter): "); LLVM_DEBUG(DbgVal->print(dbgs())); LLVM_DEBUG(dbgs() << "\n"); - Container.insert(DbgVal); + PDVRRelated.insert(DbgVal); } else { LLVM_DEBUG(dbgs() << " Delete (!parameter): "); LLVM_DEBUG(DbgVal->print(dbgs())); @@ -589,7 +589,8 @@ void MergeFunctions::filterInstsUnrelatedToPDI( } }; - auto ExamineDbgDeclare = [&PDIRelated](auto *DbgDecl, auto &Container) { + auto ExamineDbgDeclare = [&PDIRelated, + &PDVRRelated](DbgVariableRecord *DbgDecl) { LLVM_DEBUG(dbgs() << " Deciding: "); LLVM_DEBUG(DbgDecl->print(dbgs())); LLVM_DEBUG(dbgs() << "\n"); @@ -616,7 +617,7 @@ void MergeFunctions::filterInstsUnrelatedToPDI( LLVM_DEBUG(dbgs() << " Include: "); LLVM_DEBUG(DbgDecl->print(dbgs())); LLVM_DEBUG(dbgs() << "\n"); - Container.insert(DbgDecl); + PDVRRelated.insert(DbgDecl); } else { LLVM_DEBUG(dbgs() << " Delete (!parameter): "); LLVM_DEBUG(SI->print(dbgs())); @@ -647,18 +648,14 @@ void MergeFunctions::filterInstsUnrelatedToPDI( // they connected to parameters? for (DbgVariableRecord &DVR : filterDbgVars(BI->getDbgRecordRange())) { if (DVR.isDbgValue() || DVR.isDbgAssign()) { - ExamineDbgValue(&DVR, PDVRRelated); + ExamineDbgValue(&DVR); } else { assert(DVR.isDbgDeclare()); - ExamineDbgDeclare(&DVR, PDVRRelated); + ExamineDbgDeclare(&DVR); } } - if (auto *DVI = dyn_cast(&*BI)) { - ExamineDbgValue(DVI, PDIRelated); - } else if (auto *DDI = dyn_cast(&*BI)) { - ExamineDbgDeclare(DDI, PDIRelated); - } else if (BI->isTerminator() && &*BI == GEntryBlock->getTerminator()) { + if (BI->isTerminator() && &*BI == GEntryBlock->getTerminator()) { LLVM_DEBUG(dbgs() << " Will Include Terminator: "); LLVM_DEBUG(BI->print(dbgs())); LLVM_DEBUG(dbgs() << "\n"); diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 91a1b61ddc483..b2c6aa8c78409 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1420,21 +1420,16 @@ void InstCombinerImpl::freelyInvertAllUsersOf(Value *I, Value *IgnoredUser) { SmallVector DbgValues; SmallVector DbgVariableRecords; llvm::findDbgValues(DbgValues, I, &DbgVariableRecords); + assert(DbgValues.empty()); - auto InvertDbgValueUse = [&](auto *DbgVal) { + for (DbgVariableRecord *DbgVal : DbgVariableRecords) { SmallVector Ops = {dwarf::DW_OP_not}; for (unsigned Idx = 0, End = DbgVal->getNumVariableLocationOps(); Idx != End; ++Idx) if (DbgVal->getVariableLocationOp(Idx) == I) DbgVal->setExpression( DIExpression::appendOpsToArg(DbgVal->getExpression(), Ops, Idx)); - }; - - for (DbgValueInst *DVI : DbgValues) - InvertDbgValueUse(DVI); - - for (DbgVariableRecord *DVR : DbgVariableRecords) - InvertDbgValueUse(DVR); + } } /// Given a 'sub' instruction, return the RHS of the instruction if the LHS is a diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index b5dbef13289ac..4d1f44076db7e 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -1979,15 +1979,13 @@ void JumpThreadingPass::updateSSA(BasicBlock *BB, BasicBlock *NewBB, // Find debug values outside of the block findDbgValues(DbgValues, &I, &DbgVariableRecords); - llvm::erase_if(DbgValues, [&](const DbgValueInst *DbgVal) { - return DbgVal->getParent() == BB; - }); + assert(DbgValues.empty()); llvm::erase_if(DbgVariableRecords, [&](const DbgVariableRecord *DbgVarRec) { return DbgVarRec->getParent() == BB; }); // If there are no uses outside the block, we're done with this instruction. - if (UsesToRename.empty() && DbgValues.empty() && DbgVariableRecords.empty()) + if (UsesToRename.empty() && DbgVariableRecords.empty()) continue; LLVM_DEBUG(dbgs() << "JT: Renaming non-local uses of: " << I << "\n"); @@ -2000,8 +1998,7 @@ void JumpThreadingPass::updateSSA(BasicBlock *BB, BasicBlock *NewBB, while (!UsesToRename.empty()) SSAUpdate.RewriteUse(*UsesToRename.pop_back_val()); - if (!DbgValues.empty() || !DbgVariableRecords.empty()) { - SSAUpdate.UpdateDebugValues(&I, DbgValues); + if (!DbgVariableRecords.empty()) { SSAUpdate.UpdateDebugValues(&I, DbgVariableRecords); DbgValues.clear(); DbgVariableRecords.clear(); @@ -2032,32 +2029,7 @@ void JumpThreadingPass::cloneInstructions(ValueToValueMapTy &ValueMapping, // copy of the block 'NewBB'. If there are PHI nodes in the source basic // block, evaluate them to account for entry from PredBB. - // Retargets llvm.dbg.value to any renamed variables. - auto RetargetDbgValueIfPossible = [&](Instruction *NewInst) -> bool { - auto DbgInstruction = dyn_cast(NewInst); - if (!DbgInstruction) - return false; - - SmallSet, 16> OperandsToRemap; - for (auto DbgOperand : DbgInstruction->location_ops()) { - auto DbgOperandInstruction = dyn_cast(DbgOperand); - if (!DbgOperandInstruction) - continue; - - auto I = ValueMapping.find(DbgOperandInstruction); - if (I != ValueMapping.end()) { - OperandsToRemap.insert( - std::pair(DbgOperand, I->second)); - } - } - - for (auto &[OldOp, MappedOp] : OperandsToRemap) - DbgInstruction->replaceVariableLocationOp(OldOp, MappedOp); - return true; - }; - - // Duplicate implementation of the above dbg.value code, using - // DbgVariableRecords instead. + // Retargets dbg.value to any renamed variables. auto RetargetDbgVariableRecordIfPossible = [&](DbgVariableRecord *DVR) { SmallSet, 16> OperandsToRemap; for (auto *Op : DVR->location_ops()) { @@ -2116,9 +2088,6 @@ void JumpThreadingPass::cloneInstructions(ValueToValueMapTy &ValueMapping, if (const DebugLoc &DL = New->getDebugLoc()) mapAtomInstance(DL, ValueMapping); - if (RetargetDbgValueIfPossible(New)) - continue; - // Remap operands to patch up intra-block references. for (unsigned i = 0, e = New->getNumOperands(); i != e; ++i) if (Instruction *Inst = dyn_cast(New->getOperand(i))) { diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index dc8fa4379752f..636bd81ce0755 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -6630,13 +6630,10 @@ struct SCEVDbgValueBuilder { /// Holds all the required data to salvage a dbg.value using the pre-LSR SCEVs /// and DIExpression. struct DVIRecoveryRec { - DVIRecoveryRec(DbgValueInst *DbgValue) - : DbgRef(DbgValue), Expr(DbgValue->getExpression()), - HadLocationArgList(false) {} DVIRecoveryRec(DbgVariableRecord *DVR) : DbgRef(DVR), Expr(DVR->getExpression()), HadLocationArgList(false) {} - PointerUnion DbgRef; + DbgVariableRecord *DbgRef; DIExpression *Expr; bool HadLocationArgList; SmallVector LocationOps; @@ -6695,44 +6692,38 @@ static void updateDVIWithLocations(T &DbgVal, } /// Write the new expression and new location ops for the dbg.value. If possible -/// reduce the szie of the dbg.value intrinsic by omitting DIArglist. This +/// reduce the szie of the dbg.value by omitting DIArglist. This /// can be omitted if: /// 1. There is only a single location, refenced by a single DW_OP_llvm_arg. /// 2. The DW_OP_LLVM_arg is the first operand in the expression. -static void UpdateDbgValueInst(DVIRecoveryRec &DVIRec, - SmallVectorImpl &NewLocationOps, - SmallVectorImpl &NewExpr) { - auto UpdateDbgValueInstImpl = [&](auto *DbgVal) { - unsigned NumLLVMArgs = numLLVMArgOps(NewExpr); - if (NumLLVMArgs == 0) { - // Location assumed to be on the stack. - updateDVIWithLocation(*DbgVal, NewLocationOps[0], NewExpr); - } else if (NumLLVMArgs == 1 && NewExpr[0] == dwarf::DW_OP_LLVM_arg) { - // There is only a single DW_OP_llvm_arg at the start of the expression, - // so it can be omitted along with DIArglist. - assert(NewExpr[1] == 0 && - "Lone LLVM_arg in a DIExpression should refer to location-op 0."); - llvm::SmallVector ShortenedOps(llvm::drop_begin(NewExpr, 2)); - updateDVIWithLocation(*DbgVal, NewLocationOps[0], ShortenedOps); - } else { - // Multiple DW_OP_llvm_arg, so DIArgList is strictly necessary. - updateDVIWithLocations(*DbgVal, NewLocationOps, NewExpr); - } +static void UpdateDbgValue(DVIRecoveryRec &DVIRec, + SmallVectorImpl &NewLocationOps, + SmallVectorImpl &NewExpr) { + DbgVariableRecord *DbgVal = DVIRec.DbgRef; + unsigned NumLLVMArgs = numLLVMArgOps(NewExpr); + if (NumLLVMArgs == 0) { + // Location assumed to be on the stack. + updateDVIWithLocation(*DbgVal, NewLocationOps[0], NewExpr); + } else if (NumLLVMArgs == 1 && NewExpr[0] == dwarf::DW_OP_LLVM_arg) { + // There is only a single DW_OP_llvm_arg at the start of the expression, + // so it can be omitted along with DIArglist. + assert(NewExpr[1] == 0 && + "Lone LLVM_arg in a DIExpression should refer to location-op 0."); + llvm::SmallVector ShortenedOps(llvm::drop_begin(NewExpr, 2)); + updateDVIWithLocation(*DbgVal, NewLocationOps[0], ShortenedOps); + } else { + // Multiple DW_OP_llvm_arg, so DIArgList is strictly necessary. + updateDVIWithLocations(*DbgVal, NewLocationOps, NewExpr); + } - // If the DIExpression was previously empty then add the stack terminator. - // Non-empty expressions have only had elements inserted into them and so - // the terminator should already be present e.g. stack_value or fragment. - DIExpression *SalvageExpr = DbgVal->getExpression(); - if (!DVIRec.Expr->isComplex() && SalvageExpr->isComplex()) { - SalvageExpr = - DIExpression::append(SalvageExpr, {dwarf::DW_OP_stack_value}); - DbgVal->setExpression(SalvageExpr); - } - }; - if (isa(DVIRec.DbgRef)) - UpdateDbgValueInstImpl(cast(DVIRec.DbgRef)); - else - UpdateDbgValueInstImpl(cast(DVIRec.DbgRef)); + // If the DIExpression was previously empty then add the stack terminator. + // Non-empty expressions have only had elements inserted into them and so + // the terminator should already be present e.g. stack_value or fragment. + DIExpression *SalvageExpr = DbgVal->getExpression(); + if (!DVIRec.Expr->isComplex() && SalvageExpr->isComplex()) { + SalvageExpr = DIExpression::append(SalvageExpr, {dwarf::DW_OP_stack_value}); + DbgVal->setExpression(SalvageExpr); + } } /// Cached location ops may be erased during LSR, in which case a poison is @@ -6746,39 +6737,34 @@ static Value *getValueOrPoison(WeakVH &VH, LLVMContext &C) { /// Restore the DVI's pre-LSR arguments. Substitute undef for any erased values. static void restorePreTransformState(DVIRecoveryRec &DVIRec) { - auto RestorePreTransformStateImpl = [&](auto *DbgVal) { - LLVM_DEBUG(dbgs() << "scev-salvage: restore dbg.value to pre-LSR state\n" - << "scev-salvage: post-LSR: " << *DbgVal << '\n'); - assert(DVIRec.Expr && "Expected an expression"); - DbgVal->setExpression(DVIRec.Expr); - - // Even a single location-op may be inside a DIArgList and referenced with - // DW_OP_LLVM_arg, which is valid only with a DIArgList. - if (!DVIRec.HadLocationArgList) { - assert(DVIRec.LocationOps.size() == 1 && - "Unexpected number of location ops."); - // LSR's unsuccessful salvage attempt may have added DIArgList, which in - // this case was not present before, so force the location back to a - // single uncontained Value. - Value *CachedValue = - getValueOrPoison(DVIRec.LocationOps[0], DbgVal->getContext()); - DbgVal->setRawLocation(ValueAsMetadata::get(CachedValue)); - } else { - SmallVector MetadataLocs; - for (WeakVH VH : DVIRec.LocationOps) { - Value *CachedValue = getValueOrPoison(VH, DbgVal->getContext()); - MetadataLocs.push_back(ValueAsMetadata::get(CachedValue)); - } - auto ValArrayRef = llvm::ArrayRef(MetadataLocs); - DbgVal->setRawLocation( - llvm::DIArgList::get(DbgVal->getContext(), ValArrayRef)); + DbgVariableRecord *DbgVal = DVIRec.DbgRef; + LLVM_DEBUG(dbgs() << "scev-salvage: restore dbg.value to pre-LSR state\n" + << "scev-salvage: post-LSR: " << *DbgVal << '\n'); + assert(DVIRec.Expr && "Expected an expression"); + DbgVal->setExpression(DVIRec.Expr); + + // Even a single location-op may be inside a DIArgList and referenced with + // DW_OP_LLVM_arg, which is valid only with a DIArgList. + if (!DVIRec.HadLocationArgList) { + assert(DVIRec.LocationOps.size() == 1 && + "Unexpected number of location ops."); + // LSR's unsuccessful salvage attempt may have added DIArgList, which in + // this case was not present before, so force the location back to a + // single uncontained Value. + Value *CachedValue = + getValueOrPoison(DVIRec.LocationOps[0], DbgVal->getContext()); + DbgVal->setRawLocation(ValueAsMetadata::get(CachedValue)); + } else { + SmallVector MetadataLocs; + for (WeakVH VH : DVIRec.LocationOps) { + Value *CachedValue = getValueOrPoison(VH, DbgVal->getContext()); + MetadataLocs.push_back(ValueAsMetadata::get(CachedValue)); } - LLVM_DEBUG(dbgs() << "scev-salvage: pre-LSR: " << *DbgVal << '\n'); - }; - if (isa(DVIRec.DbgRef)) - RestorePreTransformStateImpl(cast(DVIRec.DbgRef)); - else - RestorePreTransformStateImpl(cast(DVIRec.DbgRef)); + auto ValArrayRef = llvm::ArrayRef(MetadataLocs); + DbgVal->setRawLocation( + llvm::DIArgList::get(DbgVal->getContext(), ValArrayRef)); + } + LLVM_DEBUG(dbgs() << "scev-salvage: pre-LSR: " << *DbgVal << '\n'); } static bool SalvageDVI(llvm::Loop *L, ScalarEvolution &SE, @@ -6786,9 +6772,7 @@ static bool SalvageDVI(llvm::Loop *L, ScalarEvolution &SE, const SCEV *SCEVInductionVar, SCEVDbgValueBuilder IterCountExpr) { - if (isa(DVIRec.DbgRef) - ? !cast(DVIRec.DbgRef)->isKillLocation() - : !cast(DVIRec.DbgRef)->isKillLocation()) + if (!DVIRec.DbgRef->isKillLocation()) return false; // LSR may have caused several changes to the dbg.value in the failed salvage @@ -6882,13 +6866,8 @@ static bool SalvageDVI(llvm::Loop *L, ScalarEvolution &SE, DbgBuilder->appendToVectors(NewExpr, NewLocationOps); } - UpdateDbgValueInst(DVIRec, NewLocationOps, NewExpr); - if (isa(DVIRec.DbgRef)) - LLVM_DEBUG(dbgs() << "scev-salvage: Updated DVI: " - << *cast(DVIRec.DbgRef) << "\n"); - else - LLVM_DEBUG(dbgs() << "scev-salvage: Updated DVI: " - << *cast(DVIRec.DbgRef) << "\n"); + UpdateDbgValue(DVIRec, NewLocationOps, NewExpr); + LLVM_DEBUG(dbgs() << "scev-salvage: Updated DVI: " << *DVIRec.DbgRef << "\n"); return true; } @@ -6934,21 +6913,23 @@ static void DbgRewriteSalvageableDVIs( /// cacheing and salvaging. static void DbgGatherSalvagableDVI( Loop *L, ScalarEvolution &SE, - SmallVector, 2> &SalvageableDVISCEVs, - SmallSet, 2> &DVIHandles) { + SmallVector, 2> &SalvageableDVISCEVs) { for (const auto &B : L->getBlocks()) { for (auto &I : *B) { - auto ProcessDbgValue = [&](auto *DbgVal) -> bool { + for (DbgVariableRecord &DbgVal : filterDbgVars(I.getDbgRecordRange())) { + if (!DbgVal.isDbgValue() && !DbgVal.isDbgAssign()) + continue; + // Ensure that if any location op is undef that the dbg.vlue is not // cached. - if (DbgVal->isKillLocation()) - return false; + if (DbgVal.isKillLocation()) + continue; // Check that the location op SCEVs are suitable for translation to // DIExpression. const auto &HasTranslatableLocationOps = - [&](const auto *DbgValToTranslate) -> bool { - for (const auto LocOp : DbgValToTranslate->location_ops()) { + [&](const DbgVariableRecord &DbgValToTranslate) -> bool { + for (const auto LocOp : DbgValToTranslate.location_ops()) { if (!LocOp) return false; @@ -6963,31 +6944,21 @@ static void DbgGatherSalvagableDVI( }; if (!HasTranslatableLocationOps(DbgVal)) - return false; + continue; std::unique_ptr NewRec = - std::make_unique(DbgVal); + std::make_unique(&DbgVal); // Each location Op may need a SCEVDbgValueBuilder in order to recover // it. Pre-allocating a vector will enable quick lookups of the builder // later during the salvage. - NewRec->RecoveryExprs.resize(DbgVal->getNumVariableLocationOps()); - for (const auto LocOp : DbgVal->location_ops()) { + NewRec->RecoveryExprs.resize(DbgVal.getNumVariableLocationOps()); + for (const auto LocOp : DbgVal.location_ops()) { NewRec->SCEVs.push_back(SE.getSCEV(LocOp)); NewRec->LocationOps.push_back(LocOp); - NewRec->HadLocationArgList = DbgVal->hasArgList(); + NewRec->HadLocationArgList = DbgVal.hasArgList(); } SalvageableDVISCEVs.push_back(std::move(NewRec)); - return true; - }; - for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) { - if (DVR.isDbgValue() || DVR.isDbgAssign()) - ProcessDbgValue(&DVR); } - auto DVI = dyn_cast(&I); - if (!DVI) - continue; - if (ProcessDbgValue(DVI)) - DVIHandles.insert(DVI); } } } @@ -7036,8 +7007,7 @@ static bool ReduceLoopStrength(Loop *L, IVUsers &IU, ScalarEvolution &SE, // Debug preservation - before we start removing anything identify which DVI // meet the salvageable criteria and store their DIExpression and SCEVs. SmallVector, 2> SalvageableDVIRecords; - SmallSet, 2> DVIHandles; - DbgGatherSalvagableDVI(L, SE, SalvageableDVIRecords, DVIHandles); + DbgGatherSalvagableDVI(L, SE, SalvageableDVIRecords); bool Changed = false; std::unique_ptr MSSAU; @@ -7105,7 +7075,6 @@ static bool ReduceLoopStrength(Loop *L, IVUsers &IU, ScalarEvolution &SE, for (auto &Rec : SalvageableDVIRecords) Rec->clear(); SalvageableDVIRecords.clear(); - DVIHandles.clear(); return Changed; } diff --git a/llvm/lib/Transforms/Utils/Debugify.cpp b/llvm/lib/Transforms/Utils/Debugify.cpp index a1f030a336c15..4210ce6da1eb2 100644 --- a/llvm/lib/Transforms/Utils/Debugify.cpp +++ b/llvm/lib/Transforms/Utils/Debugify.cpp @@ -808,9 +808,6 @@ bool checkDebugifyMetadata(Module &M, // Find missing lines. for (Instruction &I : instructions(F)) { - if (isa(&I)) - continue; - auto DL = I.getDebugLoc(); if (DL && DL.getLine() != 0) { MissingLines.reset(DL.getLine() - 1); @@ -839,10 +836,6 @@ bool checkDebugifyMetadata(Module &M, for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) if (DVR.isDbgValue() || DVR.isDbgAssign()) CheckForMisSized(&DVR); - auto *DVI = dyn_cast(&I); - if (!DVI) - continue; - CheckForMisSized(DVI); } } diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index ccdaca9b0e91c..76cdb34f8c325 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -1611,12 +1611,8 @@ static bool PhiHasDebugValue(DILocalVariable *DIVar, SmallVector DbgValues; SmallVector DbgVariableRecords; findDbgValues(DbgValues, APN, &DbgVariableRecords); - for (auto *DVI : DbgValues) { - assert(is_contained(DVI->getValues(), APN)); - if ((DVI->getVariable() == DIVar) && (DVI->getExpression() == DIExpr)) - return true; - } - for (auto *DVR : DbgVariableRecords) { + assert(DbgValues.empty()); + for (DbgVariableRecord *DVR : DbgVariableRecords) { assert(is_contained(DVR->location_ops(), APN)); if ((DVR->getVariable() == DIVar) && (DVR->getExpression() == DIExpr)) return true; @@ -2199,7 +2195,6 @@ bool llvm::replaceDbgDeclare(Value *Address, Value *NewAddress, static void updateOneDbgValueForAlloca(const DebugLoc &Loc, DILocalVariable *DIVar, DIExpression *DIExpr, Value *NewAddress, - DbgValueInst *DVI, DbgVariableRecord *DVR, DIBuilder &Builder, int Offset) { assert(DIVar && "Missing variable"); @@ -2215,14 +2210,8 @@ static void updateOneDbgValueForAlloca(const DebugLoc &Loc, if (Offset) DIExpr = DIExpression::prepend(DIExpr, 0, Offset); - if (DVI) { - DVI->setExpression(DIExpr); - DVI->replaceVariableLocationOp(0u, NewAddress); - } else { - assert(DVR); - DVR->setExpression(DIExpr); - DVR->replaceVariableLocationOp(0u, NewAddress); - } + DVR->setExpression(DIExpr); + DVR->replaceVariableLocationOp(0u, NewAddress); } void llvm::replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress, @@ -2230,18 +2219,13 @@ void llvm::replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress, SmallVector DbgUsers; SmallVector DPUsers; findDbgValues(DbgUsers, AI, &DPUsers); - - // Attempt to replace dbg.values that use this alloca. - for (auto *DVI : DbgUsers) - updateOneDbgValueForAlloca(DVI->getDebugLoc(), DVI->getVariable(), - DVI->getExpression(), NewAllocaAddress, DVI, - nullptr, Builder, Offset); + assert(DbgUsers.empty()); // Replace any DbgVariableRecords that use this alloca. for (DbgVariableRecord *DVR : DPUsers) updateOneDbgValueForAlloca(DVR->getDebugLoc(), DVR->getVariable(), - DVR->getExpression(), NewAllocaAddress, nullptr, - DVR, Builder, Offset); + DVR->getExpression(), NewAllocaAddress, DVR, + Builder, Offset); } /// Where possible to salvage debug information for \p I do so. diff --git a/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp b/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp index 66d0573e83f65..06115e0741ade 100644 --- a/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp @@ -161,29 +161,8 @@ static void RewriteUsesOfClonedInstructions(BasicBlock *OrigHeader, SmallVector DbgValues; SmallVector DbgVariableRecords; llvm::findDbgValues(DbgValues, OrigHeaderVal, &DbgVariableRecords); - for (auto &DbgValue : DbgValues) { - // The original users in the OrigHeader are already using the original - // definitions. - BasicBlock *UserBB = DbgValue->getParent(); - if (UserBB == OrigHeader) - continue; - - // Users in the OrigPreHeader need to use the value to which the - // original definitions are mapped and anything else can be handled by - // the SSAUpdater. To avoid adding PHINodes, check if the value is - // available in UserBB, if not substitute poison. - Value *NewVal; - if (UserBB == OrigPreheader) - NewVal = OrigPreHeaderVal; - else if (SSA.HasValueForBlock(UserBB)) - NewVal = SSA.GetValueInMiddleOfBlock(UserBB); - else - NewVal = PoisonValue::get(OrigHeaderVal->getType()); - DbgValue->replaceVariableLocationOp(OrigHeaderVal, NewVal); - } + assert(DbgValues.empty()); - // RemoveDIs: duplicate implementation for non-instruction debug-info - // storage in DbgVariableRecords. for (DbgVariableRecord *DVR : DbgVariableRecords) { // The original users in the OrigHeader are already using the original // definitions. diff --git a/llvm/lib/Transforms/Utils/SSAUpdater.cpp b/llvm/lib/Transforms/Utils/SSAUpdater.cpp index 5db7fc956c497..561c898ec55d8 100644 --- a/llvm/lib/Transforms/Utils/SSAUpdater.cpp +++ b/llvm/lib/Transforms/Utils/SSAUpdater.cpp @@ -200,11 +200,7 @@ void SSAUpdater::UpdateDebugValues(Instruction *I) { SmallVector DbgValues; SmallVector DbgVariableRecords; llvm::findDbgValues(DbgValues, I, &DbgVariableRecords); - for (auto &DbgValue : DbgValues) { - if (DbgValue->getParent() == I->getParent()) - continue; - UpdateDebugValue(I, DbgValue); - } + assert(DbgValues.empty()); for (auto &DVR : DbgVariableRecords) { if (DVR->getParent() == I->getParent()) continue; @@ -212,13 +208,6 @@ void SSAUpdater::UpdateDebugValues(Instruction *I) { } } -void SSAUpdater::UpdateDebugValues(Instruction *I, - SmallVectorImpl &DbgValues) { - for (auto &DbgValue : DbgValues) { - UpdateDebugValue(I, DbgValue); - } -} - void SSAUpdater::UpdateDebugValues( Instruction *I, SmallVectorImpl &DbgVariableRecords) { for (auto &DVR : DbgVariableRecords) { @@ -226,15 +215,6 @@ void SSAUpdater::UpdateDebugValues( } } -void SSAUpdater::UpdateDebugValue(Instruction *I, DbgValueInst *DbgValue) { - BasicBlock *UserBB = DbgValue->getParent(); - if (HasValueForBlock(UserBB)) { - Value *NewVal = GetValueAtEndOfBlock(UserBB); - DbgValue->replaceVariableLocationOp(I, NewVal); - } else - DbgValue->setKillLocation(); -} - void SSAUpdater::UpdateDebugValue(Instruction *I, DbgVariableRecord *DVR) { BasicBlock *UserBB = DVR->getParent(); if (HasValueForBlock(UserBB)) { diff --git a/llvm/tools/llvm-dis/llvm-dis.cpp b/llvm/tools/llvm-dis/llvm-dis.cpp index 422eb855ba2cf..2b43d27f292a0 100644 --- a/llvm/tools/llvm-dis/llvm-dis.cpp +++ b/llvm/tools/llvm-dis/llvm-dis.cpp @@ -131,20 +131,6 @@ class CommentWriter : public AssemblyAnnotationWriter { printDebugLoc(DL,OS); OS << "]"; } - if (const DbgDeclareInst *DDI = dyn_cast(I)) { - if (!Padded) { - OS.PadToColumn(50); - OS << ";"; - } - OS << " [debug variable = " << DDI->getVariable()->getName() << "]"; - } - else if (const DbgValueInst *DVI = dyn_cast(I)) { - if (!Padded) { - OS.PadToColumn(50); - OS << ";"; - } - OS << " [debug variable = " << DVI->getVariable()->getName() << "]"; - } } } }; diff --git a/llvm/unittests/CodeGen/LexicalScopesTest.cpp b/llvm/unittests/CodeGen/LexicalScopesTest.cpp index 3d707462fa615..563d496d1e600 100644 --- a/llvm/unittests/CodeGen/LexicalScopesTest.cpp +++ b/llvm/unittests/CodeGen/LexicalScopesTest.cpp @@ -67,7 +67,7 @@ class LexicalScopesTest : public testing::Test { BeanInst.Opcode = 1; BeanInst.Size = 1; - memset(&DbgValueInst, 0, sizeof(DbgValueInst)); + memset(&DbgValueInst, 0, sizeof(MCInstrDesc)); DbgValueInst.Opcode = TargetOpcode::DBG_VALUE; DbgValueInst.Size = 1; DbgValueInst.Flags = 1U << MCID::Meta; diff --git a/llvm/unittests/IR/DebugInfoTest.cpp b/llvm/unittests/IR/DebugInfoTest.cpp index 41bf863420304..baa13e1199eea 100644 --- a/llvm/unittests/IR/DebugInfoTest.cpp +++ b/llvm/unittests/IR/DebugInfoTest.cpp @@ -188,6 +188,7 @@ TEST(MetadataTest, DeleteInstUsedByDbgRecord) { SmallVector DVIs; SmallVector DVRs; findDbgValues(DVIs, &I, &DVRs); + assert(DVIs.empty()); // Delete %b. The dbg.value should now point to undef. I.eraseFromParent(); @@ -314,6 +315,7 @@ TEST(MetadataTest, DeleteInstUsedByDbgVariableRecord) { SmallVector DVIs; SmallVector DVRs; findDbgValues(DVIs, &I, &DVRs); + assert(DVIs.empty()); ASSERT_EQ(DVRs.size(), 2u); // Delete %b. The DbgVariableRecord should now point to undef.