diff options
author | Alon Zakai <azakai@google.com> | 2022-11-01 17:12:29 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-02 00:12:29 +0000 |
commit | 25e5aa67bd16f277ad32d42bfbbf7cd130ddf028 (patch) | |
tree | 6156f359bfc057a6e36b38ba7512d2ba317c98a3 /src/passes/pass.cpp | |
parent | a030cc7f69a00dc0e699b8b580224126650c738b (diff) | |
download | binaryen-25e5aa67bd16f277ad32d42bfbbf7cd130ddf028.tar.gz binaryen-25e5aa67bd16f277ad32d42bfbbf7cd130ddf028.tar.bz2 binaryen-25e5aa67bd16f277ad32d42bfbbf7cd130ddf028.zip |
ReorderGlobals pass (#4904)
This sorts globals by their usage (and respecting dependencies). If the module
has very many globals then using smaller LEBs can matter.
If there are fewer than 128 globals then we cannot reduce size, and the pass
exits early (so this pass will not slow down MVP builds, which usually have just
1 global, the stack pointer). But with wasm GC it is common to use globals for
vtables etc., and often there is a very large number of them.
Diffstat (limited to 'src/passes/pass.cpp')
-rw-r--r-- | src/passes/pass.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index c6d94ddf7..7190201a1 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -359,6 +359,12 @@ void PassRegistry::registerPasses() { registerPass("reorder-functions", "sorts functions by access frequency", createReorderFunctionsPass); + registerPass("reorder-globals", + "sorts globals by access frequency", + createReorderGlobalsPass); + registerTestPass("reorder-globals-always", + "sorts globals by access frequency (even if there are few)", + createReorderGlobalsAlwaysPass); registerPass("reorder-locals", "sorts locals by access frequency", createReorderLocalsPass); @@ -621,6 +627,9 @@ void PassRunner::addDefaultGlobalOptimizationPostPasses() { addIfNoDWARFIssues("simplify-globals"); } addIfNoDWARFIssues("remove-unused-module-elements"); + if (options.optimizeLevel >= 2 || options.shrinkLevel >= 1) { + addIfNoDWARFIssues("reorder-globals"); + } // may allow more inlining/dae/etc., need --converge for that addIfNoDWARFIssues("directize"); // perform Stack IR optimizations here, at the very end of the |