aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/CGData/StableFunctionMapTest.cpp
diff options
context:
space:
mode:
authorKyungwoo Lee <kyulee@meta.com>2024-11-13 17:34:07 -0800
committerGitHub <noreply@github.com>2024-11-13 17:34:07 -0800
commitd23c5c2d6566fce4380cfa31d438422db19fbce9 (patch)
treea50fe5074a1f87cfb437051b7627093f8a1d7139 /llvm/unittests/CGData/StableFunctionMapTest.cpp
parent6e614e11df6a152082b51a1b18332cb8730a4032 (diff)
downloadllvm-d23c5c2d6566fce4380cfa31d438422db19fbce9.zip
llvm-d23c5c2d6566fce4380cfa31d438422db19fbce9.tar.gz
llvm-d23c5c2d6566fce4380cfa31d438422db19fbce9.tar.bz2
[CGData] Global Merge Functions (#112671)
This implements a global function merging pass. Unlike traditional function merging passes that use IR comparators, this pass employs a structurally stable hash to identify similar functions while ignoring certain constant operands. These ignored constants are tracked and encoded into a stable function summary. When merging, instead of explicitly folding similar functions and their call sites, we form a merging instance by supplying different parameters via thunks. The actual size reduction occurs when identically created merging instances are folded by the linker. Currently, this pass is wired to a pre-codegen pass, enabled by the `-enable-global-merge-func` flag. In a local merging mode, the analysis and merging steps occur sequentially within a module: - `analyze`: Collects stable function hashes and tracks locations of ignored constant operands. - `finalize`: Identifies merge candidates with matching hashes and computes the set of parameters that point to different constants. - `merge`: Uses the stable function map to optimistically create a merged function. We can enable a global merging mode similar to the global function outliner (https://discourse.llvm.org/t/rfc-enhanced-machine-outliner-part-2-thinlto-nolto/78753/), which will perform the above steps separately. - `-codegen-data-generate`: During the first round of code generation, we analyze local merging instances and publish their summaries. - Offline using `llvm-cgdata` or at link-time, we can finalize all these merging summaries that are combined to determine parameters. - `-codegen-data-use`: During the second round of code generation, we optimistically create merging instances within each module, and finally, the linker folds identically created merging instances. Depends on #112664 This is a patch for https://discourse.llvm.org/t/rfc-global-function-merging/82608.
Diffstat (limited to 'llvm/unittests/CGData/StableFunctionMapTest.cpp')
-rw-r--r--llvm/unittests/CGData/StableFunctionMapTest.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/llvm/unittests/CGData/StableFunctionMapTest.cpp b/llvm/unittests/CGData/StableFunctionMapTest.cpp
index 5e178dc..d551ac8 100644
--- a/llvm/unittests/CGData/StableFunctionMapTest.cpp
+++ b/llvm/unittests/CGData/StableFunctionMapTest.cpp
@@ -108,8 +108,8 @@ TEST(StableFunctionMap, Finalize2) {
TEST(StableFunctionMap, Finalize3) {
StableFunctionMap Map;
- StableFunction Func1{1, "Func1", "Mod1", 2, {{{0, 1}, 3}, {{1, 1}, 1}}};
- StableFunction Func2{1, "Func2", "Mod2", 2, {{{0, 1}, 2}, {{1, 1}, 1}}};
+ StableFunction Func1{1, "Func1", "Mod1", 12, {{{0, 1}, 3}, {{1, 1}, 1}}};
+ StableFunction Func2{1, "Func2", "Mod2", 12, {{{0, 1}, 2}, {{1, 1}, 1}}};
Map.insert(Func1);
Map.insert(Func2);