[llvm-branch-commits] [llvm] [BOLT] Add profile density computation (PR #101094)
Amir Ayupov via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Aug 12 14:46:32 PDT 2024
https://github.com/aaupov updated https://github.com/llvm/llvm-project/pull/101094
>From f598510001859a29f6f1ff6362fb9950ab6340cd Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Mon, 29 Jul 2024 16:14:08 -0700
Subject: [PATCH 1/4] Update test to check the option with llvm-bolt with
fdata, YAML, and pre-aggregated profile
Created using spr 1.3.4
---
bolt/test/X86/pre-aggregated-perf.test | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/bolt/test/X86/pre-aggregated-perf.test b/bolt/test/X86/pre-aggregated-perf.test
index fc6f332d53dfb8..0f5137309e85d1 100644
--- a/bolt/test/X86/pre-aggregated-perf.test
+++ b/bolt/test/X86/pre-aggregated-perf.test
@@ -15,9 +15,15 @@ RUN: --show-density --profile-density-threshold=9 \
RUN: --profile-density-cutoff-hot=970000 \
RUN: --profile-use-dfs | FileCheck %s
-RUN: llvm-bolt %t.exe -data %t -o %t.null | FileCheck %s
-RUN: llvm-bolt %t.exe -data %t.new -o %t.null | FileCheck %s
-RUN: llvm-bolt %t.exe -p %p/Inputs/pre-aggregated.txt --pa -o %t.null | FileCheck %s
+RUN: llvm-bolt %t.exe -data %t -o %t.null \
+RUN: --show-density --profile-density-threshold=9 \
+RUN: --profile-density-cutoff-hot=970000 | FileCheck %s
+RUN: llvm-bolt %t.exe -data %t.new -o %t.null \
+RUN: --show-density --profile-density-threshold=9 \
+RUN: --profile-density-cutoff-hot=970000 | FileCheck %s
+RUN: llvm-bolt %t.exe -p %p/Inputs/pre-aggregated.txt --pa -o %t.null \
+RUN: --show-density --profile-density-threshold=9 \
+RUN: --profile-density-cutoff-hot=970000 | FileCheck %s
CHECK: BOLT-INFO: 4 out of 7 functions in the binary (57.1%) have non-empty execution profile
CHECK: BOLT-INFO: Functions with density >= 9.4 account for 97.00% total sample counts.
>From e91907e57b39c8c79eb58b4d28d78fa253b130cb Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Mon, 29 Jul 2024 20:09:08 -0700
Subject: [PATCH 2/4] show-density init(true)
Created using spr 1.3.4
---
bolt/lib/Passes/BinaryPasses.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bolt/lib/Passes/BinaryPasses.cpp b/bolt/lib/Passes/BinaryPasses.cpp
index 23009bf74e0773..83fd6b2562eca8 100644
--- a/bolt/lib/Passes/BinaryPasses.cpp
+++ b/bolt/lib/Passes/BinaryPasses.cpp
@@ -224,7 +224,7 @@ static cl::opt<unsigned> TopCalledLimit(
cl::init(100), cl::Hidden, cl::cat(BoltCategory));
// Profile density options, synced with llvm-profgen/ProfileGenerator.cpp
-static cl::opt<bool> ShowDensity("show-density", cl::init(false),
+static cl::opt<bool> ShowDensity("show-density", cl::init(true),
cl::desc("show profile density details"),
cl::Optional);
>From 0d5291b01264a5387f8afd9fb69baf55fdc409a7 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Fri, 9 Aug 2024 11:17:57 -0700
Subject: [PATCH 3/4] show-density off by default
Created using spr 1.3.4
---
bolt/lib/Passes/BinaryPasses.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bolt/lib/Passes/BinaryPasses.cpp b/bolt/lib/Passes/BinaryPasses.cpp
index e0ad2af63a384a..0dc4a37e0ba946 100644
--- a/bolt/lib/Passes/BinaryPasses.cpp
+++ b/bolt/lib/Passes/BinaryPasses.cpp
@@ -224,7 +224,7 @@ static cl::opt<unsigned> TopCalledLimit(
cl::init(100), cl::Hidden, cl::cat(BoltCategory));
// Profile density options, synced with llvm-profgen/ProfileGenerator.cpp
-static cl::opt<bool> ShowDensity("show-density", cl::init(true),
+static cl::opt<bool> ShowDensity("show-density", cl::init(false),
cl::desc("show profile density details"),
cl::Optional);
>From f20e9618d0ab9602ebde9ec518ae194fbc323382 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Mon, 12 Aug 2024 14:46:21 -0700
Subject: [PATCH 4/4] s/ExecutedBytes/SampleCountInBytes
Created using spr 1.3.4
---
bolt/include/bolt/Core/BinaryFunction.h | 4 ++--
bolt/lib/Passes/BinaryPasses.cpp | 4 ++--
bolt/lib/Profile/DataAggregator.cpp | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h
index 73d0d48c907e38..54ee4748b54c22 100644
--- a/bolt/include/bolt/Core/BinaryFunction.h
+++ b/bolt/include/bolt/Core/BinaryFunction.h
@@ -388,7 +388,7 @@ class BinaryFunction {
uint64_t RawBranchCount{0};
/// Dynamically executed function bytes, used for density computation.
- uint64_t ExecutedBytes{0};
+ uint64_t SampleCountInBytes{0};
/// Indicates the type of profile the function is using.
uint16_t ProfileFlags{PF_NONE};
@@ -1847,7 +1847,7 @@ class BinaryFunction {
void setRawBranchCount(uint64_t Count) { RawBranchCount = Count; }
/// Return the number of dynamically executed bytes, from raw perf data.
- uint64_t getExecutedBytes() const { return ExecutedBytes; }
+ uint64_t getSampleCountInBytes() const { return SampleCountInBytes; }
/// Return the execution count for functions with known profile.
/// Return 0 if the function has no profile.
diff --git a/bolt/lib/Passes/BinaryPasses.cpp b/bolt/lib/Passes/BinaryPasses.cpp
index 0dc4a37e0ba946..a9935f02862f87 100644
--- a/bolt/lib/Passes/BinaryPasses.cpp
+++ b/bolt/lib/Passes/BinaryPasses.cpp
@@ -1467,10 +1467,10 @@ Error PrintProgramStats::runOnFunctions(BinaryContext &BC) {
if (IsHotParentOfBOLTSplitFunction)
for (const BinaryFunction *Fragment : Function.getFragments())
Size += Fragment->getSize();
- double Density = (double)1.0 * Function.getExecutedBytes() / Size;
+ double Density = (double)1.0 * Function.getSampleCountInBytes() / Size;
FuncDensityList.emplace_back(Density, SampleCount);
LLVM_DEBUG(BC.outs() << Function << ": executed bytes "
- << Function.getExecutedBytes() << ", size (b) "
+ << Function.getSampleCountInBytes() << ", size (b) "
<< Size << ", density " << Density
<< ", sample count " << SampleCount << '\n');
}
diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp
index c26705e49774c0..a9c55c98f54a92 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -853,7 +853,7 @@ bool DataAggregator::doTrace(const LBREntry &First, const LBREntry &Second,
BinaryFunction *ParentFunc = getBATParentFunction(*FromFunc);
if (!ParentFunc)
ParentFunc = FromFunc;
- ParentFunc->ExecutedBytes += Count * (Second.From - First.To);
+ ParentFunc->SampleCountInBytes += Count * (Second.From - First.To);
std::optional<BoltAddressTranslation::FallthroughListTy> FTs =
BAT ? BAT->getFallthroughsInTrace(FromFunc->getAddress(), First.To,
More information about the llvm-branch-commits
mailing list