summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* [Wasm GC] GC-prefixed opcodes are int8, not LEBs (#4889)Alon Zakai2022-08-092-61/+61
| | | | | | This starts to matter with strings, it turns out. This change should make us runnable in v8. Spec: https://github.com/WebAssembly/gc/blob/main/proposals/gc/MVP.md#instructions-1
* [Strings] string.new.array methods have start:end arguments (#4888)Alon Zakai2022-08-096-2/+32
|
* RedundantSetElimination: ReFinalize when needed (#4877)Alon Zakai2022-08-091-0/+21
|
* SimplifyLocals: ReFinalize when needed (#4878)Alon Zakai2022-08-091-0/+25
|
* [Wasm GC] Fix SignaturePruning on CallWithoutEffects (#4882)Alon Zakai2022-08-081-0/+13
| | | | | | | | | | | | | | | | | | | call.without.effects will turn into a normal call of the last parameter later, (call $call.without.effects A B (ref.func $foo) ) ;; => intrinsic lowering (call $foo A B ) SignaturePruning needs to be aware of that: we can't remove a parameter from $foo without also updating relevant calls to $call.without.effects. Rather than handle that, just skip such cases, and leave them to be optimized after intrinsics are lowered away.
* [GUFA] Fix readFromData on a function literal (#4883)Alon Zakai2022-08-081-6/+9
| | | | | | | A function literal (ref.func) should never reach a struct or array get, but if there is a cast then it can look like they might arrive. We filter in ref.cast which avoids that (since casting a function to a data type will trap), but there is also br_on_cast which is not yet optimized. This PR adds code to avoid an assert in readFromData in that case.
* [Optimize Instructions] Fold eqz(eqz(x)) to not-equal of zero (#4855)Max Graey2022-08-081-4/+17
| | | | | | eqz(eqz(i32(x))) -> i32(x) != 0 eqz(eqz(i64(x))) -> i64(x) != 0 Only when shrinkLevel == 0 (prefer speed over binary size).
* Remove metadata generation from wasm-emscripten-finalize (#4863)Sam Clegg2022-08-073-269/+3
| | | | This is no longer needed by emscripten as of: https://github.com/emscripten-core/emscripten/pull/16529
* wasm-emscripten-finalize: Remove em_js/em_asm start/stop symbols when ↵Sam Clegg2022-08-051-0/+9
| | | | | | | | stripping data segments. (#4876) This avoid a fatal crash in `--post-emscripten` where it tries to remove data that is no longer part of the file. This fixes bug introduced by #4871 that causes emscripten tests to fail.
* Remove RTTs (#4848)Thomas Lively2022-08-0544-1945/+432
| | | | | | | RTTs were removed from the GC spec and if they are added back in in the future, they will be heap types rather than value types as in our implementation. Updating our implementation to have RTTs be heap types would have been more work than deleting them for questionable benefit since we don't know how long it will be before they are specced again.
* Cleanup em_asm/em_js strings as part of PostEmscripten (#4871)Sam Clegg2022-08-042-90/+185
| | | | Rather than doing it as a side effect of dumping the metadata in wasm-emscripten-finalize.
* [NFC] Skip Directize pass if there are no tables (#4875)Alon Zakai2022-08-041-0/+4
|
* Allow `BINARYEN_DEBUG` environment variable to be used in place of ↵Sam Clegg2022-08-041-0/+4
| | | | | | | | | `--debug`. NFC (#4874) For example I found it useful to able to do something like this: ``` $ BINARYEN_DEBUG=post-emscripten ./test/runner sometest ```
* [C-API] Add type builder C-API (#4803)dcode2022-08-042-0/+308
| | | Introduces the necessary APIs to use the type builder from C. Enables construction of compound heap types (arrays, structs and signatures) that may be recursive, including assigning concrete names to the built types and, in case of structs, their fields.
* [NFC] Mark modifiesBinaryenIR=false in more places (#4869)Alon Zakai2022-08-037-0/+14
|
* wasm-emscripten-finalize: Remove __start/__stop_em_js exports (#4870)Sam Clegg2022-08-031-0/+3
| | | | | | | | We already remove `__start_em_asm` and `__stop_em_asm`. This change is needed since I want to start exporting `__start_em_js` and `__stop_em_js` from emscripten without causing regressions. As a followup I'm planning on moving all of the em_js and em_asm stripping code it PostEmscripten.cpp.
* Remove support for parsing `let` (#4864)Thomas Lively2022-08-032-90/+2
| | | | | It has been removed from the typed function references proposal, so we no longer need to support it. Maintaining the test for `let` was difficult because Binaryen could not emit either text or binary that actually used it.
* [Optimize Instructions] Refactor squared rules (#4840)Max Graey2022-08-022-55/+135
| | | | | | | | | | | | + Move these rules to separate function; + Refactor them to use matches; + Add comments; + Handle rotational shifts as well; + Handle overflows for `<<`, `>>`, `>>>` shifts; + Add mixed rotate rules: ```rust rotl(rotr(x, C1), C2) => rotr(x, C1 - C2) rotr(rotl(x, C1), C2) => rotl(x, C1 - C2) ```
* Fix a new compiler warning (#4860)Alon Zakai2022-08-021-0/+1
| | | Avoids a "may fall through" warning.
* [NFC] Refactor getDroppedChildrenAndAppend (#4849)Max Graey2022-08-011-3/+3
|
* Update reference type Literal constructors to use HeapType (#4857)Thomas Lively2022-08-017-18/+21
| | | | | | We already require non-null literals to have non-null types, but with this change we can enforce that constraint by construction. Also remove the default behavior of creating a function reference literal with heap type `func`, since there is always a more specific function type to use.
* Add interpreter support for intrinsics (#4851)Alon Zakai2022-08-012-3/+17
| | | This can give us some chance to catch bugs like #4839 in the fuzzer.
* [GUFA] Handle GUFA + Intrinsics (#4839)Alon Zakai2022-08-012-17/+52
| | | | | | | | Like RemoveUnusedModuleElements, places that build graphs of function reachability must special-case the call-without-effects intrinsic. Without that, it looks like a call to an import. Normally a call to an import is fine - it makes us be super-pessimistic, as we think things escape all the way out - but in GC for now we are assuming a closed world, and so we end up broken. To fix that, properly handle the intrinsic case.
* [NFC] wasm-reduce: Avoid wasted work on drops (#4850)Alon Zakai2022-07-291-0/+7
| | | | | | It was wasted work to see a drop and then check if we can replace it with a drop of its child, which is identical to the original state. This didn't cause any harm (we'd not reduce code size, and stop eventually) but it did slow us down.
* Refactor doIndent (#4847)Max Graey2022-07-293-14/+3
| | | | | | | | | | | | | | | | Refactor everywhere from: ```c++ for (size_t i = 0; i < indent; i++) { o << ' '; } ``` to: ```c++ o << std::string(indent, ' '); ``` ### Motivation It is much simpler and should produce smaller code.See godbolt: https://godbolt.org/z/KMYMdn7z5
* [JS Api] Reuse C-Api for emitText and emitStackIR (#4832)Max Graey2022-07-295-41/+43
| | | Make the C API match the JS API and fix an old bug where extra newlines were emitted.
* [C/JS API] Add string reference types (#4810)dcode2022-07-273-0/+44
|
* [Strings] Add interpreter stubs for string instructions (#4835)Alon Zakai2022-07-261-35/+40
| | | | | | | | | The stubs let precompute skip over them without erroring. With this PR we can run the optimizer on strings code. We still can't run --fuzz-exec though, so we can't run the fuzzer. Also simplify the error strings in the earlier part of the file. All other code just has "unimp" so we might as well do the same and not mention full names there.
* Fix unreachable handling in getDroppedChildrenAndAppend (#4834)Heejin Ahn2022-07-261-1/+1
| | | | | | | The previous code assumes if `last`'s type is unreachable it traps. But it's not always the case because it can be other instructions like `br` whose type is unreachable but doesn't necessarily trap. Context: https://github.com/WebAssembly/binaryen/pull/4827#discussion_r929395477
* wasm-reduce: Apply commandline features (#4833)Alon Zakai2022-07-261-3/+11
| | | | | This lets wasm-reduce --enable-FOO work. Usually this is not needed as we do enable all features by default, but sometimes it is nice to disable features (e.g. to avoid reducing into a testcase that uses something the original wasm did not use).
* Make `GlobalTypeRewriter` work for isorecursive types (#4829)Thomas Lively2022-07-263-4/+15
| | | | | | | | | | | | | | | | | | | There are two new potential problems that `GlobalTypeRewriter` can run into when working with isorecursive types instead of nominal types. First, the refined types may have replaced generic references with references to specific other types, potentially creating new recursions and making the existing recursion groups insufficient. Second, distinct types may be refined to structurally identical types and those distinct input types may map the same output type, potentially changing cast behavior. Both of these problems are solved by putting all the new types in a single large recursion group. We do not currently account for the fact that types may be used in the external interface of the module, but when we do, externalized types will be excluded from optimizations and will not be affected by the creation of this single large rec group. Fixes #4816.
* Changing ref maps in wasm-binary to use a value of a vector of Name* (#4830)Ashley Nelson2022-07-262-40/+17
| | | | | | | | | | | * Changing ref maps in wasm-binary to use a value of a vector of Name* * clang-format * Update src/wasm/wasm-binary.cpp Co-authored-by: Thomas Lively <7121787+tlively@users.noreply.github.com> Co-authored-by: Thomas Lively <7121787+tlively@users.noreply.github.com>
* [C/JS API] Expose string reference feature (#4831)Max Graey2022-07-263-0/+5
|
* [OptimizeInstructions] Add folding for mixed left shift and mul with ↵Max Graey2022-07-261-0/+17
| | | | | | constants on RHS (#4808) (x * C1) << C2 -> x * (C1 << C2) (x << C1) * C2 -> x * (C2 << C1)
* Update reference type shorthands in binary output (#4828)Thomas Lively2022-07-251-26/+31
| | | | | | | | | Add support for emitting the string type reference shorthands, which had previously been omitted accidentally due to the `default` case in that switch. Also avoid emitting shorthands for non-nullable reference types as a first step towards transitioning the shorthands to represent nullable types instead. Not emitting these shorthands at all will give V8 the flexibility it needs to change its interpretation of the shorthands without breaking any workflows using Binaryen.
* Move method implementations to drop.cpp (#4823)Heejin Ahn2022-07-254-77/+109
| | | | | | | | | | | | Now that we have `getDroppedUnconditionalChildrenAndAppend`, all passes need to use it rather than the old `getDroppedChildrenAndAppend`, which is used within the new method `getDroppedUnconditionalChildrenAndAppend`. This creates `drop.cpp` and move method implementations in drop.h there, and merge two methods given that the old method is not supposed to be used from outside anyway, and drops `Unconditional` from the new method name because this is the only method and doesn't have to be specific about that.
* [Effects] call_ref traps when the target is null (#4826)Alon Zakai2022-07-251-3/+5
| | | | | | This is not observable in practice atm since call_ref also does a call, which has even more effects. However, future optimizations might benefit from this, and it is more consistent to avoid marking the instruction as trapping if it can't.
* [Wasm GC] i31get can trap (#4825)Alon Zakai2022-07-251-1/+6
|
* [wasm-split] Add --print-profile option (#4771)sps-gold2022-07-253-19/+118
| | | | | | | | | | | | | | | | | | | | | | | There are several reasons why a function may not be trained in deterministically. So to perform quick validation we need to inspect profile.data (another ways requires split to be performed). However as profile.data is a binary file and is not self sufficient, so we cannot currently use it to perform such validation. Therefore to allow quick check on whether a particular function has been trained in, we need to dump profile.data in a more readable format. This PR, allows us to output, the list of functions to be kept (in main wasm) and those split functions (to be moved to deferred.wasm) in a readable format, to console. Added a new option `--print-profile` - input path to orig.wasm (its the original wasm file that will be used later during split) - input path to profile.data that we need to output optionally pass `--unescape` to unescape the function names Usage: ``` binaryen\build>bin\wasm-split.exe test\profile_data\MY.orig.wasm --print-profile=test\profile_data\profile.data > test\profile_data\out.log ``` note: meaning of prefixes `+` => fn to be kept in main wasm `-` => fn to be split and moved to deferred wasm
* [Wasm GC] Properly represent nulls in i31 (#4819)Alon Zakai2022-07-253-8/+18
| | | | | The encoding here is simple: we store i31 values in the literal.i32 field. The top bit says if a value exists, which means literal.i32 == 0 is the same as null.
* Grand Unified Flow Analysis (GUFA) (#4598)Alon Zakai2022-07-226-17/+381
| | | | | | | | | | | | | This tracks the possible contents in the entire program all at once using a single IR. That is in contrast to say DeadArgumentElimination of LocalRefining etc., all of whom look at one particular aspect of the program (function params and returns in DAE, locals in LocalRefining). The cost is to build up an entire new IR, which takes a lot of new code (mostly in the already-landed PossibleContents). Another cost is this new IR is very big and requires a lot of time and memory to process. The benefit is that this can find opportunities that are only obvious when looking at the entire program, and also it can track information that is more specialized than the normal type system in the IR - in particular, this can track an ExactType, which is the case where we know the value is of a particular type exactly and not a subtype.
* [Strings] GC variants for string.encode (#4817)Alon Zakai2022-07-2110-23/+130
|
* Remove usage of emscripten's deprecated allocate runtime function (#4795)Sam Clegg2022-07-211-3/+5
|
* Remove basic reference types (#4802)Thomas Lively2022-07-2029-631/+386
| | | | | | | | | Basic reference types like `Type::funcref`, `Type::anyref`, etc. made it easy to accidentally forget to handle reference types with the same basic HeapTypes but the opposite nullability. In principle there is nothing special about the types with shorthands except in the binary and text formats. Removing these shorthands from the internal type representation by removing all basic reference types makes some code more complicated locally, but simplifies code globally and encourages properly handling both nullable and non-nullable reference types.
* [Strings] Add string.new GC variants (#4813)Alon Zakai2022-07-1911-27/+143
|
* [Strings] stringview_wtf16.length (#4809)Alon Zakai2022-07-186-0/+20
| | | | This measures the length of a view, so it seems simplest to make it a sub-operation of the existing measure instruction.
* [Strings] stringview_*.slice (#4805)Alon Zakai2022-07-1519-22/+298
| | | | | | | Unfortunately one slice is the same as python [start:end], using 2 params, and the other slice is one param, [CURR:CURR+num] (where CURR is implied by the current state in the iter). So we can't use a single class here. Perhaps a different name would be good, like slice vs substring (like JS does), but I picked names to match the current spec.
* [Wasm GC] Check if ref.eq inputs can possibly be the same (#4780)Alon Zakai2022-07-141-3/+27
| | | | | For them to be the same we must have a value that can appear on both sides. If the heap types disallow that, then only null is possible, and if that is impossible as well then the result must be 0.
* [C-API] Add utility to go between types and heap types (#4792)dcode2022-07-142-0/+24
|
* [Wasm GC] GTO should not reorder trapping of removed sets (#4801)Alon Zakai2022-07-132-10/+18
| | | | | Minor fuzz bug. When we replace a struct.set with its children we also add a ref.as_non_null on the reference, but that must not occur before effects in the other child.