summaryrefslogtreecommitdiff
path: root/src/passes/MinifyImportsAndExports.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Refactor interaction between Pass and PassRunner (#5093)Thomas Lively2022-09-301-1/+1
| | | | | | | | | | | | | | Previously only WalkerPasses had access to the `getPassRunner` and `getPassOptions` methods. Move those methods to `Pass` so all passes can use them. As a result, the `PassRunner` passed to `Pass::run` and `Pass::runOnFunction` is no longer necessary, so remove it. Also update `Pass::create` to return a unique_ptr, which is more efficient than having it return a raw pointer only to have the `PassRunner` wrap that raw pointer in a `unique_ptr`. Delete the unused template `PassRunner::getLast()`, which looks like it was intended to enable retrieving previous analyses and has been in the code base since 2015 but is not implemented anywhere.
* [Wasm GC] Support non-nullable locals in the "1a" form (#4959)Alon Zakai2022-08-311-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | An overview of this is in the README in the diff here (conveniently, it is near the top of the diff). Basically, we fix up nn locals after each pass, by default. This keeps things easy to reason about - what validates is what is valid wasm - but there are some minor nuances as mentioned there, in particular, we ignore nameless blocks (which are commonly added by various passes; ignoring them means we can keep more locals non-nullable). The key addition here is LocalStructuralDominance which checks which local indexes have the "structural dominance" property of 1a, that is, that each get has a set in its block or an outer block that precedes it. I optimized that function quite a lot to reduce the overhead of running that logic after each pass. The overhead is something like 2% on J2Wasm and 0% on Dart (0%, because in this mode we shrink code size, so there is less work actually, and it balances out). Since we run fixups after each pass, this PR removes logic to manually call the fixup code from various places we used to call it (like eh-utils and various passes). Various passes are now marked as requiresNonNullableLocalFixups => false. That lets us skip running the fixups after them, which we normally do automatically. This helps avoid overhead. Most passes still need the fixups, though - any pass that adds a local, or a named block, or moves code around, likely does. This removes a hack in SimplifyLocals that is no longer needed. Before we worked to avoid moving a set into a try, as it might not validate. Now, we just do it and let fixups happen automatically if they need to: in the common code they probably don't, so the extra complexity seems not worth it. Also removes a hack from StackIR. That hack tried to avoid roundtrip adding a nondefaultable local. But we have the logic to fix that up now, and opts will likely keep it non-nullable as well. Various tests end up updated here because now a local can be non-nullable - previous fixups are no longer needed. Note that this doesn't remove the gc-nn-locals feature. That has been useful for testing, and may still be useful in the future - it basically just allows nn locals in all positions (that can't read the null default value at the entry). We can consider removing it separately. Fixes #4824
* Modernize code to C++17 (#3104)Max Graey2021-11-221-4/+4
|
* [Refactoring] Cleanup asm2wasm. Use JS instead ASM prefix where possible. ↵Max Graey2021-09-011-1/+1
| | | | NFC (#4090)
* [NFC] Factor out and simplify minified name generation (#3909)Thomas Lively2021-05-271-89/+3
| | | | Simplifies the public API to not unnecessarily take an index and simplifies the implementation to use a single integer as state rather than a vector of indices.
* MinifyImportsAndExports: Minify the memory and table as well. (#3089)Alon Zakai2020-09-021-16/+4
| | | | | | | | | | | | We were careful not to minify those, as well as the stack pointer, which makes sense in dynamic linking. But we don't run this pass in dynamic linking anyhow - we need the proper names of symbols in that case. So this was not helping us, and was just a leftover from an early state. This both a useful optimization and also important for #3043, as the wasm backend exports the table as __indirect_function_table - a much longer name than emscripten's table. So just changing to that would regress code size on small projects. Once we land this, the name won't matter as it will be minified anyhow.
* Optionally minify imported module names (#2620)Alon Zakai2020-01-271-8/+48
| | | | | | | | | | | | | | | | This replaces imports like env.foo with a.foo, which can save a bunch of bytes when there are many imported functions. Note that by changing all the import names to a it ends up requiring a single merged import module. Note also that when doing this we modify all the imports, minifying their modules and names (since it makes no sense to be careful about minifying only modules known to us - env/wasi - if we are minifyin the names of all modules). This will require an emscripten PR to benefit from it.
* Include in minification all imports from modules starting with `wasi_` (#2509)Sam Clegg2019-12-051-3/+1
| | | | | | This allows us to support not just wasi_unstable but also the new wasi_snapshot_preview1 and beyond. See https://github.com/emscripten-core/emscripten/pull/9956
* Wasi followups to #2323 (#2329)Alon Zakai2019-09-031-2/+3
| | | | | Remove wasi, as only wasi_unstable makes sense. Also remove shared constant for wasi as we don't know yet if it'll be needed later.
* Minify wasi imports and exports, and not just "env" (#2323)Alon Zakai2019-09-011-5/+13
| | | This makes the minification pass aware of "wasi_unstable" and "wasi" as well.
* Don't minify __stack_pointer import (#2219)Sam Clegg2019-07-111-1/+1
| | | This is core import like __memory_base and __table_base.
* Add event section (#2151)Heejin Ahn2019-05-311-0/+1
| | | | | | | | | | | | | | | | | | This adds support for the event and the event section, as specified in https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md#changes-to-the-binary-model. Wasm events are features that suspend the current execution and transfer the control flow to a corresponding handler. Currently the only supported event kind is exceptions. For events, this includes support for - Binary file reading/writing - Wast file reading/writing - Binaryen.js API - Fuzzer - Validation - Metadce - Passes: metrics, minify-imports-and-exports, remove-unused-module-elements
* Apply format changes from #2048 (#2059)Alon Zakai2019-04-261-13/+15
| | | Mass change to apply clang-format to everything. We are applying this in a PR by me so the (git) blame is all mine ;) but @aheejin did all the work to get clang-format set up and all the manual work to tidy up some things to make the output nicer in #2048
* Adjust MinifyImportsAndExports to optionally minify the export names, ↵Jukka Jylänki2018-11-221-4/+16
| | | | sometimes that is not desirable.
* Fix a bug with (add (sub 0 X) Y) => (sub Y X) (#1727)Alon Zakai2018-11-071-1/+0
| | | | | We need to verify that the reordering is valid if there are side effects. Original bug report: https://groups.google.com/forum/?nomobile=true#!topic/emscripten-discuss/HIlGf8o2Ato
* Add pass to minify import and export names (#1719)Alon Zakai2018-11-011-0/+170
This new pass minifies import and export names, for example, this may minify (import "env" "longname" (func $internal)) to (import "env" "a" (func $internal)) By updating the JS that provides those imports/calls those exports, we can use the minified names properly. This can save a useful amount of space in the wasm and JS, see kripken/emscripten#7414