Skip to content

Commit 1ee84e5

Browse files
committed
[DebugInfo] Allow spill slots in call site parameter descriptions
Allow call site paramter descriptions to reference spill slots. Spill slots are not visible to high-level LLVM IR, so they can safely be referenced during entry value evaluation (as they cannot be clobbered by some other function). This gives a 5% increase in the number of call site parameter DIEs in an LTO x86_64 build of the xnu kernel. This reverts commit eb4c98c ( [DebugInfo] Exclude memory location values as parameter entry values), effectively reintroducing the portion of D60716 which dealt with memory locations (authored by Djordje, Nikola, Ananth, and Ivan). This partially addresses llvm.org/PR43343. However, not all memory operands forwarded to callees live in spill slots. In the xnu build, it may be possible to use an escape analysis to increase the number of call site parameter by another 15% (more details in PR43343). Differential Revision: https://reviews.llvm.org/D70254
1 parent 4d02263 commit 1ee84e5

File tree

3 files changed

+200
-5
lines changed

3 files changed

+200
-5
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ bool DwarfExpression::addMachineRegExpression(const TargetRegisterInfo &TRI,
246246
// a call site parameter expression and if that expression is just a register
247247
// location, emit it with addBReg and offset 0, because we should emit a DWARF
248248
// expression representing a value, rather than a location.
249-
if (!isMemoryLocation() && !HasComplexExpression &&
250-
(!isParameterValue() || isEntryValue())) {
249+
if (!isMemoryLocation() && !HasComplexExpression && (!isParameterValue() ||
250+
isEntryValue())) {
251251
for (auto &Reg : DwarfRegs) {
252252
if (Reg.DwarfRegNo >= 0)
253253
addReg(Reg.DwarfRegNo, Reg.Comment);
@@ -436,9 +436,6 @@ void DwarfExpression::addExpression(DIExpressionCursor &&ExprCursor,
436436
break;
437437
case dwarf::DW_OP_deref:
438438
assert(!isRegisterLocation());
439-
// For more detailed explanation see llvm.org/PR43343.
440-
assert(!isParameterValue() && "Parameter entry values should not be "
441-
"dereferenced due to safety reasons.");
442439
if (!isMemoryLocation() && ::isMemoryLocation(ExprCursor))
443440
// Turning this into a memory location description makes the deref
444441
// implicit.

llvm/lib/CodeGen/TargetInstrInfo.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,27 @@ TargetInstrInfo::describeLoadedValue(const MachineInstr &MI) const {
11311131
} else if (auto DestSrc = isAddImmediate(MI, Offset)) {
11321132
Expr = DIExpression::prepend(Expr, DIExpression::ApplyOffset, Offset);
11331133
return ParamLoadedValue(*DestSrc->Source, Expr);
1134+
} else if (MI.hasOneMemOperand()) {
1135+
// Only describe memory which provably does not escape the function. As
1136+
// described in llvm.org/PR43343, escaped memory may be clobbered by the
1137+
// callee (or by another thread).
1138+
const auto &TII = MF->getSubtarget().getInstrInfo();
1139+
const MachineFrameInfo &MFI = MF->getFrameInfo();
1140+
const MachineMemOperand *MMO = MI.memoperands()[0];
1141+
const PseudoSourceValue *PSV = MMO->getPseudoValue();
1142+
1143+
// If the address points to "special" memory (e.g. a spill slot), it's
1144+
// sufficient to check that it isn't aliased by any high-level IR value.
1145+
if (!PSV || PSV->mayAlias(&MFI))
1146+
return None;
1147+
1148+
const auto &TRI = MF->getSubtarget().getRegisterInfo();
1149+
const MachineOperand *BaseOp;
1150+
if (!TII->getMemOperandWithOffset(MI, BaseOp, Offset, TRI))
1151+
return None;
1152+
1153+
Expr = DIExpression::prepend(Expr, DIExpression::DerefAfter, Offset);
1154+
return ParamLoadedValue(*BaseOp, Expr);
11341155
}
11351156

11361157
return None;
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# Check that llvm can describe a call site parameter which resides in a spill slot.
2+
#
3+
# RUN: llc -debug-entry-values -start-after=machineverifier -filetype=obj %s -o - | llvm-dwarfdump - | FileCheck %s
4+
#
5+
# Command:
6+
# $ ~/src/builds/llvm-project-master-RA/bin/clang -g -Xclang -femit-debug-entry-values -O2 -c -o spill.o spill.cc -mllvm -stop-before=machineverifier -o spill.mir
7+
#
8+
# Source:
9+
## extern void callee(int);
10+
##
11+
## #define FORCE_SPILL() \
12+
## asm volatile("" \
13+
## : \
14+
## : \
15+
## : "rax", "rbx", "rcx", "rdx", "rsi", "rdi", "rbp", "r8", "r9", \
16+
## "r10", "r11", "r12", "r13", "r14", "r15")
17+
##
18+
## __attribute__((disable_tail_calls)) void caller(int x) {
19+
## FORCE_SPILL();
20+
## callee(x);
21+
## }
22+
23+
# CHECK-LABEL: DW_TAG_call_site_parameter
24+
# CHECK-NEXT: DW_AT_location (DW_OP_reg5 RDI)
25+
# CHECK-NEXT: DW_AT_call_value (DW_OP_fbreg -44, DW_OP_deref)
26+
27+
--- |
28+
; ModuleID = 'spill.cc'
29+
source_filename = "spill.cc"
30+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
31+
target triple = "x86_64-apple-macosx10.14.0"
32+
33+
; Function Attrs: ssp uwtable
34+
define void @_Z6calleri(i32 %x) local_unnamed_addr #0 !dbg !13 {
35+
entry:
36+
call void @llvm.dbg.value(metadata i32 %x, metadata !15, metadata !DIExpression()), !dbg !16
37+
call void asm sideeffect "", "~{rax},~{rbx},~{rcx},~{rdx},~{rsi},~{rdi},~{rbp},~{r8},~{r9},~{r10},~{r11},~{r12},~{r13},~{r14},~{r15},~{dirflag},~{fpsr},~{flags}"(), !dbg !17, !srcloc !18
38+
call void @_Z6calleei(i32 %x), !dbg !19
39+
ret void, !dbg !20
40+
}
41+
42+
declare !dbg !4 void @_Z6calleei(i32) local_unnamed_addr
43+
44+
; Function Attrs: nounwind readnone speculatable willreturn
45+
declare void @llvm.dbg.value(metadata, metadata, metadata)
46+
47+
; Function Attrs: nounwind
48+
declare void @llvm.stackprotector(i8*, i8**)
49+
50+
attributes #0 = { "disable-tail-calls"="true" "frame-pointer"="all" }
51+
52+
!llvm.dbg.cu = !{!0}
53+
!llvm.module.flags = !{!8, !9, !10, !11}
54+
!llvm.ident = !{!12}
55+
56+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 10.0.0 ([email protected]:llvm/llvm-project.git 132f768649d8f21d577ee220e5e084904874cb3d)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, nameTableKind: None)
57+
!1 = !DIFile(filename: "spill.cc", directory: "/Users/vsk/tmp/param-analysis")
58+
!2 = !{}
59+
!3 = !{!4}
60+
!4 = !DISubprogram(name: "callee", linkageName: "_Z6calleei", scope: !1, file: !1, line: 1, type: !5, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2)
61+
!5 = !DISubroutineType(types: !6)
62+
!6 = !{null, !7}
63+
!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
64+
!8 = !{i32 2, !"Dwarf Version", i32 4}
65+
!9 = !{i32 2, !"Debug Info Version", i32 3}
66+
!10 = !{i32 1, !"wchar_size", i32 4}
67+
!11 = !{i32 7, !"PIC Level", i32 2}
68+
!12 = !{!"clang version 10.0.0 ([email protected]:llvm/llvm-project.git 132f768649d8f21d577ee220e5e084904874cb3d)"}
69+
!13 = distinct !DISubprogram(name: "caller", linkageName: "_Z6calleri", scope: !1, file: !1, line: 10, type: !5, scopeLine: 10, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !14)
70+
!14 = !{!15}
71+
!15 = !DILocalVariable(name: "x", arg: 1, scope: !13, file: !1, line: 10, type: !7, flags: DIFlagArgumentNotModified)
72+
!16 = !DILocation(line: 0, scope: !13)
73+
!17 = !DILocation(line: 11, column: 3, scope: !13)
74+
!18 = !{i32 -2147469811}
75+
!19 = !DILocation(line: 12, column: 3, scope: !13)
76+
!20 = !DILocation(line: 13, column: 1, scope: !13)
77+
78+
...
79+
---
80+
name: _Z6calleri
81+
alignment: 16
82+
exposesReturnsTwice: false
83+
legalized: false
84+
regBankSelected: false
85+
selected: false
86+
failedISel: false
87+
tracksRegLiveness: true
88+
hasWinCFI: false
89+
registers: []
90+
liveins:
91+
- { reg: '$edi', virtual-reg: '' }
92+
frameInfo:
93+
isFrameAddressTaken: false
94+
isReturnAddressTaken: false
95+
hasStackMap: false
96+
hasPatchPoint: false
97+
stackSize: 56
98+
offsetAdjustment: -56
99+
maxAlignment: 4
100+
adjustsStack: true
101+
hasCalls: true
102+
stackProtector: ''
103+
maxCallFrameSize: 0
104+
cvBytesOfCalleeSavedRegisters: 40
105+
hasOpaqueSPAdjustment: false
106+
hasVAStart: false
107+
hasMustTailInVarArgFunc: false
108+
localFrameSize: 0
109+
savePoint: ''
110+
restorePoint: ''
111+
fixedStack:
112+
- { id: 0, type: spill-slot, offset: -56, size: 8, alignment: 8, stack-id: default,
113+
callee-saved-register: '$rbx', callee-saved-restored: true, debug-info-variable: '',
114+
debug-info-expression: '', debug-info-location: '' }
115+
- { id: 1, type: spill-slot, offset: -48, size: 8, alignment: 16, stack-id: default,
116+
callee-saved-register: '$r12', callee-saved-restored: true, debug-info-variable: '',
117+
debug-info-expression: '', debug-info-location: '' }
118+
- { id: 2, type: spill-slot, offset: -40, size: 8, alignment: 8, stack-id: default,
119+
callee-saved-register: '$r13', callee-saved-restored: true, debug-info-variable: '',
120+
debug-info-expression: '', debug-info-location: '' }
121+
- { id: 3, type: spill-slot, offset: -32, size: 8, alignment: 16, stack-id: default,
122+
callee-saved-register: '$r14', callee-saved-restored: true, debug-info-variable: '',
123+
debug-info-expression: '', debug-info-location: '' }
124+
- { id: 4, type: spill-slot, offset: -24, size: 8, alignment: 8, stack-id: default,
125+
callee-saved-register: '$r15', callee-saved-restored: true, debug-info-variable: '',
126+
debug-info-expression: '', debug-info-location: '' }
127+
- { id: 5, type: spill-slot, offset: -16, size: 8, alignment: 16, stack-id: default,
128+
callee-saved-register: '', callee-saved-restored: true, debug-info-variable: '',
129+
debug-info-expression: '', debug-info-location: '' }
130+
stack:
131+
- { id: 0, name: '', type: spill-slot, offset: -60, size: 4, alignment: 4,
132+
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
133+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
134+
callSites:
135+
- { bb: 0, offset: 23, fwdArgRegs:
136+
- { arg: 0, reg: '$edi' } }
137+
constants: []
138+
machineFunctionInfo: {}
139+
body: |
140+
bb.0.entry:
141+
liveins: $edi, $r15, $r14, $r13, $r12, $rbx
142+
143+
DBG_VALUE $edi, $noreg, !15, !DIExpression(), debug-location !16
144+
frame-setup PUSH64r killed $rbp, implicit-def $rsp, implicit $rsp
145+
CFI_INSTRUCTION def_cfa_offset 16
146+
CFI_INSTRUCTION offset $rbp, -16
147+
$rbp = frame-setup MOV64rr $rsp
148+
CFI_INSTRUCTION def_cfa_register $rbp
149+
frame-setup PUSH64r killed $r15, implicit-def $rsp, implicit $rsp
150+
frame-setup PUSH64r killed $r14, implicit-def $rsp, implicit $rsp
151+
frame-setup PUSH64r killed $r13, implicit-def $rsp, implicit $rsp
152+
frame-setup PUSH64r killed $r12, implicit-def $rsp, implicit $rsp
153+
frame-setup PUSH64r killed $rbx, implicit-def $rsp, implicit $rsp
154+
frame-setup PUSH64r undef $rax, implicit-def $rsp, implicit $rsp
155+
CFI_INSTRUCTION offset $rbx, -56
156+
CFI_INSTRUCTION offset $r12, -48
157+
CFI_INSTRUCTION offset $r13, -40
158+
CFI_INSTRUCTION offset $r14, -32
159+
CFI_INSTRUCTION offset $r15, -24
160+
MOV32mr $rbp, 1, $noreg, -44, $noreg, $edi :: (store 4 into %stack.0)
161+
DBG_VALUE $rbp, 0, !15, !DIExpression(DW_OP_constu, 44, DW_OP_minus), debug-location !16
162+
INLINEASM &"", 1, 12, implicit-def dead early-clobber $rax, 12, implicit-def dead early-clobber $rbx, 12, implicit-def dead early-clobber $rcx, 12, implicit-def dead early-clobber $rdx, 12, implicit-def dead early-clobber $rsi, 12, implicit-def dead early-clobber $rdi, 12, implicit-def early-clobber $rbp, 12, implicit-def dead early-clobber $r8, 12, implicit-def dead early-clobber $r9, 12, implicit-def dead early-clobber $r10, 12, implicit-def dead early-clobber $r11, 12, implicit-def dead early-clobber $r12, 12, implicit-def dead early-clobber $r13, 12, implicit-def dead early-clobber $r14, 12, implicit-def dead early-clobber $r15, 12, implicit-def dead early-clobber $df, 12, implicit-def early-clobber $fpsw, 12, implicit-def dead early-clobber $eflags, !18, debug-location !17
163+
DBG_VALUE $edi, $noreg, !15, !DIExpression(DW_OP_LLVM_entry_value, 1), debug-location !16
164+
$edi = MOV32rm $rbp, 1, $noreg, -44, $noreg :: (load 4 from %stack.0)
165+
DBG_VALUE $edi, $noreg, !15, !DIExpression(), debug-location !16
166+
CALL64pcrel32 @_Z6calleei, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit-def $rsp, implicit-def $ssp, debug-location !19
167+
DBG_VALUE $edi, $noreg, !15, !DIExpression(DW_OP_LLVM_entry_value, 1), debug-location !16
168+
$rsp = frame-destroy ADD64ri8 $rsp, 8, implicit-def dead $eflags, debug-location !20
169+
$rbx = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !20
170+
$r12 = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !20
171+
$r13 = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !20
172+
$r14 = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !20
173+
$r15 = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !20
174+
$rbp = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !20
175+
RETQ debug-location !20
176+
177+
...

0 commit comments

Comments
 (0)