From 25e5aa67bd16f277ad32d42bfbbf7cd130ddf028 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 1 Nov 2022 17:12:29 -0700 Subject: 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. --- src/passes/pass.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/passes/pass.cpp') 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 -- cgit v1.2.3