Skip to content

Commit c9d8b68

Browse files
jmorsenikic
andauthored
[DebugInfo] Suppress lots of users of DbgValueInst (#149476)
This is another prune of dead code -- we never generate debug intrinsics nowadays, therefore there's no need for these codepaths to run. --------- Co-authored-by: Nikita Popov <[email protected]>
1 parent 4fbe88f commit c9d8b68

File tree

15 files changed

+109
-326
lines changed

15 files changed

+109
-326
lines changed

llvm/include/llvm/Transforms/Utils/SSAUpdater.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ template <typename T> class SSAUpdaterTraits;
2929
class Type;
3030
class Use;
3131
class Value;
32-
class DbgValueInst;
3332

3433
/// Helper class for SSA formation on a set of values defined in
3534
/// multiple blocks.
@@ -122,8 +121,6 @@ class SSAUpdater {
122121
/// the instruction. Anything outside of its block will have its
123122
/// value set to the new SSA value if available, and undef if not.
124123
void UpdateDebugValues(Instruction *I);
125-
void UpdateDebugValues(Instruction *I,
126-
SmallVectorImpl<DbgValueInst *> &DbgValues);
127124
void UpdateDebugValues(Instruction *I,
128125
SmallVectorImpl<DbgVariableRecord *> &DbgValues);
129126

@@ -136,7 +133,6 @@ class SSAUpdater {
136133

137134
private:
138135
Value *GetValueAtEndOfBlockInternal(BasicBlock *BB);
139-
void UpdateDebugValue(Instruction *I, DbgValueInst *DbgValue);
140136
void UpdateDebugValue(Instruction *I, DbgVariableRecord *DbgValue);
141137
};
142138

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ class CodeGenPrepare {
445445
bool optimizeSwitchInst(SwitchInst *SI);
446446
bool optimizeExtractElementInst(Instruction *Inst);
447447
bool dupRetToEnableTailCallOpts(BasicBlock *BB, ModifyDT &ModifiedDT);
448-
bool fixupDbgValue(Instruction *I);
449448
bool fixupDbgVariableRecord(DbgVariableRecord &I);
450449
bool fixupDbgVariableRecordsOnInst(Instruction &I);
451450
bool placeDbgValues(Function &F);
@@ -2762,9 +2761,6 @@ bool CodeGenPrepare::optimizeCallInst(CallInst *CI, ModifyDT &ModifiedDT) {
27622761
case Intrinsic::fshl:
27632762
case Intrinsic::fshr:
27642763
return optimizeFunnelShift(II);
2765-
case Intrinsic::dbg_assign:
2766-
case Intrinsic::dbg_value:
2767-
return fixupDbgValue(II);
27682764
case Intrinsic::masked_gather:
27692765
return optimizeGatherScatterInst(II, II->getArgOperand(0));
27702766
case Intrinsic::masked_scatter:
@@ -3554,8 +3550,6 @@ class TypePromotionTransaction {
35543550
/// Keep track of the original uses (pair Instruction, Index).
35553551
SmallVector<InstructionAndIdx, 4> OriginalUses;
35563552
/// Keep track of the debug users.
3557-
SmallVector<DbgValueInst *, 1> DbgValues;
3558-
/// And non-instruction debug-users too.
35593553
SmallVector<DbgVariableRecord *, 1> DbgVariableRecords;
35603554

35613555
/// Keep track of the new value so that we can undo it by replacing
@@ -3577,7 +3571,9 @@ class TypePromotionTransaction {
35773571
}
35783572
// Record the debug uses separately. They are not in the instruction's
35793573
// use list, but they are replaced by RAUW.
3574+
SmallVector<DbgValueInst *> DbgValues;
35803575
findDbgValues(DbgValues, Inst, &DbgVariableRecords);
3576+
assert(DbgValues.empty());
35813577

35823578
// Now, we can replace the uses.
35833579
Inst->replaceAllUsesWith(New);
@@ -3591,11 +3587,7 @@ class TypePromotionTransaction {
35913587
// RAUW has replaced all original uses with references to the new value,
35923588
// including the debug uses. Since we are undoing the replacements,
35933589
// the original debug uses must also be reinstated to maintain the
3594-
// correctness and utility of debug value instructions.
3595-
for (auto *DVI : DbgValues)
3596-
DVI->replaceVariableLocationOp(New, Inst);
3597-
// Similar story with DbgVariableRecords, the non-instruction
3598-
// representation of dbg.values.
3590+
// correctness and utility of debug value records.
35993591
for (DbgVariableRecord *DVR : DbgVariableRecords)
36003592
DVR->replaceVariableLocationOp(New, Inst);
36013593
}
@@ -8933,32 +8925,6 @@ bool CodeGenPrepare::optimizeBlock(BasicBlock &BB, ModifyDT &ModifiedDT) {
89338925
return MadeChange;
89348926
}
89358927

8936-
// Some CGP optimizations may move or alter what's computed in a block. Check
8937-
// whether a dbg.value intrinsic could be pointed at a more appropriate operand.
8938-
bool CodeGenPrepare::fixupDbgValue(Instruction *I) {
8939-
assert(isa<DbgValueInst>(I));
8940-
DbgValueInst &DVI = *cast<DbgValueInst>(I);
8941-
8942-
// Does this dbg.value refer to a sunk address calculation?
8943-
bool AnyChange = false;
8944-
SmallDenseSet<Value *> LocationOps(DVI.location_ops().begin(),
8945-
DVI.location_ops().end());
8946-
for (Value *Location : LocationOps) {
8947-
WeakTrackingVH SunkAddrVH = SunkAddrs[Location];
8948-
Value *SunkAddr = SunkAddrVH.pointsToAliveValue() ? SunkAddrVH : nullptr;
8949-
if (SunkAddr) {
8950-
// Point dbg.value at locally computed address, which should give the best
8951-
// opportunity to be accurately lowered. This update may change the type
8952-
// of pointer being referred to; however this makes no difference to
8953-
// debugging information, and we can't generate bitcasts that may affect
8954-
// codegen.
8955-
DVI.replaceVariableLocationOp(Location, SunkAddr);
8956-
AnyChange = true;
8957-
}
8958-
}
8959-
return AnyChange;
8960-
}
8961-
89628928
bool CodeGenPrepare::fixupDbgVariableRecordsOnInst(Instruction &I) {
89638929
bool AnyChange = false;
89648930
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange()))
@@ -8993,14 +8959,6 @@ bool CodeGenPrepare::fixupDbgVariableRecord(DbgVariableRecord &DVR) {
89938959
return AnyChange;
89948960
}
89958961

8996-
static void DbgInserterHelper(DbgValueInst *DVI, BasicBlock::iterator VI) {
8997-
DVI->removeFromParent();
8998-
if (isa<PHINode>(VI))
8999-
DVI->insertBefore(VI->getParent()->getFirstInsertionPt());
9000-
else
9001-
DVI->insertAfter(VI);
9002-
}
9003-
90048962
static void DbgInserterHelper(DbgVariableRecord *DVR, BasicBlock::iterator VI) {
90058963
DVR->removeFromParent();
90068964
BasicBlock *VIBB = VI->getParent();
@@ -9065,15 +9023,8 @@ bool CodeGenPrepare::placeDbgValues(Function &F) {
90659023

90669024
for (BasicBlock &BB : F) {
90679025
for (Instruction &Insn : llvm::make_early_inc_range(BB)) {
9068-
// Process dbg.value intrinsics.
9069-
DbgValueInst *DVI = dyn_cast<DbgValueInst>(&Insn);
9070-
if (DVI) {
9071-
DbgProcessor(DVI, DVI);
9072-
continue;
9073-
}
9074-
9075-
// If this isn't a dbg.value, process any attached DbgVariableRecord
9076-
// records attached to this instruction.
9026+
// Process any DbgVariableRecord records attached to this
9027+
// instruction.
90779028
for (DbgVariableRecord &DVR : llvm::make_early_inc_range(
90789029
filterDbgVars(Insn.getDbgRecordRange()))) {
90799030
if (DVR.Type != DbgVariableRecord::LocationType::Value)

llvm/lib/CodeGen/MachineDebugify.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,9 @@ bool applyDebugifyMetadataToMachineFunction(MachineModuleInfo &MMI,
6363
// which cover a wide range of lines can help stress the debug info passes:
6464
// if we can't do that, fall back to using the local variable which precedes
6565
// all the others.
66-
Function *DbgValF = M.getFunction("llvm.dbg.value");
67-
DbgValueInst *EarliestDVI = nullptr;
6866
DbgVariableRecord *EarliestDVR = nullptr;
6967
DenseMap<unsigned, DILocalVariable *> Line2Var;
7068
DIExpression *Expr = nullptr;
71-
if (DbgValF) {
72-
for (const Use &U : DbgValF->uses()) {
73-
auto *DVI = dyn_cast<DbgValueInst>(U.getUser());
74-
if (!DVI || DVI->getFunction() != &F)
75-
continue;
76-
unsigned Line = DVI->getDebugLoc().getLine();
77-
assert(Line != 0 && "debugify should not insert line 0 locations");
78-
Line2Var[Line] = DVI->getVariable();
79-
if (!EarliestDVI || Line < EarliestDVI->getDebugLoc().getLine())
80-
EarliestDVI = DVI;
81-
Expr = DVI->getExpression();
82-
}
83-
}
8469
for (BasicBlock &BB : F) {
8570
for (Instruction &I : BB) {
8671
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
@@ -125,8 +110,7 @@ bool applyDebugifyMetadataToMachineFunction(MachineModuleInfo &MMI,
125110
unsigned Line = MI.getDebugLoc().getLine();
126111
auto It = Line2Var.find(Line);
127112
if (It == Line2Var.end()) {
128-
Line = EarliestDVI ? EarliestDVI->getDebugLoc().getLine()
129-
: EarliestDVR->getDebugLoc().getLine();
113+
Line = EarliestDVR->getDebugLoc().getLine();
130114
It = Line2Var.find(Line);
131115
assert(It != Line2Var.end());
132116
}

llvm/lib/Transforms/Coroutines/SpillUtils.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,17 +514,15 @@ void collectSpillsAndAllocasFromInsts(
514514
void collectSpillsFromDbgInfo(SpillInfo &Spills, Function &F,
515515
const SuspendCrossingInfo &Checker) {
516516
// We don't want the layout of coroutine frame to be affected
517-
// by debug information. So we only choose to salvage DbgValueInst for
517+
// by debug information. So we only choose to salvage dbg.values for
518518
// whose value is already in the frame.
519519
// We would handle the dbg.values for allocas specially
520520
for (auto &Iter : Spills) {
521521
auto *V = Iter.first;
522522
SmallVector<DbgValueInst *, 16> DVIs;
523523
SmallVector<DbgVariableRecord *, 16> DVRs;
524524
findDbgValues(DVIs, V, &DVRs);
525-
for (DbgValueInst *DVI : DVIs)
526-
if (Checker.isDefinitionAcrossSuspend(*V, DVI))
527-
Spills[V].push_back(DVI);
525+
assert(DVIs.empty());
528526
// Add the instructions which carry debug info that is in the frame.
529527
for (DbgVariableRecord *DVR : DVRs)
530528
if (Checker.isDefinitionAcrossSuspend(*V, DVR->Marker->MarkedInstr))

llvm/lib/Transforms/IPO/MergeFunctions.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ void MergeFunctions::filterInstsUnrelatedToPDI(
572572

573573
// Work out whether a dbg.value intrinsic or an equivalent DbgVariableRecord
574574
// is a parameter to be preserved.
575-
auto ExamineDbgValue = [](auto *DbgVal, auto &Container) {
575+
auto ExamineDbgValue = [&PDVRRelated](DbgVariableRecord *DbgVal) {
576576
LLVM_DEBUG(dbgs() << " Deciding: ");
577577
LLVM_DEBUG(DbgVal->print(dbgs()));
578578
LLVM_DEBUG(dbgs() << "\n");
@@ -581,15 +581,16 @@ void MergeFunctions::filterInstsUnrelatedToPDI(
581581
LLVM_DEBUG(dbgs() << " Include (parameter): ");
582582
LLVM_DEBUG(DbgVal->print(dbgs()));
583583
LLVM_DEBUG(dbgs() << "\n");
584-
Container.insert(DbgVal);
584+
PDVRRelated.insert(DbgVal);
585585
} else {
586586
LLVM_DEBUG(dbgs() << " Delete (!parameter): ");
587587
LLVM_DEBUG(DbgVal->print(dbgs()));
588588
LLVM_DEBUG(dbgs() << "\n");
589589
}
590590
};
591591

592-
auto ExamineDbgDeclare = [&PDIRelated](auto *DbgDecl, auto &Container) {
592+
auto ExamineDbgDeclare = [&PDIRelated,
593+
&PDVRRelated](DbgVariableRecord *DbgDecl) {
593594
LLVM_DEBUG(dbgs() << " Deciding: ");
594595
LLVM_DEBUG(DbgDecl->print(dbgs()));
595596
LLVM_DEBUG(dbgs() << "\n");
@@ -616,7 +617,7 @@ void MergeFunctions::filterInstsUnrelatedToPDI(
616617
LLVM_DEBUG(dbgs() << " Include: ");
617618
LLVM_DEBUG(DbgDecl->print(dbgs()));
618619
LLVM_DEBUG(dbgs() << "\n");
619-
Container.insert(DbgDecl);
620+
PDVRRelated.insert(DbgDecl);
620621
} else {
621622
LLVM_DEBUG(dbgs() << " Delete (!parameter): ");
622623
LLVM_DEBUG(SI->print(dbgs()));
@@ -647,18 +648,14 @@ void MergeFunctions::filterInstsUnrelatedToPDI(
647648
// they connected to parameters?
648649
for (DbgVariableRecord &DVR : filterDbgVars(BI->getDbgRecordRange())) {
649650
if (DVR.isDbgValue() || DVR.isDbgAssign()) {
650-
ExamineDbgValue(&DVR, PDVRRelated);
651+
ExamineDbgValue(&DVR);
651652
} else {
652653
assert(DVR.isDbgDeclare());
653-
ExamineDbgDeclare(&DVR, PDVRRelated);
654+
ExamineDbgDeclare(&DVR);
654655
}
655656
}
656657

657-
if (auto *DVI = dyn_cast<DbgValueInst>(&*BI)) {
658-
ExamineDbgValue(DVI, PDIRelated);
659-
} else if (auto *DDI = dyn_cast<DbgDeclareInst>(&*BI)) {
660-
ExamineDbgDeclare(DDI, PDIRelated);
661-
} else if (BI->isTerminator() && &*BI == GEntryBlock->getTerminator()) {
658+
if (BI->isTerminator() && &*BI == GEntryBlock->getTerminator()) {
662659
LLVM_DEBUG(dbgs() << " Will Include Terminator: ");
663660
LLVM_DEBUG(BI->print(dbgs()));
664661
LLVM_DEBUG(dbgs() << "\n");

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,21 +1420,16 @@ void InstCombinerImpl::freelyInvertAllUsersOf(Value *I, Value *IgnoredUser) {
14201420
SmallVector<DbgValueInst *, 4> DbgValues;
14211421
SmallVector<DbgVariableRecord *, 4> DbgVariableRecords;
14221422
llvm::findDbgValues(DbgValues, I, &DbgVariableRecords);
1423+
assert(DbgValues.empty());
14231424

1424-
auto InvertDbgValueUse = [&](auto *DbgVal) {
1425+
for (DbgVariableRecord *DbgVal : DbgVariableRecords) {
14251426
SmallVector<uint64_t, 1> Ops = {dwarf::DW_OP_not};
14261427
for (unsigned Idx = 0, End = DbgVal->getNumVariableLocationOps();
14271428
Idx != End; ++Idx)
14281429
if (DbgVal->getVariableLocationOp(Idx) == I)
14291430
DbgVal->setExpression(
14301431
DIExpression::appendOpsToArg(DbgVal->getExpression(), Ops, Idx));
1431-
};
1432-
1433-
for (DbgValueInst *DVI : DbgValues)
1434-
InvertDbgValueUse(DVI);
1435-
1436-
for (DbgVariableRecord *DVR : DbgVariableRecords)
1437-
InvertDbgValueUse(DVR);
1432+
}
14381433
}
14391434

14401435
/// Given a 'sub' instruction, return the RHS of the instruction if the LHS is a

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,15 +1979,13 @@ void JumpThreadingPass::updateSSA(BasicBlock *BB, BasicBlock *NewBB,
19791979

19801980
// Find debug values outside of the block
19811981
findDbgValues(DbgValues, &I, &DbgVariableRecords);
1982-
llvm::erase_if(DbgValues, [&](const DbgValueInst *DbgVal) {
1983-
return DbgVal->getParent() == BB;
1984-
});
1982+
assert(DbgValues.empty());
19851983
llvm::erase_if(DbgVariableRecords, [&](const DbgVariableRecord *DbgVarRec) {
19861984
return DbgVarRec->getParent() == BB;
19871985
});
19881986

19891987
// If there are no uses outside the block, we're done with this instruction.
1990-
if (UsesToRename.empty() && DbgValues.empty() && DbgVariableRecords.empty())
1988+
if (UsesToRename.empty() && DbgVariableRecords.empty())
19911989
continue;
19921990
LLVM_DEBUG(dbgs() << "JT: Renaming non-local uses of: " << I << "\n");
19931991

@@ -2000,8 +1998,7 @@ void JumpThreadingPass::updateSSA(BasicBlock *BB, BasicBlock *NewBB,
20001998

20011999
while (!UsesToRename.empty())
20022000
SSAUpdate.RewriteUse(*UsesToRename.pop_back_val());
2003-
if (!DbgValues.empty() || !DbgVariableRecords.empty()) {
2004-
SSAUpdate.UpdateDebugValues(&I, DbgValues);
2001+
if (!DbgVariableRecords.empty()) {
20052002
SSAUpdate.UpdateDebugValues(&I, DbgVariableRecords);
20062003
DbgValues.clear();
20072004
DbgVariableRecords.clear();
@@ -2032,32 +2029,7 @@ void JumpThreadingPass::cloneInstructions(ValueToValueMapTy &ValueMapping,
20322029
// copy of the block 'NewBB'. If there are PHI nodes in the source basic
20332030
// block, evaluate them to account for entry from PredBB.
20342031

2035-
// Retargets llvm.dbg.value to any renamed variables.
2036-
auto RetargetDbgValueIfPossible = [&](Instruction *NewInst) -> bool {
2037-
auto DbgInstruction = dyn_cast<DbgValueInst>(NewInst);
2038-
if (!DbgInstruction)
2039-
return false;
2040-
2041-
SmallSet<std::pair<Value *, Value *>, 16> OperandsToRemap;
2042-
for (auto DbgOperand : DbgInstruction->location_ops()) {
2043-
auto DbgOperandInstruction = dyn_cast<Instruction>(DbgOperand);
2044-
if (!DbgOperandInstruction)
2045-
continue;
2046-
2047-
auto I = ValueMapping.find(DbgOperandInstruction);
2048-
if (I != ValueMapping.end()) {
2049-
OperandsToRemap.insert(
2050-
std::pair<Value *, Value *>(DbgOperand, I->second));
2051-
}
2052-
}
2053-
2054-
for (auto &[OldOp, MappedOp] : OperandsToRemap)
2055-
DbgInstruction->replaceVariableLocationOp(OldOp, MappedOp);
2056-
return true;
2057-
};
2058-
2059-
// Duplicate implementation of the above dbg.value code, using
2060-
// DbgVariableRecords instead.
2032+
// Retargets dbg.value to any renamed variables.
20612033
auto RetargetDbgVariableRecordIfPossible = [&](DbgVariableRecord *DVR) {
20622034
SmallSet<std::pair<Value *, Value *>, 16> OperandsToRemap;
20632035
for (auto *Op : DVR->location_ops()) {
@@ -2116,9 +2088,6 @@ void JumpThreadingPass::cloneInstructions(ValueToValueMapTy &ValueMapping,
21162088
if (const DebugLoc &DL = New->getDebugLoc())
21172089
mapAtomInstance(DL, ValueMapping);
21182090

2119-
if (RetargetDbgValueIfPossible(New))
2120-
continue;
2121-
21222091
// Remap operands to patch up intra-block references.
21232092
for (unsigned i = 0, e = New->getNumOperands(); i != e; ++i)
21242093
if (Instruction *Inst = dyn_cast<Instruction>(New->getOperand(i))) {

0 commit comments

Comments
 (0)