Debian Codegraph @

llvm/test/Transforms/SampleProfile/pseudo-probe-inline.ll

raw
1 ; RUN: opt < %s -passes=pseudo-probe,sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-inline.prof -S -pass-remarks=sample-profile -sample-profile-prioritized-inline=0 -pass-remarks-output=%t.opt.yaml 2>&1 | FileCheck %s
2 ; RUN: FileCheck %s -check-prefixes=YAML,YAML-NO-ANNOTATE < %t.opt.yaml
3
4 ; RUN: llvm-profdata merge --sample --extbinary %S/Inputs/pseudo-probe-inline.prof -o %t2
5 ; RUN: opt < %s -passes=pseudo-probe,sample-profile -sample-profile-file=%t2 -S -pass-remarks=sample-profile -sample-profile-prioritized-inline=0 -pass-remarks-output=%t2.opt.yaml 2>&1 | FileCheck %s
6 ; RUN: FileCheck %s -check-prefixes=YAML,YAML-NO-ANNOTATE < %t2.opt.yaml
7
8 ; RUN: opt < %s -passes=pseudo-probe,sample-profile -annotate-sample-profile-inline-phase=true -sample-profile-file=%S/Inputs/pseudo-probe-inline.prof -S -pass-remarks=sample-profile -sample-profile-prioritized-inline=0 -pass-remarks-output=%t3.opt.yaml 2>&1 | FileCheck %s
9 ; RUN: FileCheck %s -check-prefixes=YAML,YAML-ANNOTATE < %t3.opt.yaml
10
11 ; RUN: opt < %s -passes=pseudo-probe,sample-profile -annotate-sample-profile-inline-phase=true -sample-profile-file=%t2 -S -pass-remarks=sample-profile -sample-profile-prioritized-inline=0 -pass-remarks-output=%t4.opt.yaml 2>&1 | FileCheck %s
12 ; RUN: FileCheck %s -check-prefixes=YAML,YAML-ANNOTATE < %t4.opt.yaml
13
14 @factor = dso_local global i32 3, align 4
15
16 define dso_local i32 @foo(i32 %x) #0 !dbg !12 {
17 entry:
18 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID1:]], i64 1, i32 0, i64 -1)
19 %add = add nsw i32 %x, 100000, !dbg !19
20 ;; Check zen is fully inlined so there's no call to zen anymore.
21 ;; Check code from the inlining of zen is properly annotated here.
22 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID2:]], i64 1, i32 0, i64 -1)
23 ; CHECK: br i1 %cmp.i, label %while.cond.i, label %while.cond2.i, !dbg ![[#]], !prof ![[PD1:[0-9]+]]
24 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID2]], i64 2, i32 0, i64 -1)
25 ; CHECK: br i1 %cmp1.i, label %while.body.i, label %zen.exit, !dbg ![[#]], !prof ![[PD2:[0-9]+]]
26 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID2]], i64 3, i32 0, i64 -1)
27 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID2]], i64 4, i32 0, i64 -1)
28 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID2]], i64 5, i32 0, i64 -1)
29 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID2]], i64 6, i32 0, i64 -1)
30 ; CHECK-NOT: call i32 @zen
31 %call = call i32 @zen(i32 %add), !dbg !20
32 ret i32 %call, !dbg !21
33 }
34
35 ; CHECK: define dso_local i32 @zen
36 define dso_local i32 @zen(i32 %x) #0 !dbg !22 {
37 entry:
38 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID2]], i64 1, i32 0, i64 -1)
39 %cmp = icmp sgt i32 %x, 0, !dbg !26
40 br i1 %cmp, label %while.cond, label %while.cond2, !dbg !28
41
42 while.cond:
43 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID2]], i64 2, i32 0, i64 -1)
44 %x.addr.0 = phi i32 [ %x, %entry ], [ %sub, %while.body ]
45 %cmp1 = icmp sgt i32 %x.addr.0, 0, !dbg !29
46 br i1 %cmp1, label %while.body, label %if.end, !dbg !31
47
48 while.body:
49 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID2]], i64 3, i32 0, i64 -1)
50 %0 = load volatile i32, ptr @factor, align 4, !dbg !32
51 %sub = sub nsw i32 %x.addr.0, %0, !dbg !39
52 br label %while.cond, !dbg !31
53
54 while.cond2:
55 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID2]], i64 4, i32 0, i64 -1)
56 %x.addr.1 = phi i32 [ %x, %entry ], [ %add, %while.body4 ]
57 %cmp3 = icmp slt i32 %x.addr.1, 0, !dbg !42
58 br i1 %cmp3, label %while.body4, label %if.end, !dbg !44
59
60 while.body4:
61 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID2]], i64 5, i32 0, i64 -1)
62 %1 = load volatile i32, ptr @factor, align 4, !dbg !45
63 %add = add nsw i32 %x.addr.1, %1, !dbg !48
64 br label %while.cond2, !dbg !44
65
66 if.end:
67 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID2]], i64 6, i32 0, i64 -1)
68 %x.addr.2 = phi i32 [ %x.addr.0, %while.cond ], [ %x.addr.1, %while.cond2 ]
69 ret i32 %x.addr.2, !dbg !51
70 }
71
72 ; CHECK: !llvm.pseudo_probe_desc = !{![[#DESC0:]], ![[#DESC1:]]}
73 ; CHECK: ![[#DESC0]] = !{i64 [[#GUID1]], i64 [[#HASH1:]], !"foo"}
74 ; CHECK: ![[#DESC1]] = !{i64 [[#GUID2]], i64 [[#HASH2:]], !"zen"}
75 ; CHECK: ![[PD1]] = !{!"branch_weights", i32 5, i32 0}
76 ; CHECK: ![[PD2]] = !{!"branch_weights", i32 382915, i32 5}
77
78 ; Checking to see if YAML file is generated and contains remarks
79 ;YAML: --- !Passed
80 ;YAML-NO-ANNOTATE-NEXT: Pass: sample-profile-inline
81 ;YAML-ANNOTATE-NEXT: Pass: main-sample-profile-inline
82 ;YAML-NEXT: Name: Inlined
83 ;YAML-NEXT: DebugLoc: { File: test.cpp, Line: 10, Column: 11 }
84 ;YAML-NEXT: Function: foo
85 ;YAML-NEXT: Args:
86 ;YAML-NEXT: - String: ''''
87 ;YAML-NEXT: - Callee: zen
88 ;YAML-NEXT: DebugLoc: { File: test.cpp, Line: 38, Column: 0 }
89 ;YAML-NEXT: - String: ''' inlined into '''
90 ;YAML-NEXT: - Caller: foo
91 ;YAML-NEXT: DebugLoc: { File: test.cpp, Line: 9, Column: 0 }
92 ;YAML-NEXT: - String: ''''
93 ;YAML-NEXT: - String: ' to match profiling context'
94 ;YAML-NEXT: - String: ' with '
95 ;YAML-NEXT: - String: '(cost='
96 ;YAML-NEXT: - Cost: '15'
97 ;YAML-NEXT: - String: ', threshold='
98 ;YAML-NEXT: - Threshold: '3000'
99 ;YAML-NEXT: - String: ')'
100 ;YAML-NEXT: - String: ' at callsite '
101 ;YAML-NEXT: - String: foo
102 ;YAML-NEXT: - String: ':'
103 ;YAML-NEXT: - Line: '1'
104 ;YAML-NEXT: - String: ':'
105 ;YAML-NEXT: - Column: '11'
106 ;YAML-NEXT: - String: ';'
107 ;YAML-NEXT: ...
108 ;YAML: --- !Analysis
109 ;YAML-NEXT: Pass: sample-profile
110 ;YAML-NEXT: Name: AppliedSamples
111 ;YAML-NEXT: DebugLoc: { File: test.cpp, Line: 10, Column: 22 }
112 ;YAML-NEXT: Function: foo
113 ;YAML-NEXT: Args:
114 ;YAML-NEXT: - String: 'Applied '
115 ;YAML-NEXT: - NumSamples: '23'
116 ;YAML-NEXT: - String: ' samples from profile (ProbeId='
117 ;YAML-NEXT: - ProbeId: '1'
118 ;YAML-NEXT: - String: ', Factor='
119 ;YAML-NEXT: - Factor: '1.000000e+00'
120 ;YAML-NEXT: - String: ', OriginalSamples='
121 ;YAML-NEXT: - OriginalSamples: '23'
122 ;YAML-NEXT: - String: ')'
123 ;YAML-NEXT: ...
124 ;YAML: --- !Analysis
125 ;YAML-NEXT: Pass: sample-profile
126 ;YAML-NEXT: Name: AppliedSamples
127 ;YAML-NEXT: DebugLoc: { File: test.cpp, Line: 39, Column: 9 }
128 ;YAML-NEXT: Function: foo
129 ;YAML-NEXT: Args:
130 ;YAML-NEXT: - String: 'Applied '
131 ;YAML-NEXT: - NumSamples: '23'
132 ;YAML-NEXT: - String: ' samples from profile (ProbeId='
133 ;YAML-NEXT: - ProbeId: '1'
134 ;YAML-NEXT: - String: ', Factor='
135 ;YAML-NEXT: - Factor: '1.000000e+00'
136 ;YAML-NEXT: - String: ', OriginalSamples='
137 ;YAML-NEXT: - OriginalSamples: '23'
138 ;YAML-NEXT: - String: ')'
139 ;YAML-NEXT: ...
140 ;YAML: --- !Analysis
141 ;YAML-NEXT: Pass: sample-profile
142 ;YAML-NEXT: Name: AppliedSamples
143 ;YAML-NEXT: DebugLoc: { File: test.cpp, Line: 41, Column: 14 }
144 ;YAML-NEXT: Function: foo
145 ;YAML-NEXT: Args:
146 ;YAML-NEXT: - String: 'Applied '
147 ;YAML-NEXT: - NumSamples: '382920'
148 ;YAML-NEXT: - String: ' samples from profile (ProbeId='
149 ;YAML-NEXT: - ProbeId: '2'
150 ;YAML-NEXT: - String: ', Factor='
151 ;YAML-NEXT: - Factor: '1.000000e+00'
152 ;YAML-NEXT: - String: ', OriginalSamples='
153 ;YAML-NEXT: - OriginalSamples: '382920'
154 ;YAML-NEXT: - String: ')'
155 ;YAML-NEXT: ...
156
157 attributes #0 = {"use-sample-profile"}
158
159 !llvm.module.flags = !{!8, !9}
160
161 !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3)
162 !3 = !DIFile(filename: "test.cpp", directory: "test")
163 !4 = !{}
164 !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
165 !8 = !{i32 7, !"Dwarf Version", i32 4}
166 !9 = !{i32 2, !"Debug Info Version", i32 3}
167 !12 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 9, type: !13, scopeLine: 9, unit: !2)
168 !13 = !DISubroutineType(types: !14)
169 !14 = !{!7, !7}
170 !18 = !DILocation(line: 0, scope: !12)
171 !19 = !DILocation(line: 10, column: 22, scope: !12)
172 !20 = !DILocation(line: 10, column: 11, scope: !12)
173 !21 = !DILocation(line: 12, column: 3, scope: !12)
174 !22 = distinct !DISubprogram(name: "zen", scope: !3, file: !3, line: 37, type: !13, scopeLine: 38, unit: !2)
175 !25 = !DILocation(line: 0, scope: !22)
176 !26 = !DILocation(line: 39, column: 9, scope: !27)
177 !27 = distinct !DILexicalBlock(scope: !22, file: !3, line: 39, column: 7)
178 !28 = !DILocation(line: 39, column: 7, scope: !22)
179 !29 = !DILocation(line: 41, column: 14, scope: !30)
180 !30 = distinct !DILexicalBlock(scope: !27, file: !3, line: 39, column: 14)
181 !31 = !DILocation(line: 41, column: 5, scope: !30)
182 !32 = !DILocation(line: 42, column: 16, scope: !33)
183 !33 = distinct !DILexicalBlock(scope: !30, file: !3, line: 41, column: 19)
184 !38 = !DILocation(line: 42, column: 12, scope: !33)
185 !39 = !DILocation(line: 42, column: 9, scope: !33)
186 !42 = !DILocation(line: 48, column: 14, scope: !43)
187 !43 = distinct !DILexicalBlock(scope: !27, file: !3, line: 46, column: 8)
188 !44 = !DILocation(line: 48, column: 5, scope: !43)
189 !45 = !DILocation(line: 49, column: 16, scope: !46)
190 !46 = distinct !DILexicalBlock(scope: !43, file: !3, line: 48, column: 19)
191 !47 = !DILocation(line: 49, column: 12, scope: !46)
192 !48 = !DILocation(line: 49, column: 9, scope: !46)
193 !51 = !DILocation(line: 53, column: 3, scope: !22)