aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/GlobalMerge.cpp
diff options
context:
space:
mode:
authorMichael Maitland <michaeltmaitland@gmail.com>2025-01-27 07:28:47 -0800
committerMichael Maitland <michaeltmaitland@gmail.com>2025-01-27 07:28:47 -0800
commit559287575b5b747cfc01652adb647ee5516aa626 (patch)
treeac9d98faeb48649983ad38011cd804cb5d150706 /llvm/lib/CodeGen/GlobalMerge.cpp
parent212f344b84b400c0a9dedfa3c1ec6af9d9d30223 (diff)
downloadllvm-559287575b5b747cfc01652adb647ee5516aa626.zip
llvm-559287575b5b747cfc01652adb647ee5516aa626.tar.gz
llvm-559287575b5b747cfc01652adb647ee5516aa626.tar.bz2
[GlobalMerge][NFC] Reland "Skip sorting by profitability when it is not needed"
Relands #124146 but without changes to the sorting algorithm and the following reverse.
Diffstat (limited to 'llvm/lib/CodeGen/GlobalMerge.cpp')
-rw-r--r--llvm/lib/CodeGen/GlobalMerge.cpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp
index 7b76155..4debdea 100644
--- a/llvm/lib/CodeGen/GlobalMerge.cpp
+++ b/llvm/lib/CodeGen/GlobalMerge.cpp
@@ -423,24 +423,12 @@ bool GlobalMergeImpl::doMerge(SmallVectorImpl<GlobalVariable *> &Globals,
}
}
- // Now we found a bunch of sets of globals used together. We accumulated
- // the number of times we encountered the sets (i.e., the number of functions
- // that use that exact set of globals).
- //
- // Multiply that by the size of the set to give us a crude profitability
- // metric.
- llvm::stable_sort(UsedGlobalSets,
- [](const UsedGlobalSet &UGS1, const UsedGlobalSet &UGS2) {
- return UGS1.Globals.count() * UGS1.UsageCount <
- UGS2.Globals.count() * UGS2.UsageCount;
- });
-
// We can choose to merge all globals together, but ignore globals never used
// with another global. This catches the obviously non-profitable cases of
// having a single global, but is aggressive enough for any other case.
if (GlobalMergeIgnoreSingleUse) {
BitVector AllGlobals(Globals.size());
- for (const UsedGlobalSet &UGS : llvm::reverse(UsedGlobalSets)) {
+ for (const UsedGlobalSet &UGS : UsedGlobalSets) {
if (UGS.UsageCount == 0)
continue;
if (UGS.Globals.count() > 1)
@@ -449,6 +437,18 @@ bool GlobalMergeImpl::doMerge(SmallVectorImpl<GlobalVariable *> &Globals,
return doMerge(Globals, AllGlobals, M, isConst, AddrSpace);
}
+ // Now we found a bunch of sets of globals used together. We accumulated
+ // the number of times we encountered the sets (i.e., the number of functions
+ // that use that exact set of globals).
+ //
+ // Multiply that by the size of the set to give us a crude profitability
+ // metric.
+ llvm::stable_sort(UsedGlobalSets,
+ [](const UsedGlobalSet &UGS1, const UsedGlobalSet &UGS2) {
+ return UGS1.Globals.count() * UGS1.UsageCount <
+ UGS2.Globals.count() * UGS2.UsageCount;
+ });
+
// Starting from the sets with the best (=biggest) profitability, find a
// good combination.
// The ideal (and expensive) solution can only be found by trying all