Skip to content

Commit 15fa3ba

Browse files
authored
[BOLT][YAML] Allow unknown keys in the input (#100824)
This ensures forward compatibility, where old BOLT versions can consume the profile created by newer versions with extra keys. Test Plan: added yaml-unknown-keys.test
1 parent 126940b commit 15fa3ba

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

bolt/lib/Profile/YAMLProfileReader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ Error YAMLProfileReader::preprocessProfile(BinaryContext &BC) {
373373
return errorCodeToError(EC);
374374
}
375375
yaml::Input YamlInput(MB.get()->getBuffer());
376+
YamlInput.setAllowUnknownKeys(true);
376377

377378
// Consume YAML file.
378379
YamlInput >> YamlBP;

bolt/test/X86/yaml-unknown-keys.test

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
## Test that BOLT gracefully handles a YAML profile with unknown keys.
2+
3+
# REQUIRES: system-linux
4+
# RUN: split-file %s %t
5+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %t/main.s -o %t.o
6+
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -nostdlib
7+
# RUN: llvm-bolt %t.exe -o %t.null --data %t/profile.yaml \
8+
# RUN: --profile-ignore-hash -v=1 2>&1 | FileCheck %s
9+
# CHECK: warning: unknown key 'unknown-header-key'
10+
# CHECK: warning: unknown key 'unknown_succ_key'
11+
# CHECK: warning: unknown key 'unknown_block_key'
12+
# CHECK: warning: unknown key 'unknown_function_key'
13+
# CHECK: warning: unknown key 'unknown_toplev_key'
14+
#--- main.s
15+
.globl main
16+
.type main, %function
17+
main:
18+
.cfi_startproc
19+
cmpl $0x0, %eax
20+
jne .LBB0
21+
.LBB0:
22+
retq
23+
.cfi_endproc
24+
.size main, .-main
25+
#--- profile.yaml
26+
---
27+
header:
28+
profile-version: 1
29+
binary-name: 'yaml-multiple-profiles.test.tmp.exe'
30+
binary-build-id: '<unknown>'
31+
profile-flags: [ lbr ]
32+
profile-origin: branch profile reader
33+
profile-events: ''
34+
dfs-order: false
35+
unknown-header-key: true
36+
functions:
37+
- name: 'main'
38+
fid: 1
39+
hash: 0x50BBA3441D436491
40+
exec: 1
41+
nblocks: 1
42+
blocks:
43+
- bid: 0
44+
insns: 2
45+
hash: 0x4D4D8FAF7D4C0000
46+
succ: [ { bid: 1, cnt: 0, unknown_succ_key: 0x10 } ]
47+
unknown_block_key: [ ]
48+
unknown_function_key: 1
49+
unknown_toplev_key: ''
50+
...

bolt/tools/merge-fdata/merge-fdata.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ int main(int argc, char **argv) {
392392
if (std::error_code EC = MB.getError())
393393
report_error(InputDataFilename, EC);
394394
yaml::Input YamlInput(MB.get()->getBuffer());
395+
YamlInput.setAllowUnknownKeys(true);
395396

396397
errs() << "Merging data from " << InputDataFilename << "...\n";
397398

0 commit comments

Comments
 (0)