[llvm] [BOLT] Merge DataReader::parse and parseInNoLBRMode (PR #203469)
Amir Ayupov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 11 23:52:41 PDT 2026
https://github.com/aaupov created https://github.com/llvm/llvm-project/pull/203469
None
>From bf5ac0960d1a433369e016c418d27be048d7043f Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Thu, 11 Jun 2026 23:52:28 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.8-beta.1
---
bolt/include/bolt/Profile/DataReader.h | 7 +-
bolt/lib/Profile/DataReader.cpp | 99 +++++++++-----------------
2 files changed, 38 insertions(+), 68 deletions(-)
diff --git a/bolt/include/bolt/Profile/DataReader.h b/bolt/include/bolt/Profile/DataReader.h
index d5fc1ef38d6a4..53c7a75deb116 100644
--- a/bolt/include/bolt/Profile/DataReader.h
+++ b/bolt/include/bolt/Profile/DataReader.h
@@ -329,8 +329,8 @@ class DataReader : public ProfileReaderBase {
/// offset d. The rest 773 branches were preceded by a different sequence
/// of branches, from func, offset 18 to offset 60 and then from offset 71 to
/// offset d.
- std::error_code parse();
-
+ ///
+ /// No LBR mode:
/// When no_lbr is the first line of the file, activate No LBR mode. In this
/// mode we read the addresses where samples were recorded directly instead of
/// LBR entries. The line format is almost the same, except for a missing <to>
@@ -345,8 +345,7 @@ class DataReader : public ProfileReaderBase {
/// no_lbr # First line of fdata file
/// 1 BZ2_compressBlock 466c 3
/// 1 BZ2_hbMakeCodeLengths 29c 1
- ///
- std::error_code parseInNoLBRMode();
+ std::error_code parse();
/// Return branch data matching one of the names in \p FuncNames.
FuncBranchData *
diff --git a/bolt/lib/Profile/DataReader.cpp b/bolt/lib/Profile/DataReader.cpp
index 55f4a35b780fd..5cf331da5fd3c 100644
--- a/bolt/lib/Profile/DataReader.cpp
+++ b/bolt/lib/Profile/DataReader.cpp
@@ -1090,56 +1090,12 @@ bool DataReader::hasMemData() {
return false;
}
-std::error_code DataReader::parseInNoLBRMode() {
- auto GetOrCreateFuncEntry = [&](StringRef Name) {
+std::error_code DataReader::parse() {
+ auto GetOrCreateFuncBasicEntry = [&](StringRef Name) {
return NamesToBasicSamples.try_emplace(Name, Name).first;
};
- auto GetOrCreateFuncMemEntry = [&](StringRef Name) {
- return NamesToMemEvents.try_emplace(Name, Name).first;
- };
-
- while (hasBranchData()) {
- ErrorOr<BasicSampleInfo> Res = parseSampleInfo();
- if (std::error_code EC = Res.getError())
- return EC;
-
- BasicSampleInfo SI = Res.get();
-
- // Ignore samples not involving known locations
- if (!SI.Loc.IsSymbol)
- continue;
-
- auto I = GetOrCreateFuncEntry(SI.Loc.Name);
- I->second.Data.emplace_back(std::move(SI));
- }
-
- while (hasMemData()) {
- ErrorOr<MemInfo> Res = parseMemInfo();
- if (std::error_code EC = Res.getError())
- return EC;
-
- MemInfo MI = Res.get();
-
- // Ignore memory events not involving known pc.
- if (!MI.Offset.IsSymbol)
- continue;
-
- auto I = GetOrCreateFuncMemEntry(MI.Offset.Name);
- I->second.Data.emplace_back(std::move(MI));
- }
-
- for (auto &FuncBasicSamples : NamesToBasicSamples)
- llvm::stable_sort(FuncBasicSamples.second.Data);
-
- for (auto &MemEvents : NamesToMemEvents)
- llvm::stable_sort(MemEvents.second.Data);
-
- return std::error_code();
-}
-
-std::error_code DataReader::parse() {
- auto GetOrCreateFuncEntry = [&](StringRef Name) {
+ auto GetOrCreateFuncBranchEntry = [&](StringRef Name) {
return NamesToBranches.try_emplace(Name, Name).first;
};
@@ -1164,28 +1120,40 @@ std::error_code DataReader::parse() {
return make_error_code(llvm::errc::io_error);
}
- if (NoLBRMode)
- return parseInNoLBRMode();
-
while (hasBranchData()) {
- ErrorOr<BranchInfo> Res = parseBranchInfo();
- if (std::error_code EC = Res.getError())
- return EC;
+ if (NoLBRMode) {
+ ErrorOr<BasicSampleInfo> Res = parseSampleInfo();
+ if (std::error_code EC = Res.getError())
+ return EC;
- BranchInfo BI = Res.get();
+ BasicSampleInfo SI = Res.get();
- // Ignore branches not involving known location.
- if (!BI.From.IsSymbol && !BI.To.IsSymbol)
- continue;
+ // Ignore samples not involving known locations
+ if (!SI.Loc.IsSymbol)
+ continue;
- auto I = GetOrCreateFuncEntry(BI.From.Name);
- I->second.Data.emplace_back(std::move(BI));
+ auto I = GetOrCreateFuncBasicEntry(SI.Loc.Name);
+ I->second.Data.emplace_back(std::move(SI));
+ } else {
+ ErrorOr<BranchInfo> Res = parseBranchInfo();
+ if (std::error_code EC = Res.getError())
+ return EC;
+
+ BranchInfo BI = Res.get();
- // Add entry data for branches to another function or branches
- // to entry points (including recursive calls)
- if (BI.To.IsSymbol && (BI.From.Name != BI.To.Name || BI.To.Offset == 0)) {
- I = GetOrCreateFuncEntry(BI.To.Name);
- I->second.EntryData.emplace_back(std::move(BI));
+ // Ignore branches not involving known location.
+ if (!BI.From.IsSymbol && !BI.To.IsSymbol)
+ continue;
+
+ auto I = GetOrCreateFuncBranchEntry(BI.From.Name);
+ I->second.Data.emplace_back(std::move(BI));
+
+ // Add entry data for branches to another function or branches
+ // to entry points (including recursive calls)
+ if (BI.To.IsSymbol && (BI.From.Name != BI.To.Name || BI.To.Offset == 0)) {
+ I = GetOrCreateFuncBranchEntry(BI.To.Name);
+ I->second.EntryData.emplace_back(std::move(BI));
+ }
}
}
@@ -1204,6 +1172,9 @@ std::error_code DataReader::parse() {
I->second.Data.emplace_back(std::move(MI));
}
+ for (auto &FuncBasicSamples : NamesToBasicSamples)
+ llvm::stable_sort(FuncBasicSamples.second.Data);
+
for (auto &FuncBranches : NamesToBranches)
llvm::stable_sort(FuncBranches.second.Data);
More information about the llvm-commits
mailing list