diff options
| author | Shubham Sandeep Rastogi <srastogi22@apple.com> | 2025-06-27 10:30:29 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-27 10:30:29 -0700 |
| commit | 32ef4ceec03d6510ba19a098a2894a1caeb2704e (patch) | |
| tree | ef80207ebb3f36c2d68c6d3abdfbee3e92587354 /llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp | |
| parent | e4d8e06f83f866786cb5af602857f6d161501593 (diff) | |
[InstrRef] Skip clobbered EntryValue register recovery (#142478)
This changes the final stage of InstrRef, i.e. the TransferTracker
(which combines the values locations with the variable values), so that
it treats a DEBUG_VALUE of an EntryValue just like a DEBUG_VALUE of a
constant: a location that is never clobbered and can be propagated to
subsequent BBs as long as no other DEBUG_VALUE intrinsics updated the
variable.
We add two tests here:
1. `entry_value_clobbered_stack_copy` that saves a register on the
stack, uses this register as an entry value DBG_VALUE location, and then
clobbers it. Prior to this patch, this test would crash because we would
try to describe a new location for the variable in terms of what was
saved on the stack, and use an invalid expression to do so. This is not
needed as an EntryValue can never be clobbered.
2. `entry_value_gets_propagated`, that tests that an EntryValue
DBG_VALUE is propagated in a diamond-shaped CFG.
This patch is trying to reland
https://github.com/llvm/llvm-project/pull/77938 but also fixes the bug
with InstrRef based LiveDebugValues, where entry values were not being
propagated in a diamond-shaped CFG.
Diffstat (limited to 'llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp index fdf50188fbcd..a8143bd8f427 100644 --- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp +++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp @@ -359,6 +359,7 @@ public: SmallVector<ResolvedDbgOp> ResolvedDbgOps; bool IsValueValid = true; unsigned LastUseBeforeDef = 0; + bool DbgLocAvailableAndIsEntryVal = false; // If every value used by the incoming DbgValue is available at block // entry, ResolvedDbgOps will contain the machine locations/constants for @@ -412,6 +413,8 @@ public: // live range. LocIdx M = ValuesPreferredLoc->second.getLoc(); ResolvedDbgOps.push_back(M); + if (Value.Properties.DIExpr->isEntryValue()) + DbgLocAvailableAndIsEntryVal = true; } // If we cannot produce a valid value for the LiveIn value within this @@ -425,6 +428,16 @@ public: return; } + auto &[Var, DILoc] = DVMap.lookupDVID(VarID); + PendingDbgValues.push_back( + std::make_pair(VarID, &*MTracker->emitLoc(ResolvedDbgOps, Var, DILoc, + Value.Properties))); + + // If the location is available at block entry and is an entry value, skip + // tracking and recording thr transfer. + if (DbgLocAvailableAndIsEntryVal) + return; + // The LiveIn value is available at block entry, begin tracking and record // the transfer. for (const ResolvedDbgOp &Op : ResolvedDbgOps) @@ -434,10 +447,6 @@ public: auto Result = ActiveVLocs.insert(std::make_pair(VarID, NewValue)); if (!Result.second) Result.first->second = NewValue; - auto &[Var, DILoc] = DVMap.lookupDVID(VarID); - PendingDbgValues.push_back( - std::make_pair(VarID, &*MTracker->emitLoc(ResolvedDbgOps, Var, DILoc, - Value.Properties))); } /// Load object with live-in variable values. \p mlocs contains the live-in @@ -668,6 +677,16 @@ public: auto &[Var, DILoc] = DVMap.lookupDVID(VarID); + // If the expression is a DW_OP_entry_value, emit the variable location + // as-is. + if (DIExpr->isEntryValue()) { + Register Reg = MTracker->LocIdxToLocID[Num.getLoc()]; + MachineOperand MO = MachineOperand::CreateReg(Reg, false); + PendingDbgValues.push_back(std::make_pair( + VarID, &*emitMOLoc(MO, Var, {DIExpr, Prop.Indirect, false}))); + return true; + } + // Is the variable appropriate for entry values (i.e., is a parameter). if (!isEntryValueVariable(Var, DIExpr)) return false; @@ -694,7 +713,7 @@ public: DebugVariableID VarID = DVMap.getDVID(Var); // Ignore non-register locations, we don't transfer those. - if (MI.isUndefDebugValue() || + if (MI.isUndefDebugValue() || MI.getDebugExpression()->isEntryValue() || all_of(MI.debug_operands(), [](const MachineOperand &MO) { return !MO.isReg(); })) { auto It = ActiveVLocs.find(VarID); |
