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 | FileCheck %s
2 ; RUN: FileCheck %s -check-prefix=YAML < %t.opt.yaml
4 define dso_local i32 @foo(i32 %x, ptr %f) #0 !dbg !4 {
6 %retval = alloca i32, align 4
7 %x.addr = alloca i32, align 4
8 store i32 %x, ptr %x.addr, align 4
9 %0 = load i32, ptr %x.addr, align 4
10 %cmp = icmp eq i32 %0, 0
11 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1, i32 0, i64 -1)
12 br i1 %cmp, label %if.then, label %if.else
13 ; CHECK: br i1 %cmp, label %if.then, label %if.else, !prof ![[PD1:[0-9]+]]
16 ; CHECK: call {{.*}}, !dbg ![[#PROBE1:]], !prof ![[PROF1:[0-9]+]]
18 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 2, i32 0, i64 -1)
19 store i32 1, ptr %retval, align 4
23 ; CHECK: call {{.*}}, !dbg ![[#PROBE2:]], !prof ![[PROF2:[0-9]+]]
25 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 3, i32 0, i64 -1)
26 store i32 2, ptr %retval, align 4
30 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
31 %1 = load i32, ptr %retval, align 4
35 attributes #0 = {"use-sample-profile"}
37 ; CHECK: ![[PD1]] = !{!"branch_weights", i32 8, i32 7}
38 ; CHECK: ![[#PROBE1]] = !DILocation(line: 0, scope: ![[#SCOPE1:]])
39 ;; A discriminator of 119537711 which is 0x720002f in hexdecimal, stands for an indirect call probe
40 ;; with an index of 5.
41 ; CHECK: ![[#SCOPE1]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 119537711)
42 ; CHECK: ![[PROF1]] = !{!"VP", i32 0, i64 7, i64 9191153033785521275, i64 5, i64 -1069303473483922844, i64 2}
43 ;; A discriminator of 119537719 which is 0x7200037 in hexdecimal, stands for an indirect call probe
44 ;; with an index of 6.
45 ; CHECK: ![[#PROBE2]] = !DILocation(line: 0, scope: ![[#SCOPE2:]])
46 ; CHECK: ![[#SCOPE2]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 119537719)
47 ; CHECK: ![[PROF2]] = !{!"VP", i32 0, i64 6, i64 -1069303473483922844, i64 4, i64 9191153033785521275, i64 2}
49 !llvm.module.flags = !{!9, !10}
51 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1)
52 !1 = !DIFile(filename: "test.c", directory: "")
54 !4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5, unit: !0, retainedNodes: !2)
55 !5 = !DISubroutineType(types: !6)
57 !7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
58 !9 = !{i32 2, !"Dwarf Version", i32 4}
59 !10 = !{i32 2, !"Debug Info Version", i32 3}
61 ; Checking to see if YAML file is generated and contains remarks
63 ;YAML-NEXT: Pass: sample-profile
64 ;YAML-NEXT: Name: AppliedSamples
65 ;YAML-NEXT: DebugLoc: { File: test.c, Line: 0, Column: 0 }
66 ;YAML-NEXT: Function: foo
68 ;YAML-NEXT: - String: 'Applied '
69 ;YAML-NEXT: - NumSamples: '13'
70 ;YAML-NEXT: - String: ' samples from profile (ProbeId='
71 ;YAML-NEXT: - ProbeId: '1'
72 ;YAML-NEXT: - String: ', Factor='
73 ;YAML-NEXT: - Factor: '1.000000e+00'
74 ;YAML-NEXT: - String: ', OriginalSamples='
75 ;YAML-NEXT: - OriginalSamples: '13'
76 ;YAML-NEXT: - String: ')'
78 ;YAML-NEXT: Pass: sample-profile
79 ;YAML-NEXT: Name: AppliedSamples
80 ;YAML-NEXT: DebugLoc: { File: test.c, Line: 0, Column: 0 }
81 ;YAML-NEXT: Function: foo
83 ;YAML-NEXT: - String: 'Applied '
84 ;YAML-NEXT: - NumSamples: '7'
85 ;YAML-NEXT: - String: ' samples from profile (ProbeId='
86 ;YAML-NEXT: - ProbeId: '5'
87 ;YAML-NEXT: - String: ', Factor='
88 ;YAML-NEXT: - Factor: '1.000000e+00'
89 ;YAML-NEXT: - String: ', OriginalSamples='
90 ;YAML-NEXT: - OriginalSamples: '7'
91 ;YAML-NEXT: - String: ')'
93 ;YAML-NEXT: Pass: sample-profile
94 ;YAML-NEXT: Name: AppliedSamples
95 ;YAML-NEXT: DebugLoc: { File: test.c, Line: 0, Column: 0 }
96 ;YAML-NEXT: Function: foo
98 ;YAML-NEXT: - String: 'Applied '
99 ;YAML-NEXT: - NumSamples: '7'
100 ;YAML-NEXT: - String: ' samples from profile (ProbeId='
101 ;YAML-NEXT: - ProbeId: '2'
102 ;YAML-NEXT: - String: ', Factor='
103 ;YAML-NEXT: - Factor: '1.000000e+00'
104 ;YAML-NEXT: - String: ', OriginalSamples='
105 ;YAML-NEXT: - OriginalSamples: '7'
106 ;YAML-NEXT: - String: ')'
108 ;YAML-NEXT: Pass: sample-profile
109 ;YAML-NEXT: Name: AppliedSamples
110 ;YAML-NEXT: DebugLoc: { File: test.c, Line: 0, Column: 0 }
111 ;YAML-NEXT: Function: foo
113 ;YAML-NEXT: - String: 'Applied '
114 ;YAML-NEXT: - NumSamples: '6'
115 ;YAML-NEXT: - String: ' samples from profile (ProbeId='
116 ;YAML-NEXT: - ProbeId: '6'
117 ;YAML-NEXT: - String: ', Factor='
118 ;YAML-NEXT: - Factor: '1.000000e+00'
119 ;YAML-NEXT: - String: ', OriginalSamples='
120 ;YAML-NEXT: - OriginalSamples: '6'
121 ;YAML-NEXT: - String: ')'
123 ;YAML-NEXT: Pass: sample-profile
124 ;YAML-NEXT: Name: AppliedSamples
125 ;YAML-NEXT: DebugLoc: { File: test.c, Line: 0, Column: 0 }
126 ;YAML-NEXT: Function: foo
128 ;YAML-NEXT: - String: 'Applied '
129 ;YAML-NEXT: - NumSamples: '6'
130 ;YAML-NEXT: - String: ' samples from profile (ProbeId='
131 ;YAML-NEXT: - ProbeId: '3'
132 ;YAML-NEXT: - String: ', Factor='
133 ;YAML-NEXT: - Factor: '1.000000e+00'
134 ;YAML-NEXT: - String: ', OriginalSamples='
135 ;YAML-NEXT: - OriginalSamples: '6'
136 ;YAML-NEXT: - String: ')'
138 ;YAML-NEXT: Pass: sample-profile
139 ;YAML-NEXT: Name: AppliedSamples
140 ;YAML-NEXT: DebugLoc: { File: test.c, Line: 0, Column: 0 }
141 ;YAML-NEXT: Function: foo
143 ;YAML-NEXT: - String: 'Applied '
144 ;YAML-NEXT: - NumSamples: '13'
145 ;YAML-NEXT: - String: ' samples from profile (ProbeId='
146 ;YAML-NEXT: - ProbeId: '4'
147 ;YAML-NEXT: - String: ', Factor='
148 ;YAML-NEXT: - Factor: '1.000000e+00'
149 ;YAML-NEXT: - String: ', OriginalSamples='
150 ;YAML-NEXT: - OriginalSamples: '13'
151 ;YAML-NEXT: - String: ')'