1# RUN: llc -emit-call-site-info -start-after=machineverifier -filetype=obj %s -o -| llvm-dwarfdump -| FileCheck %s
2#
3# CHECK:        DW_TAG_GNU_call_site
4# CHECK-NEXT:     DW_AT_abstract_origin {{.*}} "foo"
5# CHECK-NEXT:     DW_AT_low_pc
6# CHECK-EMPTY:
7# CHECK-NEXT:     DW_TAG_GNU_call_site_parameter
8# CHECK-NEXT:       DW_AT_location      (DW_OP_reg2 RCX)
9# CHECK-NEXT:       DW_AT_GNU_call_site_value   (DW_OP_breg14 R14+0)
10# CHECK-EMPTY:
11# CHECK-NEXT:     DW_TAG_GNU_call_site_parameter
12# CHECK-NEXT:       DW_AT_location      (DW_OP_reg1 RDX)
13# CHECK-NEXT:       DW_AT_GNU_call_site_value   (DW_OP_fbreg +8)
14# CHECK-EMPTY:
15# CHECK-NEXT:     DW_TAG_GNU_call_site_parameter
16# CHECK-NEXT:       DW_AT_location      (DW_OP_reg4 RSI)
17# CHECK-NEXT:       DW_AT_GNU_call_site_value   (DW_OP_GNU_entry_value(DW_OP_reg4 RSI))
18# CHECK-EMPTY:
19# CHECK-NEXT:     DW_TAG_GNU_call_site_parameter
20# CHECK-NEXT:       DW_AT_location      (DW_OP_reg5 RDI)
21# CHECK-NEXT:       DW_AT_GNU_call_site_value   (DW_OP_GNU_entry_value(DW_OP_reg4 RSI))
22# CHECK-EMPTY:
23# CHECK:        DW_TAG_GNU_call_site
24# CHECK-NEXT:     DW_AT_abstract_origin {{.*}}"foo"
25# CHECK-NEXT:     DW_AT_low_pc
26# CHECK-EMPTY:
27# CHECK-NEXT:     DW_TAG_GNU_call_site_parameter
28# RCX loads memory location. We can't rely that memory location won't be changed.
29# CHECK-NOT:       DW_AT_location      (DW_OP_reg2 RCX)
30# CHECK-NEXT:       DW_AT_location      (DW_OP_reg4 RSI)
31# CHECK-NEXT:       DW_AT_GNU_call_site_value   (DW_OP_lit4)
32# CHECK-EMPTY:
33# CHECK-NOT:      DW_TAG_GNU_call_site_parameter
34#
35# Check that call site interpretation analysis can interpret instructions such
36# as move immediate, register to register moves, stack loading and LEA
37# instructions. Last negative check should verify that we are not producing
38# interpretation for RDX register since its loaded value is call clobberable.
39# Also check that we are generating proper call site debug entities.
40--- |
41  ; ModuleID = 'dbgcall-site-interpretation.c'
42  source_filename = "dbgcall-site-interpretation.c"
43  target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
44  target triple = "x86_64-unknown-linux-gnu"
45
46  ; Function Attrs: nounwind uwtable
47  define dso_local i32 @baa(i32 %arg1, i32 %arg2, i32 %arg3, i32 %arg4) local_unnamed_addr !dbg !9 {
48  entry:
49    %arg3.addr = alloca i32, align 4
50    %local2 = alloca i32, align 4
51    call void @llvm.dbg.value(metadata i32 %arg1, metadata !14, metadata !DIExpression()), !dbg !21
52    call void @llvm.dbg.value(metadata i32 %arg2, metadata !15, metadata !DIExpression()), !dbg !21
53    call void @llvm.dbg.value(metadata i32 %arg3, metadata !16, metadata !DIExpression()), !dbg !21
54    store i32 %arg3, i32* %arg3.addr, align 4
55    call void @llvm.dbg.value(metadata i32 %arg4, metadata !17, metadata !DIExpression()), !dbg !21
56    %0 = bitcast i32* %local2 to i8*, !dbg !21
57    call void @llvm.dbg.value(metadata i32* %arg3.addr, metadata !16, metadata !DIExpression(DW_OP_deref)), !dbg !21
58    %call = call i32 @foo(i32 %arg1, i32 %arg2, i32* nonnull %arg3.addr, i32 %arg4), !dbg !21
59    call void @llvm.dbg.value(metadata i32 %call, metadata !18, metadata !DIExpression()), !dbg !21
60    %cmp = icmp sgt i32 %arg1, %arg2, !dbg !21
61    %1 = load i32, i32* %arg3.addr, align 4, !dbg !21
62    call void @llvm.dbg.value(metadata i32 %1, metadata !16, metadata !DIExpression()), !dbg !21
63    %add = add nsw i32 %1, %arg1, !dbg !21
64    %add1 = add nsw i32 %arg4, %arg2, !dbg !21
65    %local1.0 = select i1 %cmp, i32 %add, i32 %add1, !dbg !21
66    call void @llvm.dbg.value(metadata i32 %local1.0, metadata !18, metadata !DIExpression()), !dbg !21
67    %rem = srem i32 %1, %arg1, !dbg !21
68    %tobool = icmp eq i32 %rem, 0, !dbg !21
69    %mul = mul nsw i32 %1, %arg1, !dbg !21
70    %add3 = add nsw i32 %1, %arg4, !dbg !21
71    %storemerge = select i1 %tobool, i32 %mul, i32 %add3, !dbg !21
72    call void @llvm.dbg.value(metadata i32 %storemerge, metadata !19, metadata !DIExpression()), !dbg !21
73    store i32 %storemerge, i32* %local2, align 4, !dbg !21
74    %cmp6 = icmp slt i32 %storemerge, %arg4, !dbg !21
75    %local3.0.v = select i1 %cmp6, i32 %local1.0, i32 %arg1, !dbg !21
76    %local3.0 = mul nsw i32 %local3.0.v, %storemerge, !dbg !21
77    call void @llvm.dbg.value(metadata i32 %local3.0, metadata !20, metadata !DIExpression()), !dbg !21
78    call void @llvm.dbg.value(metadata i32* %local2, metadata !19, metadata !DIExpression(DW_OP_deref)), !dbg !21
79    %call12 = call i32 @foo(i32 %local1.0, i32 4, i32* nonnull %local2, i32 %local3.0), !dbg !21
80    call void @llvm.dbg.value(metadata i32 %call12, metadata !14, metadata !DIExpression()), !dbg !21
81    %add13 = add nsw i32 %call12, 4, !dbg !21
82    ret i32 %add13, !dbg !21
83  }
84
85  declare !dbg !4 dso_local i32 @foo(i32, i32, i32*, i32) local_unnamed_addr
86
87  ; Function Attrs: nounwind readnone speculatable
88  declare void @llvm.dbg.value(metadata, metadata, metadata)
89
90  !llvm.dbg.cu = !{!0}
91  !llvm.module.flags = !{!5, !6, !7}
92  !llvm.ident = !{!8}
93
94  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, nameTableKind: None)
95  !1 = !DIFile(filename: "dbgcall-site-interpretation.c", directory: "/dir")
96  !2 = !{}
97  !3 = !{!4}
98  !4 = !DISubprogram(name: "foo", scope: !1, file: !1, line: 9, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2)
99  !5 = !{i32 2, !"Dwarf Version", i32 4}
100  !6 = !{i32 2, !"Debug Info Version", i32 3}
101  !7 = !{i32 1, !"wchar_size", i32 4}
102  !8 = !{!"clang version 9.0.0"}
103  !9 = distinct !DISubprogram(name: "baa", scope: !1, file: !1, line: 10, type: !10, scopeLine: 10, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !13)
104  !10 = !DISubroutineType(types: !11)
105  !11 = !{!12, !12, !12, !12, !12}
106  !12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
107  !13 = !{!14, !15, !16, !17, !18, !19, !20}
108  !14 = !DILocalVariable(name: "arg1", arg: 1, scope: !9, file: !1, line: 10, type: !12)
109  !15 = !DILocalVariable(name: "arg2", arg: 2, scope: !9, file: !1, line: 10, type: !12)
110  !16 = !DILocalVariable(name: "arg3", arg: 3, scope: !9, file: !1, line: 10, type: !12)
111  !17 = !DILocalVariable(name: "arg4", arg: 4, scope: !9, file: !1, line: 10, type: !12)
112  !18 = !DILocalVariable(name: "local1", scope: !9, file: !1, line: 11, type: !12)
113  !19 = !DILocalVariable(name: "local2", scope: !9, file: !1, line: 11, type: !12)
114  !20 = !DILocalVariable(name: "local3", scope: !9, file: !1, line: 11, type: !12)
115  !21 = !DILocation(line: 10, column: 13, scope: !9)
116
117...
118---
119name:            baa
120liveins:
121  - { reg: '$edi', virtual-reg: '' }
122  - { reg: '$esi', virtual-reg: '' }
123  - { reg: '$edx', virtual-reg: '' }
124  - { reg: '$ecx', virtual-reg: '' }
125callSites:
126  - { bb: 0, offset: 23, fwdArgRegs:
127      - { arg: 0, reg: '$edi' }
128      - { arg: 1, reg: '$esi' }
129      - { arg: 2, reg: '$rdx' }
130      - { arg: 3, reg: '$ecx' } }
131  - { bb: 0, offset: 49, fwdArgRegs:
132      - { arg: 0, reg: '$edi' }
133      - { arg: 1, reg: '$esi' }
134      - { arg: 2, reg: '$rdx' }
135      - { arg: 3, reg: '$ecx' } }
136body:             |
137  bb.0.entry:
138    liveins: $ecx, $edi, $edx, $esi, $r15, $r14, $rbx
139
140    DBG_VALUE $edi, $noreg, !14, !DIExpression(), debug-location !21
141    DBG_VALUE $esi, $noreg, !15, !DIExpression(), debug-location !21
142    DBG_VALUE $edx, $noreg, !16, !DIExpression(), debug-location !21
143    DBG_VALUE $ecx, $noreg, !17, !DIExpression(), debug-location !21
144    frame-setup PUSH64r killed $r15, implicit-def $rsp, implicit $rsp
145    CFI_INSTRUCTION def_cfa_offset 16
146    frame-setup PUSH64r killed $r14, implicit-def $rsp, implicit $rsp
147    CFI_INSTRUCTION def_cfa_offset 24
148    frame-setup PUSH64r killed $rbx, implicit-def $rsp, implicit $rsp
149    CFI_INSTRUCTION def_cfa_offset 32
150    $rsp = frame-setup SUB64ri8 $rsp, 16, implicit-def dead $eflags
151    CFI_INSTRUCTION def_cfa_offset 48
152    CFI_INSTRUCTION offset $rbx, -32
153    CFI_INSTRUCTION offset $r14, -24
154    CFI_INSTRUCTION offset $r15, -16
155    $r14d = MOV32rr $ecx, implicit-def $r14
156    DBG_VALUE $edx, $noreg, !16, !DIExpression(), debug-location !21
157    $r15d = MOV32rr $esi, implicit-def $r15
158    $ebx = MOV32rr $edi, implicit-def $rbx
159    $edi = MOV32rr $esi
160    MOV32mr $rsp, 1, $noreg, 8, $noreg, killed renamable $edx :: (store (s32) into %ir.arg3.addr)
161    renamable $rdx = LEA64r $rsp, 1, $noreg, 8, $noreg
162    renamable $ecx = MOV32rr $r14d,
163    CALL64pcrel32 @foo, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit $esi, implicit $rdx, implicit $ecx, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, implicit-def $rax, debug-location !21
164    DBG_VALUE $noreg, $noreg, !18, !DIExpression(), debug-location !21
165    $rdx = MOV64rr renamable $rax
166    $ecx = KILL renamable $ecx, implicit-def $rcx
167    renamable $eax = LEA64_32r renamable $rcx, 1, renamable $rbx, 0, $noreg, debug-location !21
168    renamable $edi = LEA64_32r renamable $r14, 1, renamable $r15, 0, $noreg, debug-location !21
169    CMP32rr renamable $ebx, renamable $r15d, implicit-def $eflags, implicit killed $r15, debug-location !21
170    renamable $edi = CMOV32rr killed renamable $edi, killed renamable $eax, 15, implicit killed $eflags, debug-location !21
171    DBG_VALUE $edi, $noreg, !18, !DIExpression(), debug-location !21
172    $eax = MOV32rr $ecx, debug-location !21
173    CDQ implicit-def $eax, implicit-def $edx, implicit $eax, debug-location !21
174    IDIV32r renamable $ebx, implicit-def dead $eax, implicit-def $edx, implicit-def dead $eflags, implicit $eax, implicit $edx, debug-location !21
175    $eax = MOV32rr $ecx, debug-location !21
176    renamable $eax = nsw IMUL32rr killed renamable $eax, renamable $ebx, implicit-def dead $eflags, debug-location !21
177    renamable $ecx = nsw ADD32rr renamable $ecx, renamable $r14d, implicit-def dead $eflags, implicit killed $rcx, implicit-def $rcx, debug-location !21
178    TEST32rr killed renamable $edx, renamable $edx, implicit-def $eflags, debug-location !21
179    renamable $ecx = CMOV32rr renamable $ecx, killed renamable $eax, 4, implicit killed $eflags, implicit killed $rcx, implicit-def $rcx, debug-location !21
180    DBG_VALUE $ecx, $noreg, !19, !DIExpression(), debug-location !21
181    MOV32mr $rsp, 1, $noreg, 12, $noreg, renamable $ecx, debug-location !21 :: (store (s32) into %ir.local2)
182    CMP32rr renamable $ecx, renamable $r14d, implicit-def $eflags, implicit killed $r14, debug-location !21
183    renamable $ebx = CMOV32rr renamable $ebx, renamable $edi, 12, implicit killed $eflags, implicit killed $rbx, implicit-def $rbx, debug-location !21
184    renamable $ecx = nsw IMUL32rr renamable $ecx, renamable $ebx, implicit-def dead $eflags, implicit killed $rbx, implicit killed $rcx, implicit-def $rcx, debug-location !21
185    DBG_VALUE $rsp, $noreg, !19, !DIExpression(DW_OP_plus_uconst, 12, DW_OP_deref), debug-location !21
186    DBG_VALUE $ecx, $noreg, !20, !DIExpression(), debug-location !21
187    $esi = MOV32ri 4, debug-location !21
188    renamable $ecx = MOV32rm $rsp, 1, $noreg, 8, $noreg, implicit-def $rcx, debug-location !21 :: (dereferenceable load (s32) from %ir.arg3.addr)
189    CALL64pcrel32 @foo, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit $esi, implicit $rdx, implicit $ecx, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, implicit-def $rax, debug-location !21
190    DBG_VALUE $eax, $noreg, !14, !DIExpression(), debug-location !21
191    renamable $eax = nsw ADD32ri8 killed renamable $eax, 4, implicit-def dead $eflags, debug-location !21
192    $rsp = frame-destroy ADD64ri8 $rsp, 16, implicit-def dead $eflags, debug-location !21
193    CFI_INSTRUCTION def_cfa_offset 32, debug-location !21
194    $rbx = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !21
195    CFI_INSTRUCTION def_cfa_offset 24, debug-location !21
196    $r14 = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !21
197    DBG_VALUE $ecx, $noreg, !17, !DIExpression(DW_OP_LLVM_entry_value, 1), debug-location !21
198    CFI_INSTRUCTION def_cfa_offset 16, debug-location !21
199    $r15 = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !21
200    DBG_VALUE $esi, $noreg, !15, !DIExpression(DW_OP_LLVM_entry_value, 1), debug-location !21
201    CFI_INSTRUCTION def_cfa_offset 8, debug-location !21
202    RETQ $eax, debug-location !21
203
204...
205