Skip to content

Commit 22740a4

Browse files
Alternative solution to soliving the entry_value issue.
Treat entry_values as constants, they will be treated just as a DBG_VALUE 1, $noreg, !1, DIExpression(), debug-location !2
1 parent 4b3faa9 commit 22740a4

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -668,16 +668,6 @@ class TransferTracker {
668668

669669
auto &[Var, DILoc] = DVMap.lookupDVID(VarID);
670670

671-
// If the expression is a DW_OP_entry_value, emit the variable location
672-
// as-is.
673-
if (DIExpr->isEntryValue()) {
674-
Register Reg = MTracker->LocIdxToLocID[Num.getLoc()];
675-
MachineOperand MO = MachineOperand::CreateReg(Reg, false);
676-
PendingDbgValues.push_back(std::make_pair(
677-
VarID, &*emitMOLoc(MO, Var, {DIExpr, Prop.Indirect, false})));
678-
return true;
679-
}
680-
681671
// Is the variable appropriate for entry values (i.e., is a parameter).
682672
if (!isEntryValueVariable(Var, DIExpr))
683673
return false;
@@ -1458,7 +1448,10 @@ bool InstrRefBasedLDV::transferDebugValue(const MachineInstr &MI) {
14581448
for (const MachineOperand &MO : MI.debug_operands()) {
14591449
// There should be no undef registers here, as we've screened for undef
14601450
// debug values.
1461-
if (MO.isReg()) {
1451+
if (MI.getDebugExpression()->isEntryValue()) {
1452+
// If the DBG_VALUE is a DW_OP_entry_value, treat it as a constant.
1453+
DebugOps.push_back(DbgOpStore.insert(MO));
1454+
} else if (MO.isReg()) {
14621455
DebugOps.push_back(DbgOpStore.insert(MTracker->readReg(MO.getReg())));
14631456
} else if (MO.isImm() || MO.isFPImm() || MO.isCImm()) {
14641457
DebugOps.push_back(DbgOpStore.insert(MO));

llvm/test/DebugInfo/MIR/InstrRef/entry_value_clobbered_stack_copy.mir

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# RUN: llc --run-pass=livedebugvalues -o - %s | FileCheck %s
22
# REQUIRES: x86-registered-target
33

4+
# This test covers the scenario where a DBG_VALUE created prior to LiveDebugValues has an entry-value expression.
5+
# It tests that an EntryValue DBG_VALUE is propagated in a diamond-shaped CFG.
6+
47
--- |
58
target triple = "x86_64-"
69
define void @foo(ptr swiftasync %0) !dbg !4 {
@@ -47,4 +50,4 @@ body: |
4750
# CHECK: bb.0:
4851
# CHECK: MOV64mr $rbp, 1, $noreg, -48, $noreg, $r14
4952
# CHECK-NEXT: DBG_VALUE $r14, {{.*}}, !DIExpression(DW_OP_LLVM_entry_value, 1)
50-
# CHECK-NOT: DBG_VALUE
53+
# CHECK-NOT: DBG_VALUE

llvm/test/DebugInfo/MIR/InstrRef/entry_value_gets_propagated.mir

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
# RUN: llc --run-pass=livedebugvalues -o - %s | FileCheck %s
1+
# RUN: llc --run-pass=livedebugvalues -o - %s | FileCheck %s --implicit-check-not=DBG_VALUE
22
# REQUIRES: x86-registered-target
3+
4+
# This test covers the scenario where a DBG_VALUE created prior to LiveDebugValues has an entry-value expression.
5+
# It ensures that a clobbered stack copy doesn't crash if used as an entry-value because entry-values can't be clobbered.
6+
37
--- |
48
target triple = "x86_64-"
59

@@ -64,13 +68,13 @@ body: |
6468
successors: %bb.2(0x40000000), %bb.1(0x40000000)
6569
liveins: $r14, $edi, $edx, $esi
6670
DBG_VALUE $r14, $noreg, !14, !DIExpression(DW_OP_LLVM_entry_value, 1), debug-location !19
67-
$r14 = MOV64ri 0, debug-location !20
6871
CMP32ri killed renamable $edx, 0, implicit-def $eflags, debug-location !20
6972
JCC_1 %bb.2, 4, implicit killed $eflags, debug-location !22
7073
bb.1.if.then:
7174
successors: %bb.3(0x80000000)
7275
liveins: $edi, $r13
7376
CALL64pcrel32 @foo, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit-def $eax, debug-location !23
77+
$r14 = MOV64ri 0, debug-location !20
7478
JMP_1 %bb.3, debug-location !25
7579
bb.2.if.else:
7680
successors: %bb.3(0x80000000)
@@ -85,7 +89,10 @@ body: |
8589
# CHECK: DBG_VALUE $r14, {{.*}}, !DIExpression(DW_OP_LLVM_entry_value, 1)
8690
# CHECK-LABEL: bb.1.if.then:
8791
# CHECK: DBG_VALUE $r14, {{.*}}, !DIExpression(DW_OP_LLVM_entry_value, 1)
92+
# CHECK-NEXT: CALL64pcrel32 @foo
93+
# CHECK-NEXT: $r14 = MOV64ri 0
94+
# CHECK-NOT: DBG_VALUE $r14, {{.*}}, !DIExpression(DW_OP_LLVM_entry_value, 1)
8895
# CHECK-LABEL: bb.2.if.else:
8996
# CHECK: DBG_VALUE $r14, {{.*}}, !DIExpression(DW_OP_LLVM_entry_value, 1)
9097
# CHECK-LABEL: bb.3.if.end:
91-
# CHECK: DBG_VALUE $r14, {{.*}}, !DIExpression(DW_OP_LLVM_entry_value, 1)
98+
# CHECK: DBG_VALUE $r14, {{.*}}, !DIExpression(DW_OP_LLVM_entry_value, 1)

0 commit comments

Comments
 (0)