More bugs squashed.
This commit is contained in:
parent
d10d3b9fc6
commit
52c4416b7e
1 changed files with 25 additions and 14 deletions
|
|
@ -549,12 +549,16 @@ bool W65816StackSlotMerge::runOnMachineFunction(MachineFunction &MF) {
|
||||||
// a DBG_VALUE that still points at slot-X reads stale data.
|
// a DBG_VALUE that still points at slot-X reads stale data.
|
||||||
//
|
//
|
||||||
// For DBG_VALUEs whose DIExpression has a leading constant offset that
|
// For DBG_VALUEs whose DIExpression has a leading constant offset that
|
||||||
// matches a renamed slot, we mark them as undef. This loses debug
|
// matches a renamed slot X, relocate them to the merged slot Y by
|
||||||
// info at the affected PC range but never reports a wrong variable
|
// rewriting that leading offset (the merge proved X and Y hold
|
||||||
// value. A future enhancement could rewrite the offset to point at
|
// equivalent values function-wide, so Y's memory is a correct location
|
||||||
// the merged slot Y (the merge proves they hold equivalent values
|
// for the variable). The trailing ops are preserved verbatim and the
|
||||||
// function-wide), but that requires DIExpression rewriting and
|
// offset is re-encoded with the canonical appendOffset form, which is
|
||||||
// re-uniquing which is non-trivial in this position.
|
// exactly what extractLeadingOffset decodes -- so this is faithful.
|
||||||
|
// This keeps the variable's location live across the rename; previously
|
||||||
|
// we dropped it (setDebugValueUndef), losing debug info at those PCs.
|
||||||
|
// Falls back to undef only if re-encoding somehow fails.
|
||||||
|
LLVMContext &Ctx = MF.getFunction().getContext();
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
for (MachineBasicBlock &MBB : MF) {
|
for (MachineBasicBlock &MBB : MF) {
|
||||||
for (MachineInstr &MI : MBB) {
|
for (MachineInstr &MI : MBB) {
|
||||||
|
|
@ -565,14 +569,21 @@ bool W65816StackSlotMerge::runOnMachineFunction(MachineFunction &MF) {
|
||||||
SmallVector<uint64_t, 4> Remaining;
|
SmallVector<uint64_t, 4> Remaining;
|
||||||
if (!Expr->extractLeadingOffset(LeadingOff, Remaining))
|
if (!Expr->extractLeadingOffset(LeadingOff, Remaining))
|
||||||
continue;
|
continue;
|
||||||
if (!Renames.count(LeadingOff)) continue;
|
auto RIt = Renames.find(LeadingOff);
|
||||||
// Match: this DBG_VALUE points at slot X (now renamed). Undef
|
if (RIt == Renames.end()) continue;
|
||||||
// every register debug operand to drop the location at this PC.
|
// Match: this DBG_VALUE points at slot X (now renamed to Y).
|
||||||
for (MachineOperand &Op : MI.debug_operands()) {
|
SmallVector<uint64_t, 8> NewOps;
|
||||||
if (Op.isReg()) {
|
DIExpression::appendOffset(NewOps, RIt->second);
|
||||||
Op.setReg(0);
|
NewOps.append(Remaining.begin(), Remaining.end());
|
||||||
Op.setSubReg(0);
|
if (const DIExpression *NewExpr = DIExpression::get(Ctx, NewOps)) {
|
||||||
}
|
MI.getDebugExpressionOp().setMetadata(NewExpr);
|
||||||
|
} else {
|
||||||
|
// Should not happen; keep the old fail-safe behavior.
|
||||||
|
for (MachineOperand &Op : MI.debug_operands())
|
||||||
|
if (Op.isReg()) {
|
||||||
|
Op.setReg(0);
|
||||||
|
Op.setSubReg(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Changed = true;
|
Changed = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue