File: live-debug-values-restore.mir

package info (click to toggle)
llvm-toolchain-9 1%3A9.0.1-16.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 882,388 kB
  • sloc: cpp: 4,167,636; ansic: 714,256; asm: 457,610; python: 155,927; objc: 65,094; sh: 42,856; lisp: 26,908; perl: 7,786; pascal: 7,722; makefile: 6,881; ml: 5,581; awk: 3,648; cs: 2,027; xml: 888; javascript: 381; ruby: 156
file content (300 lines) | stat: -rw-r--r-- 15,240 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# RUN: llc -run-pass livedebugvalues -march=x86-64 -o - %s | FileCheck %s

# Generated from the following source with:
# clang -g -mllvm -stop-before=livedebugvalues -S -O2 test.c -o test.mir

# #define FORCE_SPILL() \
#   __asm volatile("" : : : \
#                    "rax", "rbx", "rcx", "rdx", "rsi", "rdi", "rbp", "r8", \
#                    "r9", "r10", "r11", "r12", "r13", "r14", "r15")
# int f(int *p) {
#   if (p) {
#     FORCE_SPILL();
#   }
#   return *(p + 1);
# }

# Pick out DILocalVariable numbers for "p" and "q"
# CHECK: ![[PVAR:[0-9]+]] = !DILocalVariable(name: "p",
# CHECK: ![[QVAR:[0-9]+]] = !DILocalVariable(name: "q",

# Ascertain that the spill has been recognized and manifested in a DBG_VALUE.
# CHECK: MOV64mr $rsp,{{.*-8.*}}killed{{.*}}$rdi :: (store 8 into %stack.0)
# CHECK-NEXT: DBG_VALUE $rsp,{{.*}}![[PVAR]],{{.*}}!DIExpression(DW_OP_constu, 8, DW_OP_minus)

# Check for the restore.
# CHECK: $rdi = MOV64rm $rsp,{{.*-8.*}}:: (load 8 from %stack.0)
# CHECK-NEXT: DBG_VALUE $rdi,{{.*}}![[PVAR]], !DIExpression()

