From bb41564ff8a495d19a6d41ffe7f057f241e9739c Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 23 Oct 2019 15:09:11 -0700 Subject: Add ModAsyncify* passes (#2404) These passes are meant to be run after Asyncify has been run, they modify the output. We can assume that we will always unwind if we reach an import, or that we will never unwind, etc. This is meant to help with lazy code loading, that is, the ability for an initially-downloaded wasm to not contain all the code, and if code not present there is called, we download all the rest and continue with that. That could work something like this: * The wasm is created. It contains calls to a special import for lazy code loading. * Asyncify is run on it. * The initially downloaded wasm is created by running --mod-asyncify-always-and-only-unwind: if the special import for lazy code loading is called, we will definitely unwind, and we won't rewind in this binary. * The lazily downloaded wasm is created by running --mod-asyncify-never-unwind: we will rewind into this binary, but no longer need support for unwinding. (Optionally, there could also be a third wasm, which has not had Asyncify run on it, and which we'd swap to for max speed.) These --mod-asyncify passes allow the optimizer to do a lot of work, especially for the initially downloaded wasm if we have lots of calls to the lazy code loading import. In that case the optimizer will see that those calls unwind, which means the code after them is not reached, potentially making lots of code dead and removable. --- src/passes/pass.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/passes/pass.cpp') diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index 7d17510fc..0ac70aa59 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -180,6 +180,13 @@ void PassRegistry::registerPasses() { "minifies both import and export names, and emits a mapping to " "the minified ones", createMinifyImportsAndExportsPass); + registerPass("mod-asyncify-always-and-only-unwind", + "apply the assumption that asyncify imports always unwind, " + "and we never rewind", + createModAsyncifyAlwaysOnlyUnwindPass); + registerPass("mod-asyncify-never-unwind", + "apply the assumption that asyncify never unwinds", + createModAsyncifyNeverUnwindPass); registerPass("nm", "name list", createNameListPass); registerPass("no-exit-runtime", "removes calls to atexit(), which is valid if the C runtime " -- cgit v1.2.3