!56 [ AArch64] Add hybrid guess approach for edge weight estimation

From: @mwl2000 
Reviewed-by: @li-yancheng 
Signed-off-by: @li-yancheng
This commit is contained in:
openeuler-ci-bot 2024-11-18 11:40:09 +00:00 committed by Gitee
commit 7c1fdeb40f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 82 additions and 1 deletions

View File

@ -0,0 +1,74 @@
From 43aa1ec5b46baf032cf2fee22d765a195d40cf59 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=89=9F=E6=96=87=E9=BE=99?= <muwl182@163.com>
Date: Mon, 18 Nov 2024 02:13:25 +0000
Subject: [PATCH] [AArch64] Add hybrid guess approach for edge weight
estimation
---
bolt/lib/Passes/MCF.cpp | 33 +++++++++++++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
diff --git a/bolt/lib/Passes/MCF.cpp b/bolt/lib/Passes/MCF.cpp
index c3898d2dc..a6455bbeb 100644
--- a/bolt/lib/Passes/MCF.cpp
+++ b/bolt/lib/Passes/MCF.cpp
@@ -36,6 +36,11 @@ static cl::opt<bool> IterativeGuess(
cl::desc("in non-LBR mode, guess edge counts using iterative technique"),
cl::Hidden, cl::cat(BoltOptCategory));
+static cl::opt<bool> HybridGuess(
+ "hybrid-guess",
+ cl::desc("in non-LBR mode, guess edge counts using hybird estimation technique"),
+ cl::Hidden, cl::cat(BoltOptCategory));
+
static cl::opt<bool> UseRArcs(
"mcf-use-rarcs",
cl::desc("in MCF, consider the possibility of cancelling flow to balance "
@@ -350,6 +355,27 @@ void guessEdgeByIterativeApproach(BinaryFunction &BF) {
}
}
+void guessEdgeByHybridApproach(BinaryFunction &BF,
+ EdgeWeightMap &PredEdgeWeights,
+ EdgeWeightMap &SuccEdgeWeights) {
+ for (BinaryBasicBlock &BB : BF) {
+ for (BinaryBasicBlock *Pred : BB.predecessors()) {
+ double RelativeExecSucc = SuccEdgeWeights[std::make_pair(Pred, &BB)];
+ double RelativeExec = PredEdgeWeights[std::make_pair(Pred, &BB)];
+ RelativeExec *= BB.getExecutionCount();
+ RelativeExecSucc *= Pred->getExecutionCount();
+ BinaryBasicBlock::BinaryBranchInfo &BI = Pred->getBranchInfo(BB);
+ if ((static_cast<uint64_t>(RelativeExec) != 0) && (static_cast<uint64_t>(RelativeExecSucc) != 0)) {
+ BI.Count = (static_cast<uint64_t>(RelativeExec) + RelativeExecSucc) / 2;
+ } else if (static_cast<uint64_t>(RelativeExec) != 0) {
+ BI.Count = static_cast<uint64_t>(RelativeExec);
+ } else if (static_cast<uint64_t>(RelativeExecSucc) != 0) {
+ BI.Count = static_cast<uint64_t>(RelativeExecSucc);
+ }
+ }
+ }
+}
+
/// Associate each basic block with the BinaryLoop object corresponding to the
/// innermost loop containing this block.
DenseMap<const BinaryBasicBlock *, const BinaryLoop *>
@@ -454,11 +480,14 @@ void estimateEdgeCounts(BinaryFunction &BF) {
equalizeBBCounts(Info, BF);
LLVM_DEBUG(BF.print(dbgs(), "after equalize BB counts"));
}
- if (opts::IterativeGuess)
+ if (opts::IterativeGuess) {
guessEdgeByIterativeApproach(BF);
- else
+ } else if (opts::HybridGuess) {
+ guessEdgeByHybridApproach(BF, PredEdgeWeights, SuccEdgeWeights);
+ } else {
guessEdgeByRelHotness(BF, /*UseSuccs=*/false, PredEdgeWeights,
SuccEdgeWeights);
+ }
recalculateBBCounts(BF, /*AllEdges=*/false);
}
--
2.25.1

View File

@ -22,7 +22,7 @@
Name: %{pkg_name}
Version: %{bolt_version}
Release: 10
Release: 11
Summary: BOLT is a post-link optimizer developed to speed up large applications
License: Apache 2.0
URL: https://github.com/llvm/llvm-project/tree/main/bolt
@ -39,6 +39,7 @@ Patch6: 0006-AArch64-Add-CFG-block-count-correction-optimization.patch
Patch7: 0007-BOLT-Skip-PLT-search-for-zero-value-weak-reference-symbols.patch
Patch8: 0008-merge-fdata-Support-process-no_lbr-profile-file.patch
Patch9: 0009-support-aarch64-instrumentation.patch
Patch10: 0010-AArch64-Add-hybrid-guess-approach-for-edge-weight-estimation.patch
BuildRequires: gcc
BuildRequires: gcc-c++
@ -154,6 +155,12 @@ rm -f %{buildroot}/%{_builddir}/%{bolt_srcdir}/%{_vpath_builddir}/%{_lib}/lib*.a
%doc %{install_docdir}
%changelog
* Mon Nov 18 2024 mwl2000 <muwl182@163.com> 17.0.6-11
- Type:Feature
- ID:NA
- SUG:NA
- DESC: Add hybrid guess approach for edge weight estimation.
* Thu Oct 31 2024 rfwang07 <wangrufeng5@huawei.com> 17.0.6-10
- Type:Backport
- ID:NA