[BOLT][merge-fdata] Preserve event names

Test Plan: added merge-fdata-no-lbr-event*.test

Reviewers:
maksfb, paschalis-mpeis, yozhu, yota9, yavtuk, rafaelauler, ayermolo

Reviewed By: rafaelauler

Pull Request: https://github.com/llvm/llvm-project/pull/199323
This commit is contained in:
Amir Ayupov 2026-05-27 00:38:55 -07:00 committed by GitHub
parent 3e0c818e6f
commit d63f99627b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 61 additions and 2 deletions

View file

@ -0,0 +1,22 @@
## Check that merge-fdata preserves and propagates multiple event names from
## the "no_lbr" header line, deduplicating across input files, when combined
## with boltedcollection.
# REQUIRES: system-linux
# RUN: split-file %s %t
# RUN: merge-fdata %t/a.fdata %t/b.fdata -o %t/merged.fdata
# RUN: FileCheck %s --input-file %t/merged.fdata
# CHECK: boltedcollection
# CHECK: no_lbr{{.*( cycles:u| instructions)( cycles:u| instructions)}}
# CHECK: 0 main 10 150
#--- a.fdata
boltedcollection
no_lbr cycles:u instructions
0 main 10 100
#--- b.fdata
boltedcollection
no_lbr instructions cycles:u
0 main 10 50

View file

@ -0,0 +1,18 @@
## Check that merge-fdata preserves and propagates event names from the
## "no_lbr" header line to the merged output.
# REQUIRES: system-linux
# RUN: split-file %s %t
# RUN: merge-fdata %t/a.fdata %t/b.fdata -o %t/merged.fdata
# RUN: FileCheck %s --input-file %t/merged.fdata
# CHECK: no_lbr cycles:u
# CHECK: 1 main 0 2
#--- a.fdata
no_lbr cycles:u
1 main 0 1
#--- b.fdata
no_lbr cycles:u
1 main 0 1

View file

@ -15,6 +15,7 @@
#include "bolt/Profile/ProfileYAMLMapping.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/ManagedStatic.h"
@ -268,6 +269,7 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
std::optional<bool> BoltedCollection;
std::optional<bool> NoLBRCollection;
std::mutex BoltedCollectionMutex;
std::set<std::string> EventNames;
struct CounterTy {
uint64_t Exec{0};
uint64_t Mispred{0};
@ -312,7 +314,20 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
checkMode("boltedcollection", BoltedCollection);
// Check if the string "no_lbr" is in the first line
// (or second line if BoltedCollection is true)
// The line may also contain space-separated event names following
// "no_lbr", e.g. "no_lbr cycles:u". Preserve and propagate them to
// the merged output.
std::string NoLBRLineCopy = FdataLine;
checkMode("no_lbr", NoLBRCollection);
StringRef NoLBRLine(NoLBRLineCopy);
if (NoLBRCollection.value_or(false) &&
NoLBRLine.consume_front("no_lbr")) {
SmallVector<StringRef> Events;
NoLBRLine.trim().split(Events, ' ', /*MaxSplit=*/-1,
/*KeepEmpty=*/false);
for (StringRef Event : Events)
EventNames.insert(Event.str());
}
Profile = &Profiles[tid];
}
@ -382,8 +397,12 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
if (BoltedCollection.value_or(false))
output() << "boltedcollection\n";
if (NoLBRCollection.value_or(false))
output() << "no_lbr\n";
if (NoLBRCollection.value_or(false)) {
output() << "no_lbr";
for (StringRef Entry : EventNames)
output() << ' ' << Entry;
output() << '\n';
}
for (const auto &[Key, Value] : MergedProfile.Branch) {
output() << Key << " ";
if (!NoLBRCollection.value_or(false))