Skip to content

Commit 91423d7

Browse files
authored
[BOLT][NFC] Don't assign YAML profile to functions with no CFG (#92487)
YAML profile for non-simple functions without CFG is 1) useless for optimizations, 2) can't be attached, similar to fdata profile, 3) would be reported as invalid/stale even if the profile is valid. Don't attempt to attach the profile in this case, aligning the behavior to DataReader. Test Plan: added yaml-non-simple.test
1 parent fc0144a commit 91423d7

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

bolt/lib/Profile/YAMLProfileReader.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ bool YAMLProfileReader::parseFunctionProfile(
9999
FuncRawBranchCount += YamlSI.Count;
100100
BF.setRawBranchCount(FuncRawBranchCount);
101101

102+
if (BF.empty())
103+
return true;
104+
102105
if (!opts::IgnoreHash &&
103106
YamlBF.Hash != BF.computeHash(IsDFSOrder, HashFunction)) {
104107
if (opts::Verbosity >= 1)

bolt/test/X86/yaml-non-simple.test

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
## Check that YAML profile for non-simple function is not reported as stale.
2+
3+
# RUN: split-file %s %t
4+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %t/main.s -o %t.o
5+
# RUN: %clang %cflags %t.o -o %t.exe -nostdlib
6+
# RUN: llvm-bolt %t.exe -o %t.out --data %t/yaml --profile-ignore-hash -v=1 \
7+
# RUN: --report-stale 2>&1 | FileCheck %s
8+
9+
# CHECK: BOLT-INFO: could not disassemble function main. Will ignore.
10+
# CHECK: BOLT-INFO: could not disassemble function main.cold. Will ignore.
11+
# CHECK: BOLT-INFO: 0 out of 2 functions in the binary (0.0%) have non-empty execution profile
12+
# CHECK: BOLT-INFO: 1 function with profile could not be optimized
13+
14+
#--- main.s
15+
.globl main
16+
.type main, @function
17+
main:
18+
.cfi_startproc
19+
.LBB00:
20+
pushq %rbp
21+
movq %rsp, %rbp
22+
subq $16, %rsp
23+
testq %rax, %rax
24+
js .LBB03
25+
.LBB01:
26+
jne .LBB04
27+
.LBB02:
28+
nop
29+
.LBB03:
30+
xorl %eax, %eax
31+
addq $16, %rsp
32+
popq %rbp
33+
retq
34+
.LBB04:
35+
xorl %eax, %eax
36+
addq $16, %rsp
37+
popq %rbp
38+
retq
39+
.cfi_endproc
40+
.size main, .-main
41+
42+
.globl main.cold
43+
.type main.cold, @function
44+
main.cold:
45+
.cfi_startproc
46+
nop
47+
.cfi_endproc
48+
.size main.cold, .-main.cold
49+
50+
#--- yaml
51+
---
52+
header:
53+
profile-version: 1
54+
binary-name: 'yaml-non-simple.s.tmp.exe'
55+
binary-build-id: '<unknown>'
56+
profile-flags: [ lbr ]
57+
profile-origin: branch profile reader
58+
profile-events: ''
59+
dfs-order: false
60+
hash-func: xxh3
61+
functions:
62+
- name: main
63+
fid: 0
64+
hash: 0x0000000000000000
65+
exec: 1
66+
nblocks: 5
67+
blocks:
68+
- bid: 1
69+
insns: 1
70+
succ: [ { bid: 3, cnt: 1} ]
71+
...

0 commit comments

Comments
 (0)