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