Skip to content

Commit 41457bc

Browse files
authored
[NFC][AsmPrinter] Rework/add comments (#145587)
- Add a comment explaining TrackedRegs cache in handleNewDebugValue - Remove a comment which is not meaningful since https://reviews.llvm.org/D4919 - Expand the subject of a comment to match the code it describes
1 parent 2bf0ff3 commit 41457bc

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,18 @@ static void handleNewDebugValue(InlinedEntity Var, const MachineInstr &DV,
374374
DbgValueHistoryMap &HistMap) {
375375
EntryIndex NewIndex;
376376
if (HistMap.startDbgValue(Var, DV, NewIndex)) {
377+
// As we already need to iterate all LiveEntries when handling a DbgValue,
378+
// we use this map to avoid a more expensive check against RegVars. There
379+
// is an assert that we handle this correctly in addRegDescribedVar.
380+
//
381+
// In other terms, the presence in this map indicates the presence of a
382+
// corresponding entry in RegVars.
383+
//
384+
// The bool value then tracks whether an entry is to be retained (true) or
385+
// removed (false); as we end previous entries we speculatively assume they
386+
// can be dropped from RegVars, but we then also visit the new entry whose
387+
// set of debug register operands may overlap and "save" a reg from being
388+
// dropped.
377389
SmallDenseMap<unsigned, bool, 4> TrackedRegs;
378390

379391
// If we have created a new debug value entry, close all preceding
@@ -467,9 +479,6 @@ void llvm::calculateDbgEntityHistory(const MachineFunction *MF,
467479
for (const auto &MI : MBB) {
468480
if (MI.isDebugValue()) {
469481
assert(MI.getNumOperands() > 1 && "Invalid DBG_VALUE instruction!");
470-
// Use the base variable (without any DW_OP_piece expressions)
471-
// as index into History. The full variables including the
472-
// piece expressions are attached to the MI.
473482
const DILocalVariable *RawVar = MI.getDebugVariable();
474483
assert(RawVar->isValidLocationForIntrinsic(MI.getDebugLoc()) &&
475484
"Expected inlined-at fields to agree");
@@ -493,8 +502,7 @@ void llvm::calculateDbgEntityHistory(const MachineFunction *MF,
493502
if (MI.isMetaInstruction())
494503
continue;
495504

496-
// Not a DBG_VALUE instruction. It may clobber registers which describe
497-
// some variables.
505+
// Other instructions may clobber registers which describe some variables.
498506
for (const MachineOperand &MO : MI.operands()) {
499507
if (MO.isReg() && MO.isDef() && MO.getReg()) {
500508
// Ignore call instructions that claim to clobber SP. The AArch64

0 commit comments

Comments
 (0)