Skip to content

Commit ccfee2d

Browse files
committed
[PseudoProbe] Mix and reorder block and call probe ID in lexical order
1 parent e80b943 commit ccfee2d

File tree

11 files changed

+59
-69
lines changed

11 files changed

+59
-69
lines changed

clang/test/CodeGen/pseudo-probe-emit.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ void foo(int x) {
1010
// CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1, i32 0, i64 -1)
1111
if (x == 0)
1212
// CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 2, i32 0, i64 -1)
13-
bar();
13+
bar(); // probe id : 3
1414
else
15-
// CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 3, i32 0, i64 -1)
16-
go();
17-
// CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 4, i32 0, i64 -1)
15+
// CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 4, i32 0, i64 -1)
16+
go(); // probe id : 5
17+
// CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 6, i32 0, i64 -1)
1818
}

llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ class SampleProfileProber {
8282
uint32_t getBlockId(const BasicBlock *BB) const;
8383
uint32_t getCallsiteId(const Instruction *Call) const;
8484
void computeCFGHash();
85-
void computeProbeIdForBlocks();
86-
void computeProbeIdForCallsites();
85+
void computeProbeId();
8786

8887
Function *F;
8988

llvm/lib/Transforms/IPO/SampleProfileProbe.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ SampleProfileProber::SampleProfileProber(Function &Func,
173173
BlockProbeIds.clear();
174174
CallProbeIds.clear();
175175
LastProbeId = (uint32_t)PseudoProbeReservedId::Last;
176-
computeProbeIdForBlocks();
177-
computeProbeIdForCallsites();
176+
computeProbeId();
178177
computeCFGHash();
179178
}
180179

@@ -209,7 +208,10 @@ void SampleProfileProber::computeCFGHash() {
209208
<< ", Hash = " << FunctionHash << "\n");
210209
}
211210

