Skip to content

Commit 6a1cf54

Browse files
committed
[BOLT][YAML] Only read first profile per function
D159460 regressed the bugfix in D156644. Fix that and emit a warning. Add a test case. Reviewed By: #bolt, maksfb Differential Revision: https://reviews.llvm.org/D159529
1 parent 4ea883c commit 6a1cf54

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

bolt/lib/Profile/YAMLProfileReader.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,19 @@ Error YAMLProfileReader::preprocessProfile(BinaryContext &BC) {
294294
buildNameMaps(BC);
295295

296296
// Preliminary assign function execution count.
297-
for (auto [YamlBF, BF] : llvm::zip_equal(YamlBP.Functions, ProfileBFs))
298-
if (BF)
297+
for (auto [YamlBF, BF] : llvm::zip_equal(YamlBP.Functions, ProfileBFs)) {
298+
if (!BF)
299+
continue;
300+
if (!BF->hasProfile()) {
299301
BF->setExecutionCount(YamlBF.ExecCount);
302+
} else {
303+
if (opts::Verbosity >= 1) {
304+
errs() << "BOLT-WARNING: dropping duplicate profile for " << YamlBF.Name
305+
<< '\n';
306+
}
307+
BF = nullptr;
308+
}
309+
}
300310

301311
return Error::success();
302312
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# This test ensures that a YAML profile with multiple profiles matching the same
2+
# function is handled gracefully.
3+
4+
# REQUIRES: system-linux
5+
# RUN: split-file %s %t
6+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %t/main.s -o %t.o
7+
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -nostdlib
8+
# RUN: llvm-bolt %t.exe -o /dev/null --data %t/profile.yaml \
9+
# RUN: --profile-ignore-hash -v=1 2>&1 | FileCheck %s
10+
# CHECK: BOLT-WARNING: dropping duplicate profile for main_alias(*2)
11+
#--- main.s
12+
.globl main_alias
13+
.type main_alias, %function
14+
main_alias:
15+
.globl main
16+
.type main, %function
17+
main:
18+
.cfi_startproc
19+
cmpl $0x0, %eax
20+
retq
21+
.cfi_endproc
22+
.size main, .-main
23+
.size main_alias, .-main_alias
24+
#--- profile.yaml
25+
---
26+
header:
27+
profile-version: 1
28+
binary-name: 'yaml-multiple-profiles.test.tmp.exe'
29+
binary-build-id: '<unknown>'
30+
profile-flags: [ lbr ]
31+
profile-origin: branch profile reader
32+
profile-events: ''
33+
dfs-order: false
34+
functions:
35+
- name: 'main(*2)'
36+
fid: 1
37+
hash: 0x50BBA3441D436491
38+
exec: 1
39+
nblocks: 1
40+
blocks:
41+
- bid: 0
42+
insns: 2
43+
hash: 0x4D4D8FAF7D4C0000
44+
- name: 'main_alias(*2)'
45+
fid: 1
46+
hash: 0x50BBA3441D436491
47+
exec: 1
48+
nblocks: 1
49+
blocks:
50+
- bid: 0
51+
insns: 2
52+
hash: 0x4D4D8FAF7D4C0000
53+
...

0 commit comments

Comments
 (0)