Skip to content

Commit 8841709

Browse files
[CodeGen][DebugInfo] Append OP_deref when converting an EntryValue dbg.declare
When we convert an EntryValue dbg.declare into an entry of the MF side table, we currently copy its DIExpression as is, and rely on subsequent layers to "know" that this expression is implicitly indirect. This is bad because it adds an implicit assumption to the IR representation, and requires subsequent layers to know about this assumption. This also limits the reusability of this table: what if, in the future, we want to use this table for dbg.values? This patch changes existing behavior so that the entities converting dbg_declares explicitly add an OP_deref when converting EntryValue dbg.declares. Differential Revision: https://reviews.llvm.org/D158437
1 parent 4efd1e0 commit 8841709

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,7 @@ void DwarfDebug::collectVariableInfoFromMFTable(
15651565
if (VI.inStackSlot())
15661566
RegVar->initializeMMI(VI.Expr, VI.getStackSlot());
15671567
else {
1568-
MachineLocation MLoc(VI.getEntryValueRegister(), /*IsIndirect*/ true);
1568+
MachineLocation MLoc(VI.getEntryValueRegister(), /*IsIndirect*/ false);
15691569
auto LocEntry = DbgValueLocEntry(MLoc);
15701570
RegVar->initializeDbgValue(DbgValueLoc(VI.Expr, LocEntry));
15711571
}

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,8 @@ bool IRTranslator::translateIfEntryValueArgument(
19431943
if (!PhysReg)
19441944
return false;
19451945

1946+
// Append an op deref to account for the fact that this is a dbg_declare.
1947+
Expr = DIExpression::append(Expr, dwarf::DW_OP_deref);
19461948
MF->setVariableDbgInfo(DebugInst.getVariable(), Expr, *PhysReg,
19471949
DebugInst.getDebugLoc());
19481950
return true;

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,8 @@ static bool processIfEntryValueDbgDeclare(FunctionLoweringInfo &FuncInfo,
13571357
// Find the corresponding livein physical register to this argument.
13581358
for (auto [PhysReg, VirtReg] : FuncInfo.RegInfo->liveins())
13591359
if (VirtReg == ArgVReg) {
1360+
// Append an op deref to account for the fact that this is a dbg_declare.
1361+
Expr = DIExpression::append(Expr, dwarf::DW_OP_deref);
13601362
FuncInfo.MF->setVariableDbgInfo(Var, Expr, PhysReg, DbgLoc);
13611363
LLVM_DEBUG(dbgs() << "processDbgDeclare: setVariableDbgInfo Var=" << *Var
13621364
<< ", Expr=" << *Expr << ", MCRegister=" << PhysReg

llvm/test/CodeGen/AArch64/dbg-declare-swift-async.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
; RUN: llc -O0 -fast-isel=false -global-isel=false -stop-after=finalize-isel %s -o - | FileCheck %s
44

55
; CHECK: void @foo
6-
; CHECK-NEXT: dbg.declare(metadata {{.*}}, metadata ![[VAR:.*]], metadata ![[EXPR:.*]]), !dbg ![[LOC:.*]]
6+
; CHECK-NEXT: dbg.declare(metadata {{.*}}, metadata ![[VAR:.*]], metadata !DIExpression([[EXPR:.*]])), !dbg ![[LOC:.*]]
77
; CHECK: entry_values:
8-
; CHECK-NEXT: entry-value-register: '$x22', debug-info-variable: '![[VAR]]', debug-info-expression: '![[EXPR]]',
8+
; CHECK-NEXT: entry-value-register: '$x22', debug-info-variable: '![[VAR]]', debug-info-expression: '!DIExpression([[EXPR]], DW_OP_deref)',
99
; CHECK-NEXT: debug-info-location: '![[LOC]]
10-
; CHECK-NEXT: entry-value-register: '$x22', debug-info-variable: '![[VAR]]', debug-info-expression: '![[EXPR]]'
10+
; CHECK-NEXT: entry-value-register: '$x22', debug-info-variable: '![[VAR]]', debug-info-expression: '!DIExpression([[EXPR]], DW_OP_deref)'
1111
; CHECK-NEXT: debug-info-location: '![[LOC]]
1212

1313
; CHECK-NOT: DBG_VALUE

llvm/test/DebugInfo/AArch64/dbg-entry-value-swiftasync.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ stack:
3636
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
3737
stack-id: default, callee-saved-register: '$lr', callee-saved-restored: true }
3838
entry_values:
39-
- { entry-value-register: '$x22', debug-info-variable: '!10', debug-info-expression: '!DIExpression(DW_OP_LLVM_entry_value, 1)',
39+
- { entry-value-register: '$x22', debug-info-variable: '!10', debug-info-expression: '!DIExpression(DW_OP_LLVM_entry_value, 1, DW_OP_deref)',
4040
debug-info-location: '!12' }
4141
body: |
4242
bb.0 (%ir-block.0):

0 commit comments

Comments
 (0)