summaryrefslogtreecommitdiff
path: root/src/wasm2js.h
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2019-05-10 10:23:58 -0700
committerGitHub <noreply@github.com>2019-05-10 10:23:58 -0700
commitd216f8742ba0663fffb035c577a5449bbc8a33a2 (patch)
treed01bc76ad836d0874e22f27fde6df8aff4ff06d8 /src/wasm2js.h
parentbdfdbfbbac4a0f47d8b789167697d6dd70a39720 (diff)
downloadbinaryen-d216f8742ba0663fffb035c577a5449bbc8a33a2.tar.gz
binaryen-d216f8742ba0663fffb035c577a5449bbc8a33a2.tar.bz2
binaryen-d216f8742ba0663fffb035c577a5449bbc8a33a2.zip
wasm2js: avoid reinterprets (#2094)
In JS a reinterpret is especially expensive, as we implement it as a write to a temp buffer and a read using another view. This finds places where we load a value from memory, then reinterpret it later - in that case, we can load it using another view, at the cost of another load and another local. This is helpful on things like Box2D, where there are many reinterprets due to the main 2D vector class being an union over two floats/ints, and LLVM likes to do a single i64 load of them.
Diffstat (limited to 'src/wasm2js.h')
-rw-r--r--src/wasm2js.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/wasm2js.h b/src/wasm2js.h
index 24d168355..78bfd30ff 100644
--- a/src/wasm2js.h
+++ b/src/wasm2js.h
@@ -296,7 +296,18 @@ Ref Wasm2JSBuilder::processWasm(Module* wasm, Name funcName) {
// Next, optimize that as best we can. This should not generate
// non-JS-friendly things.
if (options.optimizeLevel > 0) {
+ // It is especially import to propagate constants after the lowering.
+ // However, this can be a slow operation, especially after flattening;
+ // some local simplification helps.
+ if (options.optimizeLevel >= 3 || options.shrinkLevel >= 1) {
+ runner.add("simplify-locals-nonesting");
+ runner.add("precompute-propagate");
+ // Avoiding reinterpretation is helped by propagation. We also run
+ // it later down as default optimizations help as well.
+ runner.add("avoid-reinterprets");
+ }
runner.addDefaultOptimizationPasses();
+ runner.add("avoid-reinterprets");
}
// Finally, get the code into the flat form we need for wasm2js itself, and
// optimize that a little in a way that keeps flat property.