aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineOutliner.cpp
diff options
context:
space:
mode:
authorXuan Zhang <144393379+xuanzh-meta@users.noreply.github.com>2024-06-07 09:50:13 -0400
committerGitHub <noreply@github.com>2024-06-07 06:50:13 -0700
commit3b16630c26505060a876f578e4b2ba701c780e9a (patch)
treece66ddefb69a4aca074a635c0547aeb65a4b6953 /llvm/lib/CodeGen/MachineOutliner.cpp
parent2afea7296812b7e12c6ec683e6858bd4cbe8dd8d (diff)
downloadllvm-3b16630c26505060a876f578e4b2ba701c780e9a.zip
llvm-3b16630c26505060a876f578e4b2ba701c780e9a.tar.gz
llvm-3b16630c26505060a876f578e4b2ba701c780e9a.tar.bz2
[MachineOutliner] Sort by Benefit to Cost Ratio (#90264)
This PR depends on https://github.com/llvm/llvm-project/pull/90260 We changed the order in which functions are outlined in Machine Outliner. The formula for priority is found via a black-box Bayesian optimization toolbox. Using this formula for sorting consistently reduces the uncompressed size of large real-world mobile apps. We also ran a few benchmarks using LLVM test suites, and showed that sorting by priority consistently reduces the text segment size. |run (CTMark/)   |baseline (1)|priority (2)|diff (1 -> 2)| |----------------|------------|------------|-------------| |lencod          |349624      |349264      |-0.1030%     | |SPASS           |219672      |219480      |-0.0874%     | |kc              |271956      |251200      |-7.6321%     | |sqlite3         |223920      |223708      |-0.0947%     | |7zip-benchmark  |405364      |402624      |-0.6759%     | |bullet          |139820      |139500      |-0.2289%     | |consumer-typeset|295684      |290196      |-1.8560%     | |pairlocalalign  |72236       |72092       |-0.1993%     | |tramp3d-v4      |189572      |189292      |-0.1477%     | This is part of an enhanced version of machine outliner -- see [RFC](https://discourse.llvm.org/t/rfc-enhanced-machine-outliner-part-1-fulllto-part-2-thinlto-nolto-to-come/78732).
Diffstat (limited to 'llvm/lib/CodeGen/MachineOutliner.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineOutliner.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp
index 626e577..9e2e631 100644
--- a/llvm/lib/CodeGen/MachineOutliner.cpp
+++ b/llvm/lib/CodeGen/MachineOutliner.cpp
@@ -828,10 +828,12 @@ bool MachineOutliner::outline(Module &M,
<< "\n");
bool OutlinedSomething = false;
- // Sort by benefit. The most beneficial functions should be outlined first.
+ // Sort by priority where priority := getNotOutlinedCost / getOutliningCost.
+ // The function with highest priority should be outlined first.
stable_sort(FunctionList,
[](const OutlinedFunction &LHS, const OutlinedFunction &RHS) {
- return LHS.getBenefit() > RHS.getBenefit();
+ return LHS.getNotOutlinedCost() * RHS.getOutliningCost() >
+ RHS.getNotOutlinedCost() * LHS.getOutliningCost();
});
// Walk over each function, outlining them as we go along. Functions are