--- |
  define dso_local i32 @f(i32* readonly %p) local_unnamed_addr !dbg !7 {
  entry:
    call void @llvm.dbg.value(metadata i32* %p, metadata !13, metadata !DIExpression()), !dbg !14
    %tobool = icmp eq i32* %p, null, !dbg !15
    br i1 %tobool, label %if.end, label %if.then, !dbg !17
  
  if.then:                                          ; preds = %entry
    tail call void asm sideeffect "", "~{rax},~{rbx},~{rcx},~{rdx},~{rsi},~{rdi},~{rbp},~{r8},~{r9},~{r10},~{r11},~{r12},~{r13},~{r14},~{r15},~{dirflag},~{fpsr},~{flags}"(), !dbg !18, !srcloc !20
    br label %if.end, !dbg !21
  
  if.end:                                           ; preds = %entry, %if.then
    %add.ptr = getelementptr inbounds i32, i32* %p, i64 1, !dbg !22
    %0 = load i32, i32* %add.ptr, align 4, !dbg !23, !tbaa !24
    ret i32 %0, !dbg !28
  }
  
  define dso_local i32 @g(i32* readonly %p) local_unnamed_addr !dbg !107 {
  entry:
    call void @llvm.dbg.value(metadata i32* %p, metadata !113, metadata !DIExpression()), !dbg !114
    %tobool = icmp eq i32* %p, null, !dbg !115
    br i1 %tobool, label %if.end, label %if.then, !dbg !117
  
  if.then:                                          ; preds = %entry
    tail call void asm sideeffect "", "~{rax},~{rbx},~{rcx},~{rdx},~{rsi},~{rdi},~{rbp},~{r8},~{r9},~{r10},~{r11},~{r12},~{r13},~{r14},~{r15},~{dirflag},~{fpsr},~{flags}"(), !dbg !118, !srcloc !120
    br label %if.end, !dbg !121
  
  if.end:                                           ; preds = %entry, %if.then
    %add.ptr = getelementptr inbounds i32, i32* %p, i64 1, !dbg !122
    %0 = load i32, i32* %add.ptr, align 4, !dbg !123, !tbaa !24
    ret i32 %0, !dbg !128
  }
 
  declare void @llvm.dbg.value(metadata, metadata, metadata)
  
  !llvm.dbg.cu = !{!0}
  !llvm.module.flags = !{!3, !4, !5}
  !llvm.ident = !{!6}
  
  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (https://git.llvm.org/git/clang.git/ 57a6ce7ac318de98e3e777e09cb9ed8282b5cc03) (https://git.llvm.org/git/llvm.git/ ff54a19e4912d7f15cb02798a7f2048441bff751)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
  !1 = !DIFile(filename: "test2.c", directory: "/home/test")
  !2 = !{}
  !3 = !{i32 2, !"Dwarf Version", i32 4}
  !4 = !{i32 2, !"Debug Info Version", i32 3}
  !5 = !{i32 1, !"wchar_size", i32 4}
  !6 = !{!"clang version 9.0.0 (https://git.llvm.org/git/clang.git/ 57a6ce7ac318de98e3e777e09cb9ed8282b5cc03) (https://git.llvm.org/git/llvm.git/ ff54a19e4912d7f15cb02798a7f2048441bff751)"}
  !7 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12)
  !8 = !DISubroutineType(types: !9)
  !9 = !{!10, !11}
  !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  !11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64)
  !12 = !{!13}
  !13 = !DILocalVariable(name: "p", arg: 1, scope: !7, file: !1, line: 5, type: !11)
  !14 = !DILocation(line: 5, column: 12, scope: !7)
  !15 = !DILocation(line: 6, column: 7, scope: !16)
  !16 = distinct !DILexicalBlock(scope: !7, file: !1, line: 6, column: 7)
  !17 = !DILocation(line: 6, column: 7, scope: !7)
  !18 = !DILocation(line: 7, column: 5, scope: !19)
  !19 = distinct !DILexicalBlock(scope: !16, file: !1, line: 6, column: 10)
  !20 = !{i32 -2147471544}
  !21 = !DILocation(line: 8, column: 3, scope: !19)
  !22 = !DILocation(line: 9, column: 14, scope: !7)
  !23 = !DILocation(line: 9, column: 10, scope: !7)
  !24 = !{!25, !25, i64 0}
  !25 = !{!"int", !26, i64 0}
  !26 = !{!"omnipotent char", !27, i64 0}
  !27 = !{!"Simple C/C++ TBAA"}
  !28 = !DILocation(line: 9, column: 3, scope: !7)
  !101 = !DIBasicType(name: "looong int", size: 64, encoding: DW_ATE_signed)
  !107 = distinct !DISubprogram(name: "g", scope: !1, file: !1, line: 105, type: !8, scopeLine: 105, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !112)
  !112 = !{!113}
  !113 = !DILocalVariable(name: "q", arg: 1, scope: !107, file: !1, line: 105, type: !101)
  !114 = !DILocation(line: 105, column: 12, scope: !107)
  !115 = !DILocation(line: 106, column: 7, scope: !116)
  !116 = distinct !DILexicalBlock(scope: !107, file: !1, line: 106, column: 7)
  !117 = !DILocation(line: 106, column: 7, scope: !107)
  !118 = !DILocation(line: 107, column: 5, scope: !119)
  !119 = distinct !DILexicalBlock(scope: !116, file: !1, line: 106, column: 10)
  !120 = !{i32 -2147471544}
  !121 = !DILocation(line: 108, column: 3, scope: !119)
  !122 = !DILocation(line: 109, column: 14, scope: !107)
  !123 = !DILocation(line: 109, column: 10, scope: !107)
  !128 = !DILocation(line: 109, column: 3, scope: !107)


...
---
name:            f
alignment:       4
exposesReturnsTwice: false
legalized:       false
regBankSelected: false
selected:        false
failedISel:      false
tracksRegLiveness: true
hasWinCFI:       false
registers:       []
liveins:         
  - { reg: '$rdi', virtual-reg: '' }
frameInfo:       
  isFrameAddressTaken: false
  isReturnAddressTaken: false
  hasStackMap:     false
  hasPatchPoint:   false
  stackSize:       48
  offsetAdjustment: -48
  maxAlignment:    8
  adjustsStack:    false
  hasCalls:        false
  stackProtector:  ''
  maxCallFrameSize: 0
  cvBytesOfCalleeSavedRegisters: 48
  hasOpaqueSPAdjustment: false
  hasVAStart:      false
  hasMustTailInVarArgFunc: false
  localFrameSize:  0
  savePoint:       ''
  restorePoint:    ''
