From 95a66b5b3ad34b47703131207bbab739366408c4 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 8 Apr 2020 09:47:26 -0700 Subject: Run reorder-locals more in wasm2js (#2729) coalesce-locals is nonlinear in the number of locals, so it is greatly beneficial to reorder the locals (which then drops the unused ones at the end automatically). The default passes do this already, but wasm2js does some custom work, and this was missing. With this change that pass takes 10x less time on poppler with --flatten --flatten --simplify-locals-notee-nostructure which approximates what wasm2js does. --- src/passes/CoalesceLocals.cpp | 5 +++++ src/wasm2js.h | 1 + 2 files changed, 6 insertions(+) (limited to 'src') diff --git a/src/passes/CoalesceLocals.cpp b/src/passes/CoalesceLocals.cpp index 232685001..e5416971b 100644 --- a/src/passes/CoalesceLocals.cpp +++ b/src/passes/CoalesceLocals.cpp @@ -19,6 +19,11 @@ // is similar to register allocation, however, there is never any // spilling, and there isn't a fixed number of locals. // +// NB: This pass is nonlinear in the number of locals. It is best to run it +// after the number of locals has been somewhat reduced by other passes, +// for example by simplify-locals (to remove unneeded uses of locals) and +// reorder-locals (to sort them by # of uses and remove all unneeded ones). +// #include #include diff --git a/src/wasm2js.h b/src/wasm2js.h index cc2cfa128..1fe5db0c1 100644 --- a/src/wasm2js.h +++ b/src/wasm2js.h @@ -326,6 +326,7 @@ Ref Wasm2JSBuilder::processWasm(Module* wasm, Name funcName) { if (options.optimizeLevel > 0) { runner.add("remove-unused-names"); runner.add("merge-blocks"); + runner.add("reorder-locals"); runner.add("coalesce-locals"); } runner.add("reorder-locals"); -- cgit v1.2.3