1## Test mips32:
2# RUN: llc -mtriple mips-linux-gnu -emit-call-site-info -start-after=machineverifier -filetype=obj %s -o -| llvm-dwarfdump -| FileCheck %s
3## Test mipsel:
4# RUN: llc -mtriple mipsel-linux-gnu -emit-call-site-info -start-after=machineverifier -filetype=obj %s -o -| llvm-dwarfdump -| FileCheck %s
5
6## Following code is used for producing this test case.
7##
8## extern int fn1(int,int,int);
9## extern void clobber();
10## int fn2(int a) {
11##   clobber();
12##   int local = fn1(44, a, a+10);
13##   if (local > 10)
14##     return local + 10;
15##   return local;
16## }
17## Check that parameters value loaded by instruction ADDiu/DADDiu is
18## interpreted correctly.
19
20## Test mips32:
21# CHECK: DW_TAG_GNU_call_site
22# CHECK-NEXT: DW_AT_abstract_origin {{.*}} "fn1"
23# CHECK: DW_TAG_GNU_call_site_parameter
24# CHECK-NEXT:   DW_AT_location      (DW_OP_reg5 A1_64)
25# CHECK-NEXT:   DW_AT_GNU_call_site_value   (DW_OP_breg16 S0_64+0)
26# CHECK-EMPTY:
27# CHECK-NEXT: DW_TAG_GNU_call_site_parameter
28# CHECK-NEXT:   DW_AT_location      (DW_OP_reg4 A0_64)
29# CHECK-NEXT:   DW_AT_GNU_call_site_value   (DW_OP_constu 0x2c)
30# CHECK-EMPTY:
31# CHECK-NEXT: DW_TAG_GNU_call_site_parameter
32# CHECK-NEXT:   DW_AT_location      (DW_OP_reg6 A2_64)
33# CHECK-NEXT:   DW_AT_GNU_call_site_value   (DW_OP_breg16 S0_64+10)
34--- |
35  ; ModuleID = 'm.ll'
36  source_filename = "m.c"
37  target datalayout = "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64"
38  target triple = "mips-unknown-linux-gnu"
39
40  ; Function Attrs: nounwind
41  define dso_local i32 @fn2(i32 signext %a) local_unnamed_addr !dbg !12 {
42  entry:
43    call void @llvm.dbg.value(metadata i32 %a, metadata !16, metadata !DIExpression()), !dbg !18
44    tail call void bitcast (void (...)* @clobber to void ()*)(), !dbg !18
45    %add = add nsw i32 %a, 10, !dbg !18
46    %call = tail call i32 @fn1(i32 signext 44, i32 signext %a, i32 signext %add), !dbg !18
47    call void @llvm.dbg.value(metadata i32 %call, metadata !17, metadata !DIExpression()), !dbg !18
48    %cmp = icmp sgt i32 %call, 10, !dbg !22
49    %add1 = add nsw i32 %call, 10, !dbg !18
50    %retval.0 = select i1 %cmp, i32 %add1, i32 %call, !dbg !18
51    ret i32 %retval.0, !dbg !18
52  }
53
54  declare dso_local void @clobber(...) local_unnamed_addr
55
56  declare !dbg !4 dso_local i32 @fn1(i32 signext, i32 signext, i32 signext) local_unnamed_addr
57
58  ; Function Attrs: nounwind readnone speculatable willreturn
59  declare void @llvm.dbg.value(metadata, metadata, metadata)
60
61  !llvm.dbg.cu = !{!0}
62  !llvm.module.flags = !{!8, !9, !10}
63  !llvm.ident = !{!11}
64
65  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, splitDebugInlining: false, nameTableKind: None)
66  !1 = !DIFile(filename: "m.c", directory: "/dir")
67  !2 = !{}
68  !3 = !{!4}
69  !4 = !DISubprogram(name: "fn1", scope: !1, file: !1, line: 1, type: !5, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2)
70  !5 = !DISubroutineType(types: !6)
71  !6 = !{!7, !7, !7, !7}
72  !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
73  !8 = !{i32 7, !"Dwarf Version", i32 4}
74  !9 = !{i32 2, !"Debug Info Version", i32 3}
75  !10 = !{i32 1, !"wchar_size", i32 4}
76  !11 = !{!"clang version 11.0.0"}
77  !12 = distinct !DISubprogram(name: "fn2", scope: !1, file: !1, line: 3, type: !13, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !15)
78  !13 = !DISubroutineType(types: !14)
79  !14 = !{!7, !7}
80  !15 = !{!16, !17}
81  !16 = !DILocalVariable(name: "a", arg: 1, scope: !12, file: !1, line: 3, type: !7)
82  !17 = !DILocalVariable(name: "local", scope: !12, file: !1, line: 5, type: !7)
83  !18 = !DILocation(line: 0, scope: !12)
84  !22 = !DILocation(line: 6, column: 14, scope: !23)
85  !23 = distinct !DILexicalBlock(scope: !12, file: !1, line: 6, column: 8)
86
87...
88---
89name:            fn2
90alignment:       4
91liveins:
92  - { reg: '$a0', virtual-reg: '' }
93stack:
94  - { id: 0, name: '', type: spill-slot, offset: -4, size: 4, alignment: 4,
95      stack-id: default, callee-saved-register: '$ra', callee-saved-restored: true,
96      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
97  - { id: 1, name: '', type: spill-slot, offset: -8, size: 4, alignment: 4,
98      stack-id: default, callee-saved-register: '$s0', callee-saved-restored: true,
99      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
100callSites:
101  - { bb: 0, offset: 8, fwdArgRegs: [] }
102  - { bb: 0, offset: 12, fwdArgRegs:
103      - { arg: 0, reg: '$a0' }
104      - { arg: 1, reg: '$a1' }
105      - { arg: 2, reg: '$a2' } }
106body:             |
107  bb.0.entry:
108    DBG_VALUE $a0, $noreg, !16, !DIExpression(), debug-location !18
109    $sp = ADDiu $sp, -24
110    CFI_INSTRUCTION def_cfa_offset 24
111    SW killed $ra, $sp, 20 :: (store 4 into %stack.0)
112    SW killed $s0, $sp, 16 :: (store 4 into %stack.1)
113    CFI_INSTRUCTION offset $ra_64, -4
114    CFI_INSTRUCTION offset $s0_64, -8
115    DBG_VALUE $s0, $noreg, !16, !DIExpression(), debug-location !18
116    JAL @clobber, csr_o32, implicit-def dead $ra, implicit-def $sp, debug-location !18 {
117      $s0 = OR $a0, $zero
118    }
119    renamable $a2 = nsw ADDiu renamable $s0, 10, debug-location !18
120    $a0 = ADDiu $zero, 44, debug-location !18
121    JAL @fn1, csr_o32, implicit-def dead $ra, implicit $a0, implicit killed $a1, implicit $a2, implicit-def $sp, implicit-def $v0, debug-location !18 {
122      $a1 = OR killed $s0, $zero, debug-location !18
123    }
124    DBG_VALUE $v0, $noreg, !17, !DIExpression(), debug-location !18
125    renamable $at = SLTi renamable $v0, 11, debug-location !18
126    renamable $v1 = nsw ADDiu renamable $v0, 10, debug-location !18
127    renamable $v0 = MOVZ_I_I killed renamable $v1, killed renamable $at, killed renamable $v0, debug-location !18
128    $s0 = LW $sp, 16, debug-location !18 :: (load 4 from %stack.1)
129    $ra = LW $sp, 20, debug-location !18 :: (load 4 from %stack.0)
130    PseudoReturn undef $ra, implicit $v0, debug-location !18 {
131      $sp = ADDiu $sp, 24
132    }
133