fixedStack:      
  - { id: 0, type: spill-slot, offset: -56, size: 8, alignment: 8, stack-id: default,
      callee-saved-register: '$rbx', callee-saved-restored: true, debug-info-variable: '', 
      debug-info-expression: '', debug-info-location: '' }
  - { id: 1, type: spill-slot, offset: -48, size: 8, alignment: 16, stack-id: default,
      callee-saved-register: '$r12', callee-saved-restored: true, debug-info-variable: '', 
      debug-info-expression: '', debug-info-location: '' }
  - { id: 2, type: spill-slot, offset: -40, size: 8, alignment: 8, stack-id: default,
      callee-saved-register: '$r13', callee-saved-restored: true, debug-info-variable: '', 
      debug-info-expression: '', debug-info-location: '' }
  - { id: 3, type: spill-slot, offset: -32, size: 8, alignment: 16, stack-id: default,
      callee-saved-register: '$r14', callee-saved-restored: true, debug-info-variable: '', 
      debug-info-expression: '', debug-info-location: '' }
  - { id: 4, type: spill-slot, offset: -24, size: 8, alignment: 8, stack-id: default,
      callee-saved-register: '$r15', callee-saved-restored: true, debug-info-variable: '', 
      debug-info-expression: '', debug-info-location: '' }
  - { id: 5, type: spill-slot, offset: -16, size: 8, alignment: 16, stack-id: default,
      callee-saved-register: '$rbp', callee-saved-restored: true, debug-info-variable: '', 
      debug-info-expression: '', debug-info-location: '' }
