Skip to content

[BOLT][merge-fdata] Initialize YAML profile header #109613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions bolt/test/merge-fdata-uninitialized-header.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Test that merge-fdata correctly handles YAML header with an uninitialized
## fields. a.yaml does not have hash-func set and it used to crash merge-fdata.

# REQUIRES: system-linux

# RUN: split-file %s %t
# RUN: not merge-fdata %t/a.yaml %t/b.yaml 2>&1 | FileCheck %s

# CHECK: cannot merge profiles with different hash functions

#--- a.yaml
---
header:
profile-version: 1
binary-name: 'a.out'
binary-build-id: '<unknown>'
profile-flags: [ lbr ]
profile-origin: branch profile reader
profile-events: ''
dfs-order: false
functions:
- name: 'main'
fid: 1
hash: 0x50BBA3441D436491
exec: 1
nblocks: 0
...
#--- b.yaml
---
header:
profile-version: 1
binary-name: 'a.out'
binary-build-id: '<unknown>'
profile-flags: [ lbr ]
profile-origin: branch profile reader
profile-events: ''
dfs-order: false
hash-func: xxh3
functions:
- name: 'main'
fid: 1
hash: 0x50BBA3441D436491
exec: 1
nblocks: 0
...
12 changes: 11 additions & 1 deletion bolt/tools/merge-fdata/merge-fdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ void mergeProfileHeaders(BinaryProfileHeader &MergedHeader,
errs() << "WARNING: merging profiles with different sampling events\n";
MergedHeader.EventNames += "," + Header.EventNames;
}

if (MergedHeader.HashFunction != Header.HashFunction)
report_error("merge conflict",
"cannot merge profiles with different hash functions");
}

void mergeBasicBlockProfile(BinaryBasicBlockProfile &MergedBB,
Expand Down Expand Up @@ -386,6 +390,7 @@ int main(int argc, char **argv) {
// Merged information for all functions.
StringMap<BinaryFunctionProfile> MergedBFs;

bool FirstHeader = true;
for (std::string &InputDataFilename : Inputs) {
ErrorOr<std::unique_ptr<MemoryBuffer>> MB =
MemoryBuffer::getFileOrSTDIN(InputDataFilename);
Expand All @@ -409,7 +414,12 @@ int main(int argc, char **argv) {
}

// Merge the header.
mergeProfileHeaders(MergedHeader, BP.Header);
if (FirstHeader) {
MergedHeader = BP.Header;
FirstHeader = false;
} else {
mergeProfileHeaders(MergedHeader, BP.Header);
}

// Do the function merge.
for (BinaryFunctionProfile &BF : BP.Functions) {
Expand Down
Loading