|
1 | 1 | Auto generated patch. Do not edit or delete it, even if empty.
|
2 |
| -diff -ruN --strip-trailing-cr a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel |
3 |
| ---- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel |
4 |
| -+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel |
5 |
| -@@ -3652,6 +3652,7 @@ |
6 |
| - ":__support_macros_optimization", |
7 |
| - ":llvm_libc_types_size_t", |
8 |
| - ":string_memory_utils", |
9 |
| -+ ":types_size_t", |
10 |
| - ], |
11 |
| - ) |
| 2 | +diff -ruN --strip-trailing-cr a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp |
| 3 | +--- a/llvm/lib/CodeGen/GlobalMerge.cpp |
| 4 | ++++ b/llvm/lib/CodeGen/GlobalMerge.cpp |
| 5 | +@@ -423,12 +423,24 @@ |
| 6 | + } |
| 7 | + } |
12 | 8 |
|
| 9 | ++ // Now we found a bunch of sets of globals used together. We accumulated |
| 10 | ++ // the number of times we encountered the sets (i.e., the number of functions |
| 11 | ++ // that use that exact set of globals). |
| 12 | ++ // |
| 13 | ++ // Multiply that by the size of the set to give us a crude profitability |
| 14 | ++ // metric. |
| 15 | ++ llvm::stable_sort(UsedGlobalSets, |
| 16 | ++ [](const UsedGlobalSet &UGS1, const UsedGlobalSet &UGS2) { |
| 17 | ++ return UGS1.Globals.count() * UGS1.UsageCount < |
| 18 | ++ UGS2.Globals.count() * UGS2.UsageCount; |
| 19 | ++ }); |
| 20 | ++ |
| 21 | + // We can choose to merge all globals together, but ignore globals never used |
| 22 | + // with another global. This catches the obviously non-profitable cases of |
| 23 | + // having a single global, but is aggressive enough for any other case. |
| 24 | + if (GlobalMergeIgnoreSingleUse) { |
| 25 | + BitVector AllGlobals(Globals.size()); |
| 26 | +- for (const UsedGlobalSet &UGS : UsedGlobalSets) { |
| 27 | ++ for (const UsedGlobalSet &UGS : llvm::reverse(UsedGlobalSets)) { |
| 28 | + if (UGS.UsageCount == 0) |
| 29 | + continue; |
| 30 | + if (UGS.Globals.count() > 1) |
| 31 | +@@ -437,16 +449,6 @@ |
| 32 | + return doMerge(Globals, AllGlobals, M, isConst, AddrSpace); |
| 33 | + } |
| 34 | + |
| 35 | +- // Now we found a bunch of sets of globals used together. We accumulated |
| 36 | +- // the number of times we encountered the sets (i.e., the number of functions |
| 37 | +- // that use that exact set of globals). Multiply that by the size of the set |
| 38 | +- // to give us a crude profitability metric. |
| 39 | +- llvm::stable_sort(UsedGlobalSets, |
| 40 | +- [](const UsedGlobalSet &UGS1, const UsedGlobalSet &UGS2) { |
| 41 | +- return UGS1.Globals.count() * UGS1.UsageCount >= |
| 42 | +- UGS2.Globals.count() * UGS2.UsageCount; |
| 43 | +- }); |
| 44 | +- |
| 45 | + // Starting from the sets with the best (=biggest) profitability, find a |
| 46 | + // good combination. |
| 47 | + // The ideal (and expensive) solution can only be found by trying all |
| 48 | +@@ -456,7 +458,7 @@ |
| 49 | + BitVector PickedGlobals(Globals.size()); |
| 50 | + bool Changed = false; |
| 51 | + |
| 52 | +- for (const UsedGlobalSet &UGS : UsedGlobalSets) { |
| 53 | ++ for (const UsedGlobalSet &UGS : llvm::reverse(UsedGlobalSets)) { |
| 54 | + if (UGS.UsageCount == 0) |
| 55 | + continue; |
| 56 | + if (PickedGlobals.anyCommon(UGS.Globals)) |
0 commit comments