summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-04-08 09:47:26 -0700
committerGitHub <noreply@github.com>2020-04-08 09:47:26 -0700
commit95a66b5b3ad34b47703131207bbab739366408c4 (patch)
treeadf907929e9a5dd6831e28e63115332d553543c7
parent0a44e995d9b09812260ca46add0f823820d4cc31 (diff)
downloadbinaryen-95a66b5b3ad34b47703131207bbab739366408c4.tar.gz
binaryen-95a66b5b3ad34b47703131207bbab739366408c4.tar.bz2
binaryen-95a66b5b3ad34b47703131207bbab739366408c4.zip
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.
-rw-r--r--src/passes/CoalesceLocals.cpp5
-rw-r--r--src/wasm2js.h1
2 files changed, 6 insertions, 0 deletions
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 <algorithm>
#include <memory>
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");