llvm-bolt/0010-AArch64-Add-hybrid-guess-approach-for-edge-weight-estimation.patch

75 lines
2.9 KiB
Diff
Raw Permalink Normal View History

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