1 ; RUN: opt < %s -passes=pseudo-probe,sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-profile.prof -pass-remarks=sample-profile -pass-remarks-output=%t.opt.yaml -sample-profile-use-profi=0 -S -o %t
2 ; RUN: FileCheck %s --input-file %t
3 ; RUN: FileCheck %s -check-prefix=YAML --input-file %t.opt.yaml
4 ; RUN: opt < %t -passes=sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-profile.prof -sample-profile-remove-probe -S | FileCheck %s -check-prefix=REMOVE-PROBE
6 ; REMOVE-PROBE-NOT: call void @llvm.pseudoprobe
8 define dso_local i32 @foo(i32 %x, ptr %f) #0 !dbg !4 {
10 %retval = alloca i32, align 4
11 %x.addr = alloca i32, align 4
12 store i32 %x, ptr %x.addr, align 4
13 %0 = load i32, ptr %x.addr, align 4
14 %cmp = icmp eq i32 %0, 0
15 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1, i32 0, i64 -1)
16 br i1 %cmp, label %if.then, label %if.else
17 ; CHECK: br i1 %cmp, label %if.then, label %if.else, !prof ![[PD1:[0-9]+]]
20 ; CHECK: call {{.*}}, !dbg ![[#PROBE1:]], !prof ![[PROF1:[0-9]+]]
22 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 2, i32 0, i64 -1)
23 store i32 1, ptr %retval, align 4
27 ; CHECK: call {{.*}}, !dbg ![[#PROBE2:]], !prof ![[PROF2:[0-9]+]]
29 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
30 store i32 2, ptr %retval, align 4
34 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 6, i32 0, i64 -1)
35 %1 = load i32, ptr %retval, align 4
39 attributes #0 = {"use-sample-profile"}
41 ; CHECK: ![[PD1]] = !{!"branch_weights", i32 8, i32 7}
42 ; CHECK: ![[#PROBE1]] = !DILocation(line: 0, scope: ![[#SCOPE1:]])
43 ;; A discriminator of 387973151 which is 0x1720001f in hexdecimal, stands for an indirect call probe
44 ;; with an index of 3.
45 ; CHECK: ![[#SCOPE1]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 387973151)
46 ; CHECK: ![[PROF1]] = !{!"VP", i32 0, i64 7, i64 9191153033785521275, i64 5, i64 -1069303473483922844, i64 2}
47 ;; A discriminator of 387973167 which is 0x1720002f in hexdecimal, stands for an indirect call probe
48 ;; with an index of 5.
49 ; CHECK: ![[#PROBE2]] = !DILocation(line: 0, scope: ![[#SCOPE2:]])
50 ; CHECK: ![[#SCOPE2]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 387973167)
51 ; CHECK: ![[PROF2]] = !{!"VP", i32 0, i64 6, i64 -1069303473483922844, i64 4, i64 9191153033785521275, i64 2}
53 !llvm.module.flags = !{!9, !10}
55 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1)
56 !1 = !DIFile(filename: "test.c", directory: "")
58 !4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5, unit: !0, retainedNodes: !2)
59 !5 = !DISubroutineType(types: !6)
61 !7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
62 !9 = !{i32 2, !"Dwarf Version", i32 4}
63 !10 = !{i32 2, !"Debug Info Version", i32 3}
65 ; Checking to see if YAML file is generated and contains remarks
67 ;YAML-NEXT: Pass: sample-profile
68 ;YAML-NEXT: Name: AppliedSamples
69 ;YAML-NEXT: DebugLoc: { File: test.c, Line: 0, Column: 0 }
70 ;YAML-NEXT: Function: foo
72 ;YAML-NEXT: - String: 'Applied '
73 ;YAML-NEXT: - NumSamples: '13'
74 ;YAML-NEXT: - String: ' samples from profile (ProbeId='
75 ;YAML-NEXT: - ProbeId: '1'
76 ;YAML-NEXT: - String: ', Factor='
77 ;YAML-NEXT: - Factor: '1.000000e+00'
78 ;YAML-NEXT: - String: ', OriginalSamples='
79 ;YAML-NEXT: - OriginalSamples: '13'
80 ;YAML-NEXT: - String: ')'
82 ;YAML-NEXT: Pass: sample-profile
83 ;YAML-NEXT: Name: AppliedSamples
84 ;YAML-NEXT: DebugLoc: { File: test.c, Line: 0, Column: 0 }
85 ;YAML-NEXT: Function: foo
87 ;YAML-NEXT: - String: 'Applied '
88 ;YAML-NEXT: - NumSamples: '7'
89 ;YAML-NEXT: - String: ' samples from profile (ProbeId='
90 ;YAML-NEXT: - ProbeId: '3'
91 ;YAML-NEXT: - String: ', Factor='
92 ;YAML-NEXT: - Factor: '1.000000e+00'
93 ;YAML-NEXT: - String: ', OriginalSamples='
94 ;YAML-NEXT: - OriginalSamples: '7'
95 ;YAML-NEXT: - String: ')'
97 ;YAML-NEXT: Pass: sample-profile
98 ;YAML-NEXT: Name: AppliedSamples
99 ;YAML-NEXT: DebugLoc: { File: test.c, Line: 0, Column: 0 }
100 ;YAML-NEXT: Function: foo
102 ;YAML-NEXT: - String: 'Applied '
103 ;YAML-NEXT: - NumSamples: '7'
104 ;YAML-NEXT: - String: ' samples from profile (ProbeId='
105 ;YAML-NEXT: - ProbeId: '2'
106 ;YAML-NEXT: - String: ', Factor='
107 ;YAML-NEXT: - Factor: '1.000000e+00'
108 ;YAML-NEXT: - String: ', OriginalSamples='
109 ;YAML-NEXT: - OriginalSamples: '7'
110 ;YAML-NEXT: - String: ')'
112 ;YAML-NEXT: Pass: sample-profile
113 ;YAML-NEXT: Name: AppliedSamples
114 ;YAML-NEXT: DebugLoc: { File: test.c, Line: 0, Column: 0 }
115 ;YAML-NEXT: Function: foo
117 ;YAML-NEXT: - String: 'Applied '
118 ;YAML-NEXT: - NumSamples: '6'
119 ;YAML-NEXT: - String: ' samples from profile (ProbeId='
120 ;YAML-NEXT: - ProbeId: '5'
121 ;YAML-NEXT: - String: ', Factor='
122 ;YAML-NEXT: - Factor: '1.000000e+00'
123 ;YAML-NEXT: - String: ', OriginalSamples='
124 ;YAML-NEXT: - OriginalSamples: '6'
125 ;YAML-NEXT: - String: ')'
127 ;YAML-NEXT: Pass: sample-profile
128 ;YAML-NEXT: Name: AppliedSamples
129 ;YAML-NEXT: DebugLoc: { File: test.c, Line: 0, Column: 0 }
130 ;YAML-NEXT: Function: foo
132 ;YAML-NEXT: - String: 'Applied '
133 ;YAML-NEXT: - NumSamples: '6'
134 ;YAML-NEXT: - String: ' samples from profile (ProbeId='
135 ;YAML-NEXT: - ProbeId: '4'
136 ;YAML-NEXT: - String: ', Factor='
137 ;YAML-NEXT: - Factor: '1.000000e+00'
138 ;YAML-NEXT: - String: ', OriginalSamples='
139 ;YAML-NEXT: - OriginalSamples: '6'
140 ;YAML-NEXT: - String: ')'
142 ;YAML-NEXT: Pass: sample-profile
143 ;YAML-NEXT: Name: AppliedSamples
144 ;YAML-NEXT: DebugLoc: { File: test.c, Line: 0, Column: 0 }
145 ;YAML-NEXT: Function: foo
147 ;YAML-NEXT: - String: 'Applied '
148 ;YAML-NEXT: - NumSamples: '13'
149 ;YAML-NEXT: - String: ' samples from profile (ProbeId='
150 ;YAML-NEXT: - ProbeId: '6'
151 ;YAML-NEXT: - String: ', Factor='
152 ;YAML-NEXT: - Factor: '1.000000e+00'
153 ;YAML-NEXT: - String: ', OriginalSamples='
154 ;YAML-NEXT: - OriginalSamples: '13'
155 ;YAML-NEXT: - String: ')'