xref: /llvm-project/llvm/test/CodeGen/X86/machine-outliner-disubprogram.ll (revision 10b03e66629aedad79a804e22d23b575077303b3)
1; Ensure that we can correctly emit a compile unit for outlined functions and
2; that we correctly emit DISubprograms for those functions.
3; Also make sure that the DISubprograms reference the generated unit.
4; make sure that if there are two outlined functions in the program,
5; RUN: llc %s -verify-machineinstrs -enable-machine-outliner -mtriple=x86_64-apple-darwin -o /dev/null -print-after=machine-outliner
6; RUN: llc --try-experimental-debuginfo-iterators %s -verify-machineinstrs -enable-machine-outliner -mtriple=x86_64-apple-darwin -o /dev/null -print-after=machine-outliner
7define void @f6() #0 !dbg !8 {
8entry:
9  %dog = alloca i32, align 4
10  %cat = alloca i32, align 4
11  %pangolin = alloca i32, align 4
12  call void @llvm.dbg.declare(metadata ptr %dog, metadata !11, metadata !DIExpression()), !dbg !13
13  store i32 16, ptr %dog, align 4, !dbg !13
14  call void @llvm.dbg.declare(metadata ptr %cat, metadata !14, metadata !DIExpression()), !dbg !15
15  store i32 32, ptr %cat, align 4, !dbg !15
16  call void @llvm.dbg.declare(metadata ptr %pangolin, metadata !16, metadata !DIExpression()), !dbg !17
17  store i32 48, ptr %pangolin, align 4, !dbg !17
18  ret void, !dbg !18
19}
20
21declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
22
23define void @f5() #0 !dbg !19 {
24entry:
25  %dog = alloca i32, align 4
26  %cat = alloca i32, align 4
27  %pangolin = alloca i32, align 4
28  call void @llvm.dbg.declare(metadata ptr %dog, metadata !20, metadata !DIExpression()), !dbg !21
29  store i32 16, ptr %dog, align 4, !dbg !21
30  call void @llvm.dbg.declare(metadata ptr %cat, metadata !22, metadata !DIExpression()), !dbg !23
31  store i32 32, ptr %cat, align 4, !dbg !23
32  call void @llvm.dbg.declare(metadata ptr %pangolin, metadata !24, metadata !DIExpression()), !dbg !25
33  store i32 48, ptr %pangolin, align 4, !dbg !25
34  ret void, !dbg !26
35}
36
37define void @f4() #0 !dbg !27 {
38entry:
39  %dog = alloca i32, align 4
40  %cat = alloca i32, align 4
41  %pangolin = alloca i32, align 4
42  call void @llvm.dbg.declare(metadata ptr %dog, metadata !28, metadata !DIExpression()), !dbg !29
43  store i32 16, ptr %dog, align 4, !dbg !29
44  call void @llvm.dbg.declare(metadata ptr %cat, metadata !30, metadata !DIExpression()), !dbg !31
45  store i32 32, ptr %cat, align 4, !dbg !31
46  call void @llvm.dbg.declare(metadata ptr %pangolin, metadata !32, metadata !DIExpression()), !dbg !33
47  store i32 48, ptr %pangolin, align 4, !dbg !33
48  ret void, !dbg !34
49}
50
51define i32 @f1() #0 !dbg !35 {
52entry:
53  %dog = alloca i32, align 4
54  %cat = alloca i32, align 4
55  %pangolin = alloca i32, align 4
56  call void @llvm.dbg.declare(metadata ptr %dog, metadata !38, metadata !DIExpression()), !dbg !39
57  store i32 1, ptr %dog, align 4, !dbg !39
58  call void @llvm.dbg.declare(metadata ptr %cat, metadata !40, metadata !DIExpression()), !dbg !41
59  store i32 2, ptr %cat, align 4, !dbg !41
60  call void @llvm.dbg.declare(metadata ptr %pangolin, metadata !42, metadata !DIExpression()), !dbg !43
61  store i32 3, ptr %pangolin, align 4, !dbg !43
62  store i32 16, ptr %dog, align 4, !dbg !44
63  %0 = load i32, ptr %dog, align 4, !dbg !45
64  ret i32 %0, !dbg !46
65}
66
67define i32 @f2() #0 !dbg !47 {
68entry:
69  %dog = alloca i32, align 4
70  %cat = alloca i32, align 4
71  %pangolin = alloca i32, align 4
72  call void @llvm.dbg.declare(metadata ptr %dog, metadata !48, metadata !DIExpression()), !dbg !49
73  store i32 1, ptr %dog, align 4, !dbg !49
74  call void @llvm.dbg.declare(metadata ptr %cat, metadata !50, metadata !DIExpression()), !dbg !51
75  store i32 2, ptr %cat, align 4, !dbg !51
76  call void @llvm.dbg.declare(metadata ptr %pangolin, metadata !52, metadata !DIExpression()), !dbg !53
77  store i32 3, ptr %pangolin, align 4, !dbg !53
78  store i32 16, ptr %dog, align 4, !dbg !54
79  %0 = load i32, ptr %dog, align 4, !dbg !55
80  ret i32 %0, !dbg !56
81}
82
83define i32 @f3() #0 !dbg !57 {
84entry:
85  %dog = alloca i32, align 4
86  %cat = alloca i32, align 4
87  %pangolin = alloca i32, align 4
88  call void @llvm.dbg.declare(metadata ptr %dog, metadata !58, metadata !DIExpression()), !dbg !59
89  store i32 1, ptr %dog, align 4, !dbg !59
90  call void @llvm.dbg.declare(metadata ptr %cat, metadata !60, metadata !DIExpression()), !dbg !61
91  store i32 2, ptr %cat, align 4, !dbg !61
92  call void @llvm.dbg.declare(metadata ptr %pangolin, metadata !62, metadata !DIExpression()), !dbg !63
93  store i32 3, ptr %pangolin, align 4, !dbg !63
94  store i32 16, ptr %dog, align 4, !dbg !64
95  %0 = load i32, ptr %dog, align 4, !dbg !65
96  ret i32 %0, !dbg !66
97}
98
99define i32 @main() #0 !dbg !67 {
100entry:
101  %retval = alloca i32, align 4
102  %a = alloca i32, align 4
103  store i32 0, ptr %retval, align 4
104  call void @llvm.dbg.declare(metadata ptr %a, metadata !68, metadata !DIExpression()), !dbg !69
105  store i32 4, ptr %a, align 4, !dbg !69
106  %call = call i32 @f1() #2, !dbg !70
107  %call1 = call i32 @f2() #2, !dbg !71
108  %call2 = call i32 @f3() #2, !dbg !72
109  ret i32 0, !dbg !73
110}
111
112; CHECK: distinct !DISubprogram(name: "OUTLINED_FUNCTION_1",
113; CHECK-SAME: scope: !1,
114; CHECK-SAME: file: !1,
115; CHECK-SAME: type: [[TYPE:![0-9]+]],
116; CHECK-SAME: isLocal: false,
117; CHECK-SAME: isDefinition: true,
118; CHECK-SAME: flags: DIFlagArtificial,
119; CHECK-SAME: isOptimized: true,
120; CHECK-SAME: unit: !0,
121; CHECK-SAME: retainedNodes: [[VARS:![0-9]+]]
122
123; CHECK: distinct !DISubprogram(name: "OUTLINED_FUNCTION_0",
124; CHECK-SAME: scope: !1,
125; CHECK-SAME: file: !1,
126; CHECK-SAME: type: [[TYPE]],
127; CHECK-SAME: isLocal: false,
128; CHECK-SAME: isDefinition: true,
129; CHECK-SAME: flags: DIFlagArtificial,
130; CHECK-SAME: isOptimized: true,
131; CHECK-SAME: unit: !0,
132; CHECK-SAME: retainedNodes: [[VARS]]
133
134attributes #0 = { noinline noredzone nounwind optnone ssp uwtable "frame-pointer"="all"  }
135attributes #1 = { nounwind readnone speculatable }
136attributes #2 = { noredzone }
137
138!llvm.dbg.cu = !{!0}
139!llvm.module.flags = !{!3, !4, !5, !6}
140!llvm.ident = !{!7}
141
142!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
143!1 = !DIFile(filename: "test.c", directory: "/")
144!2 = !{}
145!3 = !{i32 2, !"Dwarf Version", i32 4}
146!4 = !{i32 2, !"Debug Info Version", i32 3}
147!5 = !{i32 1, !"wchar_size", i32 4}
148!6 = !{i32 7, !"PIC Level", i32 2}
149!7 = !{!"clang"}
150!8 = distinct !DISubprogram(name: "f6", scope: !1, file: !1, line: 3, type: !9, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: false, unit: !0, retainedNodes: !2)
151!9 = !DISubroutineType(types: !10)
152!10 = !{null}
153!11 = !DILocalVariable(name: "dog", scope: !8, file: !1, line: 4, type: !12)
154!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
155!13 = !DILocation(line: 4, column: 16, scope: !8)
156!14 = !DILocalVariable(name: "cat", scope: !8, file: !1, line: 5, type: !12)
157!15 = !DILocation(line: 5, column: 16, scope: !8)
158!16 = !DILocalVariable(name: "pangolin", scope: !8, file: !1, line: 6, type: !12)
159!17 = !DILocation(line: 6, column: 16, scope: !8)
160!18 = !DILocation(line: 7, column: 1, scope: !8)
161!19 = distinct !DISubprogram(name: "f5", scope: !1, file: !1, line: 9, type: !9, isLocal: false, isDefinition: true, scopeLine: 9, isOptimized: false, unit: !0, retainedNodes: !2)
162!20 = !DILocalVariable(name: "dog", scope: !19, file: !1, line: 10, type: !12)
163!21 = !DILocation(line: 10, column: 16, scope: !19)
164!22 = !DILocalVariable(name: "cat", scope: !19, file: !1, line: 11, type: !12)
165!23 = !DILocation(line: 11, column: 16, scope: !19)
166!24 = !DILocalVariable(name: "pangolin", scope: !19, file: !1, line: 12, type: !12)
167!25 = !DILocation(line: 12, column: 16, scope: !19)
168!26 = !DILocation(line: 13, column: 1, scope: !19)
169!27 = distinct !DISubprogram(name: "f4", scope: !1, file: !1, line: 15, type: !9, isLocal: false, isDefinition: true, scopeLine: 15, isOptimized: false, unit: !0, retainedNodes: !2)
170!28 = !DILocalVariable(name: "dog", scope: !27, file: !1, line: 16, type: !12)
171!29 = !DILocation(line: 16, column: 16, scope: !27)
172!30 = !DILocalVariable(name: "cat", scope: !27, file: !1, line: 17, type: !12)
173!31 = !DILocation(line: 17, column: 16, scope: !27)
174!32 = !DILocalVariable(name: "pangolin", scope: !27, file: !1, line: 18, type: !12)
175!33 = !DILocation(line: 18, column: 16, scope: !27)
176!34 = !DILocation(line: 19, column: 1, scope: !27)
177!35 = distinct !DISubprogram(name: "f1", scope: !1, file: !1, line: 21, type: !36, isLocal: false, isDefinition: true, scopeLine: 21, isOptimized: false, unit: !0, retainedNodes: !2)
178!36 = !DISubroutineType(types: !37)
179!37 = !{!12}
180!38 = !DILocalVariable(name: "dog", scope: !35, file: !1, line: 22, type: !12)
181!39 = !DILocation(line: 22, column: 16, scope: !35)
182!40 = !DILocalVariable(name: "cat", scope: !35, file: !1, line: 23, type: !12)
183!41 = !DILocation(line: 23, column: 16, scope: !35)
184!42 = !DILocalVariable(name: "pangolin", scope: !35, file: !1, line: 24, type: !12)
185!43 = !DILocation(line: 24, column: 16, scope: !35)
186!44 = !DILocation(line: 25, column: 7, scope: !35)
187!45 = !DILocation(line: 26, column: 10, scope: !35)
188!46 = !DILocation(line: 26, column: 3, scope: !35)
189!47 = distinct !DISubprogram(name: "f2", scope: !1, file: !1, line: 29, type: !36, isLocal: false, isDefinition: true, scopeLine: 29, isOptimized: false, unit: !0, retainedNodes: !2)
190!48 = !DILocalVariable(name: "dog", scope: !47, file: !1, line: 30, type: !12)
191!49 = !DILocation(line: 30, column: 16, scope: !47)
192!50 = !DILocalVariable(name: "cat", scope: !47, file: !1, line: 31, type: !12)
193!51 = !DILocation(line: 31, column: 16, scope: !47)
194!52 = !DILocalVariable(name: "pangolin", scope: !47, file: !1, line: 32, type: !12)
195!53 = !DILocation(line: 32, column: 16, scope: !47)
196!54 = !DILocation(line: 33, column: 7, scope: !47)
197!55 = !DILocation(line: 34, column: 10, scope: !47)
198!56 = !DILocation(line: 34, column: 3, scope: !47)
199!57 = distinct !DISubprogram(name: "f3", scope: !1, file: !1, line: 37, type: !36, isLocal: false, isDefinition: true, scopeLine: 37, isOptimized: false, unit: !0, retainedNodes: !2)
200!58 = !DILocalVariable(name: "dog", scope: !57, file: !1, line: 38, type: !12)
201!59 = !DILocation(line: 38, column: 16, scope: !57)
202!60 = !DILocalVariable(name: "cat", scope: !57, file: !1, line: 39, type: !12)
203!61 = !DILocation(line: 39, column: 16, scope: !57)
204!62 = !DILocalVariable(name: "pangolin", scope: !57, file: !1, line: 40, type: !12)
205!63 = !DILocation(line: 40, column: 16, scope: !57)
206!64 = !DILocation(line: 41, column: 7, scope: !57)
207!65 = !DILocation(line: 42, column: 10, scope: !57)
208!66 = !DILocation(line: 42, column: 3, scope: !57)
209!67 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 45, type: !36, isLocal: false, isDefinition: true, scopeLine: 45, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
210!68 = !DILocalVariable(name: "a", scope: !67, file: !1, line: 46, type: !12)
211!69 = !DILocation(line: 46, column: 16, scope: !67)
212!70 = !DILocation(line: 47, column: 3, scope: !67)
213!71 = !DILocation(line: 48, column: 3, scope: !67)
214!72 = !DILocation(line: 49, column: 3, scope: !67)
215!73 = !DILocation(line: 51, column: 3, scope: !67)
216