summaryrefslogtreecommitdiff
path: root/src/wasm2js.h
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2019-04-30 20:30:03 -0700
committerGitHub <noreply@github.com>2019-04-30 20:30:03 -0700
commit8d4bcd6e02bb0df3ac87e4850896ba733525b055 (patch)
tree1f98b878c22fd23c918992b53fd8e9f4f78d3788 /src/wasm2js.h
parentfba743ca5bdfe4fb437a36503b8983c5f42e4575 (diff)
downloadbinaryen-8d4bcd6e02bb0df3ac87e4850896ba733525b055.tar.gz
binaryen-8d4bcd6e02bb0df3ac87e4850896ba733525b055.tar.bz2
binaryen-8d4bcd6e02bb0df3ac87e4850896ba733525b055.zip
wasm2js: run full optimizations during the pipeline (#2071)
We flatten for the i64 lowering etc. passes, and it is worth optimizing afterwards, to clean up stuff they created. That is run if the user ran wasm2js with an optimization level (like wasm2js -O3). Split the test files to check both optimized and unoptimized code.
Diffstat (limited to 'src/wasm2js.h')
-rw-r--r--src/wasm2js.h57
1 files changed, 34 insertions, 23 deletions
diff --git a/src/wasm2js.h b/src/wasm2js.h
index c05c16f2b..18175d443 100644
--- a/src/wasm2js.h
+++ b/src/wasm2js.h
@@ -267,29 +267,40 @@ Ref Wasm2JSBuilder::processWasm(Module* wasm, Name funcName) {
// If later on they aren't needed, we'll clean them up.
ABI::wasm2js::ensureScratchMemoryHelpers(wasm);
- PassRunner runner(wasm);
- runner.add<AutoDrop>();
- runner.add("legalize-js-interface");
- // First up remove as many non-JS operations we can, including things like
- // 64-bit integer multiplication/division, `f32.nearest` instructions, etc.
- // This may inject intrinsics which use i64 so it needs to be run before the
- // i64-to-i32 lowering pass.
- runner.add("remove-non-js-ops");
- // Currently the i64-to-32 lowering pass requires that `flatten` be run before
- // it to produce correct code. For some more details about this see #1480
- runner.add("flatten");
- runner.add("i64-to-i32-lowering");
- runner.add("flatten");
- runner.add("simplify-locals-notee-nostructure");
- runner.add("reorder-locals");
- runner.add("remove-unused-names");
- runner.add("vacuum");
- runner.add("remove-unused-module-elements");
- runner.setDebug(flags.debug);
- runner.run();
-
- // Make sure we didn't corrupt anything if we're in --allow-asserts mode (aka
- // tests)
+ // Process the code, and optimize if relevant.
+ // First, do the lowering to a JS-friendly subset.
+ {
+ PassRunner runner(wasm, options);
+ runner.add<AutoDrop>();
+ runner.add("legalize-js-interface");
+ // First up remove as many non-JS operations we can, including things like
+ // 64-bit integer multiplication/division, `f32.nearest` instructions, etc.
+ // This may inject intrinsics which use i64 so it needs to be run before the
+ // i64-to-i32 lowering pass.
+ runner.add("remove-non-js-ops");
+ // Currently the i64-to-32 lowering pass requires that `flatten` be run
+ // before it to produce correct code. For some more details about this see
+ // #1480
+ runner.add("flatten");
+ runner.add("i64-to-i32-lowering");
+ // Next, optimize that as best we can. This should not generate
+ // non-JS-friendly things.
+ if (options.optimizeLevel > 0) {
+ runner.addDefaultOptimizationPasses();
+ }
+ // 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.
+ runner.add("flatten");
+ runner.add("simplify-locals-notee-nostructure");
+ // TODO: coalesce-locals?
+ runner.add("reorder-locals");
+ runner.add("remove-unused-names");
+ runner.add("vacuum");
+ runner.add("remove-unused-module-elements");
+ runner.setDebug(flags.debug);
+ runner.run();
+ }
+
#ifndef NDEBUG
if (!WasmValidator().validate(*wasm)) {
WasmPrinter::printModule(wasm);