Skip to content

Commit 09b832e

Browse files
committed
Support emitting complex expressions that include entry values
This patch enables AsmPrinter support for complex expression with entry values. It shouldn't AsmPrinter's call whether these are safe or not but the pass who introduces the DW_OP_LLVM_entry_value. This patch on its own has no effect on clang. Differential Revision: https://reviews.llvm.org/D96559
1 parent 02413b0 commit 09b832e

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,20 +285,21 @@ bool DwarfExpression::addMachineRegExpression(const TargetRegisterInfo &TRI,
285285
// a call site parameter expression and if that expression is just a register
286286
// location, emit it with addBReg and offset 0, because we should emit a DWARF
287287
// expression representing a value, rather than a location.
288-
if (!isMemoryLocation() && !HasComplexExpression &&
289-
(!isParameterValue() || isEntryValue())) {
288+
if ((!isParameterValue() && !isMemoryLocation() && !HasComplexExpression) ||
289+
isEntryValue()) {
290290
for (auto &Reg : DwarfRegs) {
291291
if (Reg.DwarfRegNo >= 0)
292292
addReg(Reg.DwarfRegNo, Reg.Comment);
293293
addOpPiece(Reg.SubRegSize);
294294
}
295295

296-
if (isEntryValue())
296+
if (isEntryValue()) {
297297
finalizeEntryValue();
298298

299-
if (isEntryValue() && !isIndirect() && !isParameterValue() &&
300-
DwarfVersion >= 4)
301-
emitOp(dwarf::DW_OP_stack_value);
299+
if (!isIndirect() && !isParameterValue() && !HasComplexExpression &&
300+
DwarfVersion >= 4)
301+
emitOp(dwarf::DW_OP_stack_value);
302+
}
302303

303304
DwarfRegs.clear();
304305
return true;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# RUN: llc -filetype=obj -start-after=livedebugvalues -verify-machineinstrs -march=x86-64 -o - %s | llvm-dwarfdump - | FileCheck %s
2+
# CHECK: DW_AT_location (DW_OP_entry_value(DW_OP_reg5 RDI), DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_lit0, DW_OP_plus)
3+
--- |
4+
; ModuleID = '/tmp/e.c'
5+
source_filename = "/tmp/e.c"
6+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
7+
target triple = "x86_64-apple-macosx11.0.0"
8+
9+
; Function Attrs: norecurse nounwind readnone ssp uwtable willreturn
10+
define dso_local void @f(i32 %i) local_unnamed_addr #0 !dbg !8 {
11+
entry:
12+
call void @llvm.dbg.value(metadata i32 %i, metadata !14, metadata !DIExpression()), !dbg !15
13+
ret void, !dbg !16
14+
}
15+
16+
; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
17+
declare void @llvm.dbg.value(metadata, metadata, metadata) #1
18+
19+
attributes #0 = { norecurse nounwind readnone ssp uwtable willreturn }
20+
attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
21+
22+
!llvm.dbg.cu = !{!0}
23+
!llvm.module.flags = !{!3, !4, !5, !6}
24+
25+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, emissionKind: FullDebug)
26+
!1 = !DIFile(filename: "/tmp/e.c", directory: "/")
27+
!2 = !{}
28+
!3 = !{i32 7, !"Dwarf Version", i32 4}
29+
!4 = !{i32 2, !"Debug Info Version", i32 3}
30+
!5 = !{i32 1, !"wchar_size", i32 4}
31+
!6 = !{i32 7, !"PIC Level", i32 2}
32+
!8 = distinct !DISubprogram(name: "f", scope: !9, file: !9, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !13)
33+
!9 = !DIFile(filename: "/tmp/e.c", directory: "")
34+
!10 = !DISubroutineType(types: !11)
35+
!11 = !{null, !12}
36+
!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
37+
!13 = !{!14}
38+
!14 = !DILocalVariable(name: "i", arg: 1, scope: !8, file: !9, line: 1, type: !12)
39+
!15 = !DILocation(line: 0, scope: !8)
40+
!16 = !DILocation(line: 1, column: 16, scope: !8)
41+
42+
...
43+
---
44+
name: f
45+
body: |
46+
bb.0.entry:
47+
DBG_VALUE $edi, $noreg, !14, !DIExpression(DW_OP_LLVM_entry_value, 1, DW_OP_lit0, DW_OP_plus), debug-location !15
48+
frame-setup PUSH64r killed $rbp, implicit-def $rsp, implicit $rsp
49+
$rbp = frame-setup MOV64rr $rsp
50+
$rbp = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !16
51+
RETQ debug-location !16
52+
53+
...

0 commit comments

Comments
 (0)