stack:           
  - { id: 0, name: '', type: spill-slot, offset: -64, size: 8, alignment: 8, 
      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
constants:       []
body:             |
  bb.0.entry:
    successors: %bb.2(0x30000000), %bb.1(0x50000000)
    liveins: $rdi, $rbx, $r12, $r13, $r14, $r15, $rbp
  
    DBG_VALUE $rdi, $noreg, !13, !DIExpression(), debug-location !14
    DBG_VALUE $rdi, $noreg, !13, !DIExpression(), debug-location !14
    TEST64rr renamable $rdi, renamable $rdi, implicit-def $eflags, debug-location !15
    JCC_1 %bb.2, 4, implicit $eflags, debug-location !17
  
  bb.1.if.then:
    successors: %bb.2(0x80000000)
    liveins: $rdi, $rbp, $r15, $r14, $r13, $r12, $rbx
  
    frame-setup PUSH64r killed $rbp, implicit-def $rsp, implicit $rsp
    CFI_INSTRUCTION def_cfa_offset 16
    frame-setup PUSH64r killed $r15, implicit-def $rsp, implicit $rsp
    CFI_INSTRUCTION def_cfa_offset 24
    frame-setup PUSH64r killed $r14, implicit-def $rsp, implicit $rsp
    CFI_INSTRUCTION def_cfa_offset 32
    frame-setup PUSH64r killed $r13, implicit-def $rsp, implicit $rsp
    CFI_INSTRUCTION def_cfa_offset 40
    frame-setup PUSH64r killed $r12, implicit-def $rsp, implicit $rsp
    CFI_INSTRUCTION def_cfa_offset 48
    frame-setup PUSH64r killed $rbx, implicit-def $rsp, implicit $rsp
    CFI_INSTRUCTION def_cfa_offset 56
    CFI_INSTRUCTION offset $rbx, -56
    CFI_INSTRUCTION offset $r12, -48
    CFI_INSTRUCTION offset $r13, -40
    CFI_INSTRUCTION offset $r14, -32
    CFI_INSTRUCTION offset $r15, -24
    CFI_INSTRUCTION offset $rbp, -16
    MOV64mr $rsp, 1, $noreg, -8, $noreg, killed renamable $rdi :: (store 8 into %stack.0)
    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 dead 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 $eflags, !20, debug-location !18
    renamable $rdi = MOV64rm $rsp, 1, $noreg, -8, $noreg :: (load 8 from %stack.0)
    $rbx = frame-destroy POP64r implicit-def $rsp, implicit $rsp
    CFI_INSTRUCTION def_cfa_offset 48
    $r12 = frame-destroy POP64r implicit-def $rsp, implicit $rsp
    CFI_INSTRUCTION def_cfa_offset 40
    $r13 = frame-destroy POP64r implicit-def $rsp, implicit $rsp
    CFI_INSTRUCTION def_cfa_offset 32
    $r14 = frame-destroy POP64r implicit-def $rsp, implicit $rsp
    CFI_INSTRUCTION def_cfa_offset 24
    $r15 = frame-destroy POP64r implicit-def $rsp, implicit $rsp
    CFI_INSTRUCTION def_cfa_offset 16
    $rbp = frame-destroy POP64r implicit-def $rsp, implicit $rsp
    CFI_INSTRUCTION def_cfa_offset 8
  
  bb.2.if.end:
    liveins: $rdi, $rbx, $r12, $r13, $r14, $r15, $rbp
  
    renamable $eax = MOV32rm killed renamable $rdi, 1, $noreg, 4, $noreg, debug-location !23 :: (load 4 from %ir.add.ptr, !tbaa !24)
    RETQ $eax, debug-location !28

...
---
# This second function has been appended as a regression test against a
# crash, caused by expressions being created from spill restores that did
# not preserve fragment information. Test that no empty expressions are
# created at all, and the last block describes both variable fragments.

# CHECK-LABEL: name: g
# CHECK-NOT: !DIExpression()
# CHECK-LABEL: bb.2.if.end:
# CHECK:       DBG_VALUE $rdi, $noreg, ![[QVAR]], !DIExpression(DW_OP_LLVM_fragment, 0, 32)
# CHECK-NEXT:  DBG_VALUE $rbx, $noreg, ![[QVAR]], !DIExpression(DW_OP_LLVM_fragment, 32, 32)

name:            g
alignment:       4
tracksRegLiveness: true
liveins:         
  - { reg: '$rdi', virtual-reg: '' }
frameInfo:       
  stackSize:       48
  offsetAdjustment: -48
  maxAlignment:    8
  cvBytesOfCalleeSavedRegisters: 48
  localFrameSize:  0
fixedStack:      
  - { id: 0, type: spill-slot, offset: -56, size: 8, alignment: 8, stack-id: default,
      callee-saved-register: '$rbx', callee-saved-restored: true, debug-info-variable: '', 
      debug-info-expression: '', debug-info-location: '' }
  - { id: 1, type: spill-slot, offset: -48, size: 8, alignment: 16, stack-id: default,
      callee-saved-register: '$r12', callee-saved-restored: true, debug-info-variable: '', 
      debug-info-expression: '', debug-info-location: '' }
  - { id: 2, type: spill-slot, offset: -40, size: 8, alignment: 8, stack-id: default,
      callee-saved-register: '$r13', callee-saved-restored: true, debug-info-variable: '', 
      debug-info-expression: '', debug-info-location: '' }
  - { id: 3, type: spill-slot, offset: -32, size: 8, alignment: 16, stack-id: default,
      callee-saved-register: '$r14', callee-saved-restored: true, debug-info-variable: '', 
      debug-info-expression: '', debug-info-location: '' }
  - { id: 4, type: spill-slot, offset: -24, size: 8, alignment: 8, stack-id: default,
      callee-saved-register: '$r15', callee-saved-restored: true, debug-info-variable: '', 
      debug-info-expression: '', debug-info-location: '' }
  - { id: 5, type: spill-slot, offset: -16, size: 8, alignment: 16, stack-id: default,
      callee-saved-register: '$rbp', callee-saved-restored: true, debug-info-variable: '', 
      debug-info-expression: '', debug-info-location: '' }
stack:           
  - { id: 0, name: '', type: spill-slot, offset: -64, size: 8, alignment: 8, 
      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
constants:       []
body:             |
  bb.0.entry:
    successors: %bb.1(0x50000000)
    liveins: $rdi, $rbx, $r12, $r13, $r14, $r15, $rbp
  
    DBG_VALUE $rdi, $noreg, !113, !DIExpression(DW_OP_LLVM_fragment, 0, 32), debug-location !114
    TEST64rr renamable $rdi, renamable $rdi, implicit-def $eflags, debug-location !115
    JMP_1 %bb.1, implicit $eflags, debug-location !117
  
  bb.1.if.then:
    successors: %bb.2(0x80000000)
    liveins: $rdi, $rbp, $r15, $r14, $r13, $r12, $rbx
  
    MOV64mr $rsp, 1, $noreg, -8, $noreg, killed renamable $rdi :: (store 8 into %stack.0)
    renamable $rdi = MOV64rm $rsp, 1, $noreg, -8, $noreg :: (load 8 from %stack.0)
  
  bb.2.if.end:
    liveins: $rdi, $rbx, $r12, $r13, $r14, $r15, $rbp
  
    DBG_VALUE $rbx, $noreg, !113, !DIExpression(DW_OP_LLVM_fragment, 32, 32), debug-location !114
    MOV64mr $rsp, 1, $noreg, -8, $noreg, killed renamable $rbx :: (store 8 into %stack.0)
    renamable $rsi = MOV64rm $rsp, 1, $noreg, -8, $noreg :: (load 8 from %stack.0)

    renamable $eax = MOV32rm killed renamable $rsi, 1, $noreg, 4, $noreg, debug-location !123 :: (load 4 from %ir.add.ptr, !tbaa !24)
    $rdi = MOV64ri 0
    RETQ $eax, debug-location !128

...