xref: /llvm-project/llvm/test/DebugInfo/X86/location-range-inlined-xblock.mir (revision 3a05e01d1a76984fe1532bd237edbbb7ed9db6ea)
1# RUN: llc -start-after=livedebugvalues --filetype=obj %s -o - \
2# RUN:   | llvm-dwarfdump -v --name local - \
3# RUN:   | FileCheck %s
4#
5## Generated with opt -inline -mem2reg, llc -stop-after=livedebugvalues from:
6## int glob;
7## int ext1(int);
8## int ext2(int);
9##
10## __attribute__((always_inline))
11## static int inline_me() {
12##   int local = glob;
13##   int r = 0;
14##   if (local)
15##     r = ext1(local);
16##   else
17##     r = ext2(local);
18##   return r * local;
19## }
20##
21## int fun(int p) {
22##   glob = p;
23##   glob = inline_me();
24##   return 0;
25## }
26##
27## Check that the location for inlined variable 'local' (RBX), which spans
28## multiple basic blocks, is given a single location.
29#
30# CHECK:      DW_AT_location [DW_FORM_exprloc] (DW_OP_reg3 RBX)
31# CHECK-NEXT: DW_AT_abstract_origin [DW_FORM_ref4] ({{.*}}"local")
32
33--- |
34  target triple = "x86_64-unknown-linux-gnu"
35
36  @glob = dso_local global i32 0, align 4, !dbg !0
37
38  define dso_local i32 @_Z3funi(i32 %p) !dbg !11 {
39  entry:
40    call void @llvm.dbg.value(metadata i32 %p, metadata !15, metadata !DIExpression()), !dbg !16
41    store i32 %p, ptr @glob, align 4, !dbg !17
42    %0 = load i32, ptr @glob, align 4, !dbg !22
43    call void @llvm.dbg.value(metadata i32 %0, metadata !27, metadata !DIExpression()), !dbg !30
44    call void @llvm.dbg.value(metadata i32 0, metadata !28, metadata !DIExpression()), !dbg !30
45    %tobool.i = icmp ne i32 %0, 0, !dbg !31
46    br i1 %tobool.i, label %if.then.i, label %if.else.i, !dbg !33
47
48  if.then.i:                                        ; preds = %entry
49    %call.i = call i32 @_Z4ext1i(i32 %0), !dbg !34
50    call void @llvm.dbg.value(metadata i32 %call.i, metadata !28, metadata !DIExpression()), !dbg !30
51    br label %_ZL9inline_mev.exit, !dbg !35
52
53  if.else.i:                                        ; preds = %entry
54    %call1.i = call i32 @_Z4ext2i(i32 %0), !dbg !36
55    call void @llvm.dbg.value(metadata i32 %call1.i, metadata !28, metadata !DIExpression()), !dbg !30
56    br label %_ZL9inline_mev.exit
57
58  _ZL9inline_mev.exit:                              ; preds = %if.else.i, %if.then.i
59    %r.0.i = phi i32 [ %call.i, %if.then.i ], [ %call1.i, %if.else.i ], !dbg !37
60    call void @llvm.dbg.value(metadata i32 %r.0.i, metadata !28, metadata !DIExpression()), !dbg !30
61    %mul.i = mul nsw i32 %r.0.i, %0, !dbg !38
62    store i32 %mul.i, ptr @glob, align 4, !dbg !39
63    ret i32 0, !dbg !40
64  }
65
66  declare !dbg !41 dso_local i32 @_Z4ext1i(i32)
67  declare !dbg !42 dso_local i32 @_Z4ext2i(i32)
68  declare void @llvm.dbg.value(metadata, metadata, metadata)
69
70  !llvm.dbg.cu = !{!2}
71  !llvm.module.flags = !{!7, !8, !9}
72  !llvm.ident = !{!10}
73
74  !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
75  !1 = distinct !DIGlobalVariable(name: "glob", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
76  !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
77  !3 = !DIFile(filename: "test.cpp", directory: "/")
78  !4 = !{}
79  !5 = !{!0}
80  !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
81  !7 = !{i32 7, !"Dwarf Version", i32 4}
82  !8 = !{i32 2, !"Debug Info Version", i32 3}
83  !9 = !{i32 1, !"wchar_size", i32 4}
84  !10 = !{!"clang version 12.0.0"}
85  !11 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funi", scope: !3, file: !3, line: 16, type: !12, scopeLine: 16, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !14)
86  !12 = !DISubroutineType(types: !13)
87  !13 = !{!6, !6}
88  !14 = !{!15}
89  !15 = !DILocalVariable(name: "p", arg: 1, scope: !11, file: !3, line: 16, type: !6)
90  !16 = !DILocation(line: 0, scope: !11)
91  !17 = !DILocation(line: 17, column: 8, scope: !11)
92  !22 = !DILocation(line: 7, column: 15, scope: !23, inlinedAt: !29)
93  !23 = distinct !DISubprogram(name: "inline_me", linkageName: "_ZL9inline_mev", scope: !3, file: !3, line: 6, type: !24, scopeLine: 6, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !26)
94  !24 = !DISubroutineType(types: !25)
95  !25 = !{!6}
96  !26 = !{!27, !28}
97  !27 = !DILocalVariable(name: "local", scope: !23, file: !3, line: 7, type: !6)
98  !28 = !DILocalVariable(name: "r", scope: !23, file: !3, line: 8, type: !6)
99  !29 = distinct !DILocation(line: 18, column: 10, scope: !11)
100  !30 = !DILocation(line: 0, scope: !23, inlinedAt: !29)
101  !31 = !DILocation(line: 9, column: 7, scope: !32, inlinedAt: !29)
102  !32 = distinct !DILexicalBlock(scope: !23, file: !3, line: 9, column: 7)
103  !33 = !DILocation(line: 9, column: 7, scope: !23, inlinedAt: !29)
104  !34 = !DILocation(line: 10, column: 9, scope: !32, inlinedAt: !29)
105  !35 = !DILocation(line: 10, column: 5, scope: !32, inlinedAt: !29)
106  !36 = !DILocation(line: 12, column: 9, scope: !32, inlinedAt: !29)
107  !37 = !DILocation(line: 0, scope: !32, inlinedAt: !29)
108  !38 = !DILocation(line: 13, column: 12, scope: !23, inlinedAt: !29)
109  !39 = !DILocation(line: 18, column: 8, scope: !11)
110  !40 = !DILocation(line: 19, column: 3, scope: !11)
111  !41 = !DISubprogram(name: "ext1", linkageName: "_Z4ext1i", scope: !3, file: !3, line: 2, type: !12, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4)
112  !42 = !DISubprogram(name: "ext2", linkageName: "_Z4ext2i", scope: !3, file: !3, line: 3, type: !12, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4)
113
114...
115---
116name:            _Z3funi
117body:             |
118  bb.0.entry:
119    successors: %bb.1(0x50000000), %bb.2(0x30000000)
120    liveins: $edi, $rbx
121
122    DBG_VALUE $edi, $noreg, !15, !DIExpression(), debug-location !16
123    frame-setup PUSH64r killed $rbx, implicit-def $rsp, implicit $rsp
124    CFI_INSTRUCTION def_cfa_offset 16
125    CFI_INSTRUCTION offset $rbx, -16
126    $ebx = MOV32rr $edi
127    DBG_VALUE $ebx, $noreg, !15, !DIExpression(), debug-location !16
128    MOV32mr $rip, 1, $noreg, @glob, $noreg, $edi, debug-location !17 :: (store (s32) into @glob)
129    DBG_VALUE $ebx, $noreg, !27, !DIExpression(), debug-location !30
130    DBG_VALUE 0, $noreg, !28, !DIExpression(), debug-location !30
131    TEST32rr $edi, $edi, implicit-def $eflags, debug-location !31
132    JCC_1 %bb.2, 4, implicit killed $eflags, debug-location !33
133
134  bb.1.if.then.i:
135    successors: %bb.3(0x80000000)
136    liveins: $ebx
137
138    DBG_VALUE $ebx, $noreg, !27, !DIExpression(), debug-location !30
139    DBG_VALUE $ebx, $noreg, !15, !DIExpression(), debug-location !16
140    DBG_VALUE 0, $noreg, !28, !DIExpression(), debug-location !30
141    $edi = MOV32rr $ebx, debug-location !34
142    CALL64pcrel32 @_Z4ext1i, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-location !34
143    DBG_VALUE $eax, $noreg, !28, !DIExpression(), debug-location !30
144    JMP_1 %bb.3
145
146  bb.2.if.else.i:
147    successors: %bb.3(0x80000000)
148    liveins: $ebx
149
150    DBG_VALUE $ebx, $noreg, !27, !DIExpression(), debug-location !30
151    DBG_VALUE $ebx, $noreg, !15, !DIExpression(), debug-location !16
152    DBG_VALUE 0, $noreg, !28, !DIExpression(), debug-location !30
153    $edi = MOV32rr $ebx, debug-location !36
154    CALL64pcrel32 @_Z4ext2i, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-location !36
155    DBG_VALUE $eax, $noreg, !28, !DIExpression(), debug-location !30
156
157  bb.3._ZL9inline_mev.exit:
158    liveins: $eax, $ebx
159
160    DBG_VALUE $ebx, $noreg, !27, !DIExpression(), debug-location !30
161    DBG_VALUE $ebx, $noreg, !15, !DIExpression(), debug-location !16
162    DBG_VALUE $eax, $noreg, !28, !DIExpression(), debug-location !30
163    DBG_VALUE $eax, $noreg, !28, !DIExpression(), debug-location !30
164    renamable $eax = nsw IMUL32rr killed renamable $eax, killed renamable $ebx, implicit-def dead $eflags, debug-location !38
165    MOV32mr $rip, 1, $noreg, @glob, $noreg, killed renamable $eax, debug-location !39 :: (store (s32) into @glob)
166    $eax = XOR32rr undef $eax, undef $eax, implicit-def dead $eflags, debug-location !40
167    $rbx = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !40
168    DBG_VALUE $edi, $noreg, !15, !DIExpression(DW_OP_LLVM_entry_value, 1), debug-location !16
169    CFI_INSTRUCTION def_cfa_offset 8, debug-location !40
170    RET64 $eax, debug-location !40
171
172...
173