212-
void SampleProfileProber::computeProbeIdForBlocks() {
211+
void SampleProfileProber::computeProbeId() {
212+
LLVMContext &Ctx = F->getContext();
213+
Module *M = F->getParent();
214+
213215
DenseSet<BasicBlock *> KnownColdBlocks;
214216
computeEHOnlyBlocks(*F, KnownColdBlocks);
215217
// Insert pseudo probe to non-cold blocks only. This will reduce IR size as
@@ -218,18 +220,9 @@ void SampleProfileProber::computeProbeIdForBlocks() {
218220
++LastProbeId;
219221
if (!KnownColdBlocks.contains(&BB))
220222
BlockProbeIds[&BB] = LastProbeId;
221-
}
222-
}
223223

224-
void SampleProfileProber::computeProbeIdForCallsites() {
225-
LLVMContext &Ctx = F->getContext();
226-
Module *M = F->getParent();
227-
228-
for (auto &BB : *F) {
229224
for (auto &I : BB) {
230-
if (!isa<CallBase>(I))
231-
continue;
232-
if (isa<IntrinsicInst>(&I))
225+
if (!isa<CallBase>(I) || isa<IntrinsicInst>(&I))
233226
continue;
234227

235228
// The current implementation uses the lower 16 bits of the discriminator
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
foo:3200:13
22
1: 13
33
2: 7
4-
3: 6
5-
4: 13
6-
5: 7 _Z3barv:2 _Z3foov:5
7-
6: 6 _Z3barv:4 _Z3foov:2
4+
4: 6
5+
6: 13
6+
3: 7 _Z3barv:2 _Z3foov:5
7+
5: 6 _Z3barv:4 _Z3foov:2
88
!CFGChecksum: 563022570642068
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
foo:3200:13
22
1: 13
33
2: 7
4-
3: 6
5-
4: 13
6-
5: 7
7-
6: 6
4+
4: 6
5+
6: 13
6+
7: 7
7+
9: 6
88
!CFGChecksum: 844530426352218

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ Merge:
2323
; JT-LABEL-NO: T
2424
; JT-LABEL-NO: F
2525
; JT-LABEL: Merge
26+
; JT-NOT: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4
2627
; JT-NOT: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 3
27-
; JT-NOT: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 2
28-
; JT: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
28+
; JT: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 5, i32 0, i64 -1)
29+
; ASM-NOT: .pseudoprobe 6699318081062747564 4
2930
; ASM-NOT: .pseudoprobe 6699318081062747564 3
30-
; ASM-NOT: .pseudoprobe 6699318081062747564 2
31-
; ASM: .pseudoprobe 6699318081062747564 4 0 0
31+
; ASM: .pseudoprobe 6699318081062747564 5 0 0
3232
ret i32 %call
3333
}
3434

3535
;; Check block T and F are gone, and their probes (probe 2 and 3) are gone too.
3636
; MIR-tail: bb.0
3737
; MIR-tail: PSEUDO_PROBE [[#GUID:]], 1, 0, 0
38-
; MIR-tail-NOT: PSEUDO_PROBE [[#GUID:]], 2
3938
; MIR-tail-NOT: PSEUDO_PROBE [[#GUID:]], 3
40-
; MIR-tail: PSEUDO_PROBE [[#GUID:]], 4, 0, 0
39+
; MIR-tail-NOT: PSEUDO_PROBE [[#GUID:]], 4
40+
; MIR-tail: PSEUDO_PROBE [[#GUID:]], 5, 0, 0
4141

4242

4343
define i32 @test(i32 %a, i32 %b, i32 %c) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ attributes #1 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "fra
6262
; DEBUG: ![[INST]] = !DILocation(line: 4, column: 15, scope: ![[INSTBLOCK:[0-9]+]])
6363
; DEBUG: ![[INSTBLOCK]] = !DILexicalBlockFile({{.*}} discriminator: 4)
6464

65-
65+
6666
; PROBE: ![[CALL1]] = !DILocation(line: 4, column: 3, scope: ![[CALL1BLOCK:[0-9]+]])
67-
; PROBE: ![[CALL1BLOCK]] = !DILexicalBlockFile({{.*}} discriminator: 186646575)
67+
; PROBE: ![[CALL1BLOCK]] = !DILexicalBlockFile({{.*}} discriminator: 186646559)
6868
; PROBE: ![[CALL2]] = !DILocation(line: 4, column: 9, scope: ![[CALL2BLOCK:[0-9]+]])
69-
; PROBE: ![[CALL2BLOCK]] = !DILexicalBlockFile({{.*}} discriminator: 186646583)
69+
; PROBE: ![[CALL2BLOCK]] = !DILexicalBlockFile({{.*}} discriminator: 186646567)
7070
; PROBE: ![[INST]] = !DILocation(line: 4, column: 15, scope: ![[INSTBLOCK:[0-9]+]])
7171
; PROBE: ![[INSTBLOCK]] = !DILexicalBlockFile({{.*}} discriminator: 4)

llvm/test/Transforms/SampleProfile/pseudo-probe-profile-metadata-2.ll

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if.else:
2929
br label %return
3030

3131
return:
32-
call void @llvm.pseudoprobe(i64 6699318081062747564, i64 4, i32 0, i64 -1)
32+
call void @llvm.pseudoprobe(i64 6699318081062747564, i64 6, i32 0, i64 -1)
3333
%1 = load i32, ptr %retval, align 4
3434
ret i32 %1
3535
}
@@ -55,13 +55,12 @@ attributes #0 = {"use-sample-profile"}
5555
!9 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !5, isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
5656
!10 = !{!"function_entry_count", i64 14}
5757
!11 = !{!"branch_weights", i32 100, i32 0}
58-
;; A discriminator of 186646575 which is 0x6f80057 in hexdecimal, stands for an indirect call probe
59-
;; with an index of 5 and probe factor of 1.0.
60-
!12 = !DILexicalBlockFile(scope: !4, file: !5, discriminator: 186646575)
58+
;; A discriminator of 186646559 which is 0xB20001F in hexdecimal, stands for an indirect call probe
59+
;; with an index of 3 and probe factor of 1.0.
60+
!12 = !DILexicalBlockFile(scope: !4, file: !5, discriminator: 186646559)
6161
!13 = distinct !DILocation(line: 10, column: 11, scope: !12)
62-
;; A discriminator of 134217775 which is 0x6f80057 in hexdecimal, stands for an indirect call probe
63-
;; with an index of 5 and probe factor of 0.
64-
!14 = !DILexicalBlockFile(scope: !4, file: !5, discriminator: 134217775)
62+
;; A discriminator of 134217759 which is 0x800001F in hexdecimal, stands for an indirect call probe
63+
;; with an index of 3 and probe factor of 0.
64+
!14 = !DILexicalBlockFile(scope: !4, file: !5, discriminator: 134217759)
6565
!15 = distinct !DILocation(line: 10, column: 11, scope: !14)
6666
!16 = !{!"VP", i32 0, i64 7, i64 9191153033785521275, i64 5, i64 -1069303473483922844, i64 2}
67-

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ if.then:
2222
if.else:
2323
; CHECK: call {{.*}}, !dbg ![[#PROBE2:]], !prof ![[PROF2:[0-9]+]]
2424
call void %f(i32 2)
25-
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 3, i32 0, i64 -1)
25+
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
2626
store i32 2, ptr %retval, align 4
2727
br label %return
2828

2929
return:
30-
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
30+
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 6, i32 0, i64 -1)
3131
%1 = load i32, ptr %retval, align 4
3232
ret i32 %1
3333
}
@@ -36,14 +36,14 @@ attributes #0 = {"use-sample-profile"}
3636

3737
; CHECK: ![[PD1]] = !{!"branch_weights", i32 8, i32 7}
3838
; CHECK: ![[#PROBE1]] = !DILocation(line: 0, scope: ![[#SCOPE1:]])
39+
;; A discriminator of 119537695 which is 0x720001f in hexdecimal, stands for an indirect call probe
40+
;; with an index of 3.
41+
; CHECK: ![[#SCOPE1]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 119537695)
42+
; CHECK: ![[PROF1]] = !{!"VP", i32 0, i64 7, i64 9191153033785521275, i64 5, i64 -1069303473483922844, i64 2}
3943
;; A discriminator of 119537711 which is 0x720002f in hexdecimal, stands for an indirect call probe
4044
;; 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.
4545
; CHECK: ![[#PROBE2]] = !DILocation(line: 0, scope: ![[#SCOPE2:]])
46-
; CHECK: ![[#SCOPE2]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 119537719)
46+
; CHECK: ![[#SCOPE2]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 119537711)
4747
; CHECK: ![[PROF2]] = !{!"VP", i32 0, i64 6, i64 -1069303473483922844, i64 4, i64 9191153033785521275, i64 2}
4848

4949
!llvm.module.flags = !{!9, !10}
@@ -83,7 +83,7 @@ attributes #0 = {"use-sample-profile"}
8383
;YAML-NEXT: - String: 'Applied '
8484
;YAML-NEXT: - NumSamples: '7'
8585
;YAML-NEXT: - String: ' samples from profile (ProbeId='
86-
;YAML-NEXT: - ProbeId: '5'
86+
;YAML-NEXT: - ProbeId: '3'
8787
;YAML-NEXT: - String: ', Factor='
8888
;YAML-NEXT: - Factor: '1.000000e+00'
8989
;YAML-NEXT: - String: ', OriginalSamples='
@@ -113,7 +113,7 @@ attributes #0 = {"use-sample-profile"}
113113
;YAML-NEXT: - String: 'Applied '
114114
;YAML-NEXT: - NumSamples: '6'
115115
;YAML-NEXT: - String: ' samples from profile (ProbeId='
116-
;YAML-NEXT: - ProbeId: '6'
116+
;YAML-NEXT: - ProbeId: '5'
117117
;YAML-NEXT: - String: ', Factor='
118118
;YAML-NEXT: - Factor: '1.000000e+00'
119119
;YAML-NEXT: - String: ', OriginalSamples='
@@ -128,7 +128,7 @@ attributes #0 = {"use-sample-profile"}
128128
;YAML-NEXT: - String: 'Applied '
129129
;YAML-NEXT: - NumSamples: '6'
130130
;YAML-NEXT: - String: ' samples from profile (ProbeId='
131-
;YAML-NEXT: - ProbeId: '3'
131+
;YAML-NEXT: - ProbeId: '4'
132132
;YAML-NEXT: - String: ', Factor='
133133
;YAML-NEXT: - Factor: '1.000000e+00'
134134
;YAML-NEXT: - String: ', OriginalSamples='
@@ -143,7 +143,7 @@ attributes #0 = {"use-sample-profile"}
143143
;YAML-NEXT: - String: 'Applied '
144144
;YAML-NEXT: - NumSamples: '13'
145145
;YAML-NEXT: - String: ' samples from profile (ProbeId='
146-
;YAML-NEXT: - ProbeId: '4'
146+
;YAML-NEXT: - ProbeId: '6'
147147
;YAML-NEXT: - String: ', Factor='
148148
;YAML-NEXT: - Factor: '1.000000e+00'
149149
;YAML-NEXT: - String: ', OriginalSamples='

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,31 @@ T1:
1414
%v1 = call i32 @f1()
1515
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 2, i32 0, i64 -1)
1616
;; The distribution factor -8513881372706734080 stands for 53.85%, whic is from 7/6+7.
17-
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -8513881372706734080)
17+
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 6, i32 0, i64 -8513881372706734080)
1818
%cond3 = icmp eq i32 %v1, 412
1919
br label %Merge
2020
F1:
2121
; CHECK: %v2 = call i32 @f2(), !prof ![[#PROF2:]]
2222
%v2 = call i32 @f2()
23-
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 3, i32 0, i64 -1)
23+
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
2424
;; The distribution factor 8513881922462547968 stands for 46.25%, which is from 6/6+7.
25-
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 8513881922462547968)
25+
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 6, i32 0, i64 8513881922462547968)
2626
br label %Merge
2727
Merge:
2828

2929
%A = phi i1 [%cond3, %T1], [%cond2, %F1]
3030
%B = phi i32 [%v1, %T1], [%v2, %F1]
3131
br i1 %A, label %T2, label %F2
3232
T2:
33-
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 5, i32 0, i64 -1)
33+
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 7, i32 0, i64 -1)
3434
call void @f3()
3535
ret i32 %B
3636
F2:
37-
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 6, i32 0, i64 -1)
37+
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 9, i32 0, i64 -1)
3838
ret i32 %B
3939
}
4040

4141
; CHECK: ![[#PROF1]] = !{!"branch_weights", i32 7}
4242
; CHECK: ![[#PROF2]] = !{!"branch_weights", i32 6}
4343

4444
attributes #0 = {"use-sample-profile"}
45-

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
; VERIFY: *** Pseudo Probe Verification After LoopFullUnrollPass ***
66
; VERIFY: Function foo:
7-
; VERIFY-DAG: Probe 6 previous factor 1.00 current factor 5.00
7+
; VERIFY-DAG: Probe 5 previous factor 1.00 current factor 5.00
88
; VERIFY-DAG: Probe 4 previous factor 1.00 current factor 5.00
99

1010
declare void @foo2() nounwind
@@ -27,15 +27,15 @@ bb7.preheader:
2727

2828
bb10:
2929
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
30-
; CHECK: call void @foo2(), !dbg ![[#PROBE6:]]
30+
; CHECK: call void @foo2(), !dbg ![[#PROBE6:]]
3131
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
32-
; CHECK: call void @foo2(), !dbg ![[#PROBE6:]]
32+
; CHECK: call void @foo2(), !dbg ![[#PROBE6:]]
3333
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
34-
; CHECK: call void @foo2(), !dbg ![[#PROBE6:]]
34+
; CHECK: call void @foo2(), !dbg ![[#PROBE6:]]
3535
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
36-
; CHECK: call void @foo2(), !dbg ![[#PROBE6:]]
36+
; CHECK: call void @foo2(), !dbg ![[#PROBE6:]]
3737
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
38-
; CHECK: call void @foo2(), !dbg ![[#PROBE6:]]
38+
; CHECK: call void @foo2(), !dbg ![[#PROBE6:]]
3939
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 2, i32 0, i64 -1)
4040
%indvars.iv = phi i64 [ 0, %bb7.preheader ], [ %indvars.iv.next, %bb10 ]
4141
%tmp1.14 = phi i32 [ %tmp1.06, %bb7.preheader ], [ %spec.select, %bb10 ]
@@ -50,14 +50,14 @@ bb10:
5050
br i1 %exitcond.not, label %bb3.loopexit, label %bb10, !llvm.loop !13
5151

5252
bb24:
53-
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 5, i32 0, i64 -1)
53+
; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 6, i32 0, i64 -1)
5454
ret void
5555
}
5656

5757
;; A discriminator of 186646583 which is 0xb200037 in hexdecimal, stands for a direct call probe
5858
;; with an index of 6 and a scale of -1%.
5959
; CHECK: ![[#PROBE6]] = !DILocation(line: 2, column: 20, scope: ![[#SCOPE:]])
60-
; CHECK: ![[#SCOPE]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 186646583)
60+
; CHECK: ![[#SCOPE]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 186646575)
6161

6262
!llvm.dbg.cu = !{!0}
6363
!llvm.module.flags = !{!9, !10}

0 commit comments

Comments
 (0)