summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* Update the ref_eq.wast spec test to match upstream (#6762)Thomas Lively2024-07-171-7/+164
|
* Revert "[threads] Allow i31refs of mixed shareability to compare equal ↵Thomas Lively2024-07-172-20/+3
| | | | | | | | | | | | | | (#6752)" (#6761) Allowing Literals with different types to compare equal causes problems for passes that want equality to mean real equality, e.g. because they are using literals as map keys or because they otherwise need to use them interchangeably. At a minimum, we would need to differentiate a `refEq` operation where mixed-shareability i31refs can compare equal from physical equality on Literals, but there is also appetite to disallow mixed-shareability ref.eq at the spec level. See https://github.com/WebAssembly/shared-everything-threads/issues/76.
* [threads][NFC] Do not include cont in shared types test (#6759)Thomas Lively2024-07-171-19/+11
| | | | | | Once the fuzzer is updated to be able to handle initial contents with shared types, it still will not be able to handle initial contents with continuation types. To avoid future issues, remove continuations from lit/basic/shared-types.wast.
* Error more clearly on wasm components (#6751)Alon Zakai2024-07-173-1/+15
| | | | | | Component binary format: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Binary.md#component-definitions Context: https://github.com/WebAssembly/binaryen/issues/6728#issuecomment-2231288924
* [NFC] Add changelog entries for the last release and since (#6755)Alon Zakai2024-07-171-4/+14
|
* [threads] Validate all features required by ref.null (#6758)Thomas Lively2024-07-172-2/+42
| | | | | | | `ref.null` of shared types should only be allowed when shared-everything is enabled, but we were previously checking only that reference types were enabled when validating `ref.null`. Update the code to check all features required by the null type and factor out shared logic for printing lists of missing feature options in error messages.
* Make it possible to skip several passes (#6714)Jérôme Vouillon2024-07-172-1/+66
| | | --skip-pass can now be specified more than once on the commandline.
* [threads] Validate all features required by ref.null (#6757)Thomas Lively2024-07-164-16/+40
| | | | | | | `ref.null` of shared types should only be allowed when shared-everything is enabled, but we were previously checking only that reference types were enabled when validating `ref.null`. Update the code to check all features required by the null type and factor out shared logic for printing lists of missing feature options in error messages.
* [threads] Fix feature detection for shared basic heap types (#6756)Thomas Lively2024-07-162-4/+15
| | | | The logic for adding the shared-everything feature was not previously executed for shared basic heap types.
* [NFC][threads] Ignore type-ssa-shared.wast in fuzzer (#6754)Thomas Lively2024-07-161-0/+1
| | | | The fuzzer does not yet properly handle initial contents containing shared types.
* Add C and JS APIs to control more pass options (#6713)Jérôme Vouillon2024-07-1613-0/+170
| | | | | | | Add functions to: * Set and get the trapsNeverHappen, closedWorld, generateStackIR and optimizeStackIR flags * Manage the list of passes to skip.
* [threads] Update TypeSSA for shared types (#6753)Thomas Lively2024-07-162-1/+76
| | | | When creating a new subtype, make sure to copy the supertype's shareability.
* [threads] Allow i31refs of mixed shareability to compare equal (#6752)Thomas Lively2024-07-162-3/+20
| | | | | | | Normally, values of different types can never compare equal to each other, but since i31refs are not actually allocations, `ref.eq` has no way to differentiate a shared i31ref and an unshared i31ref with the same value, so it will report them as equal. Update the implementation of value equality to reflect this correctly.
* [NFC] Clarify and standardize order in flexibleCopy (#6749)Alon Zakai2024-07-162-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | flexibleCopy always visited parents before children, but it visited vector children in reverse order: (call ;; 1 (call $a) ;; 3 (call $b) ;; 2 ) The order of children happened to not matter in any user of this code, and that's just what you get when you iterate over children in a vector and push them to a stack before visiting them, so this odd ordering was not noticed. For a new user I will introduce soon, however, it would be nice to have the normal pre-order: (call ;; 1 (call $a) ;; 2 (call $b) ;; 3 ) (2 & 3 swapped). This cannot be tested in the current code as it is NFC, but the later PR will depend on it and test it heavily.
* Remove extra space printed in empty structs (#6750)Thomas Lively2024-07-1657-353/+349
| | | | | | When we switched to the new type printing machinery, we inserted this extra space to minimize the diff in the test output compared with the previous type printer. Improve the quality of the printed output by removing it.
* [threads] Fix encoding of shared types (#6746)Thomas Lively2024-07-151-1/+1
|
* Simplify fuzzer generation of function references (#6745)Thomas Lively2024-07-152-45/+41
| | | | | | | | | | | | When creating a reference to `func`, fix the probability of choosing to continue on to choose some function other than the last one rather than making it depend on the number of functions. Then, do not eagerly pick from the rest of the candidate functions. Instead, fall through to the more general logic that will already pick a random candidate function. Also move the logic for coming up with a concrete signature down to where it is needed. These simplifications will make it easier to update the code to handle shared types.
* [NFC] Fix changelog order after #6687 (#6748)Alon Zakai2024-07-151-6/+7
| | | We made a release since it was written, which this is not included in.
* Allow different arguments for multiple instances of a pass (#6687)Christian Speckner2024-07-1531-89/+242
| | | | | | | | | | | | Each pass instance can now store an argument for it, which can be different. This may be a breaking change for the corner case of running a pass multiple times and setting the pass's argument multiple times as well (before, the last pass argument affected them all; now, it affects the last instance only). This only affects arguments with the name of a pass; others remain global, as before (and multiple passes can read them, in fact). See the CHANGELOG for details. Fixes #6646
* [threads] Test that array ops work with shared nulls (#6743)Thomas Lively2024-07-131-2/+26
|
* [threads] Fix struct op validation for shared null (#6742)Thomas Lively2024-07-132-1/+9
|
* Monomorphize dropped functions (#6734)Alon Zakai2024-07-126-36/+1418
| | | | | | | | | | | | | | | | | | | | | | | | | We now consider a drop to be part of the call context: If we see (drop (call $foo) ) (func $foo (result i32) (i32.const 42) ) Then we'd monomorphize to this: (call $foo_1) ;; call the specialized function instead (func $foo_1 ;; the specialized function returns nothing (drop ;; the drop was moved into here (i32.const 42) ) ) With the drop now in the called function, we may be able to optimize out unused work. Refactor a bit of code out of DAE that we can reuse here, into a new return-utils.h.
* Remove non-standard `i31.new` (#6736)Thomas Lively2024-07-126-83/+53
| | | | The standard name for the instruction is `ref.i31`. Remove support for the non-standard name and update tests that were still using it.
* [threads] ref.i31_shared (#6735)Thomas Lively2024-07-1222-38/+348
| | | | | | | Implement `ref.i31_shared` the new instruction for creating references to shared i31s. Implement binary and text parsing and emitting as well as interpretation. Copy the upstream spec test for i31 and modify it so that all the heap types are shared. Comment out some parts that we do not yet support.
* SafeHeap: Handle overflows when adding the pointer and the size (#6409)Alon Zakai2024-07-126-5525/+11980
| | | | | | | | | | | | | E.g. loading 4 bytes from 2^32 - 2 should error: 2 bytes are past the maximum address. Before this PR we added 2^32 - 2 + 4 and overflowed to 2, which we saw as a low and safe address. This PR adds an extra check for an overflow in that add. Also add unreachables after calls to segfault(), which reduces the overhead of the extra check here (the unreachable apparently allows VMs to see that control flow ends, after the segfault() which is truly no-return). Fixes emscripten-core/emscripten#21557
* Do not abbreviate items in element segments (#6737)Thomas Lively2024-07-127-30/+31
| | | | | | | | The full syntax for an expression in an element syntax looks like `(item (ref.null none))`, but we have been printing the abbreviated version, which omits the `(item ...)`. This abbreviation is only valid when the item has only a single instruction, so it is not always correct to use it. Rather than determining whether or not to use the abbreviation on a case-by-case basis, always print the full syntax.
* Memory64Lowering: Handle -1 return value from memory.grow (#6733)Sam Clegg2024-07-112-6/+43
| | | This edge case make the lowering a little more tricky.
* Convert memory64 lowering test to lit. NFC (#6731)Sam Clegg2024-07-113-264/+283
| | | Test was converted using port_passes_tests_to_lit.py.
* Monomorphize: Use -O3 over -O1 + tweaks (#6732)Alon Zakai2024-07-113-43/+36
| | | | | Eventually we will need to do some tuning of compile time speed, but for now it is going to be simpler to do all the opts, in particular because it makes writing tests simpler.
* [threads] Shared polymorphism for extern conversions (#6730)Thomas Lively2024-07-113-11/+29
| | | | | `any.convert_extern` and `extern.convert_any` return references to shared heap types iff their operands are references to shared heap types.
* [wasm-split] Use a fresh table when reference types are enabled (#6726)Thomas Lively2024-07-114-104/+254
| | | | | | | Rather than trying to trampoline primary-to-secondary calls through an existing table, just create a fresh table for this purpose. This ensures that modifications to the existing tables cannot interfere with primary-to-secondary calls and conversely that loading the secondary module cannot overwrite modifications to the tables.
* [WasmGC] Heap2Local: Optimize RefCast failures (#6727)Alon Zakai2024-07-112-37/+111
| | | | | | | Previously we just did not optimize cases where our escape analysis showed an allocation flowed into a cast that failed. However, after inlining there can be real-world cases where that happens, even in traps-never-happen mode (if the cast is behind a conditional branch), so it seems worth optimizing.
* Heap2Local: Drop RefEq's two arms (#6729)Alon Zakai2024-07-112-84/+79
| | | | | This is a tiny bit more code but it is more consistent with other operations, and it saves work later.
* Monomorphization: Optimize constants (#6711)Alon Zakai2024-07-118-124/+1268
| | | | | | | | | | | | | | | | | | | | | | | Previously the pass would monomorphize a call when we were sending more refined types than the target expects. This generalizes the pass to also consider the case where we send a constant in a parameter. To achieve that, this refactors the pass to explicitly define the "call context", which is the code around the call (inputs and outputs) that may end up leading to optimization opportunities when combined with the target function. Also add comments about the overall design + roadmap. The existing test is mostly unmodified, and the diff there is smaller when ignoring whitespace. We do "regress" those tests by adding more local.set operations, as in the refactoring that makes things a lot simpler, that is, to handle the general case of an operand having either a refined type or be a constant, we copy it inside the function, which works either way. This "regression" is only in the testing version of the pass (the normal version runs optimizations, which would remove that extra code). This also enables the pass when GC is disabled. Previously we only handled refined types, so only GC could benefit. Add a test for MVP content specifically to show we operate there as well.
* [WasmGC] Heap2Local: Optimize RefIs and RefTest (#6705)Alon Zakai2024-07-112-14/+438
|
* [StackIR] Allow StackIR to be disabled from the commandline (#6725)Alon Zakai2024-07-107-78/+737
| | | | | | | | | Normally we use it when optimizing (above a certain level). This lets the user prevent it from being used even then. Also add optimization options to wasm-metadce so that this is possible there as well and not just in wasm-opt (this also opens the door to running more passes in metadce, which may be useful later).
* Allow --keepfuncs and --splitfuncs to be use alongside a profile data (#6322)Benjamin Ling2024-07-106-49/+74
| | | | | | | | | There are times after collecting a profile, we wish to manually include specific functions into the primary module. It could be due to non-deterministic profiling or functions for error scenarios (e.g. _trap). This PR helps to unlock this workflow by honoring both the `--keep-funcs` flag as well as the `--profile` flag
* [C API] Add APIs for getting/setting function types, and a CallRef example ↵Alon Zakai2024-07-094-0/+58
| | | | | (#6721) Fixes #6718
* [tests] Remove use of CHECK-SAME (#6717)Anton Lydike2024-07-091-3/+1
| | | | The `filecheck` command used for tests does not support `CHECK-SAME`, so use should be avoided.
* StackIR: Optimize away a drop before an unreachable (#6719)Alon Zakai2024-07-082-1/+156
| | | | | | | | | | | | | | | | | | | | | | | | Anything else right before an unreachable is removed by the main DCE pass anyhow, but because of the structured form of BinaryenIR we can't remove a drop. That is, this is the difference between (i32.eqz (i32.const 42) (unreachable) ) and (drop (call $foo) ) (unreachable) In both cases the unreachable is preceded by something we don't need, but in the latter case it must remain in BinaryenIR for validation. To optimize this, add a rule in StackIR. Fixes #6715
* Version 118 (#6720)Alon Zakai2024-07-082-1/+4
|
* Rename external conversion instructions (#6716)Jérôme Vouillon2024-07-0837-122/+161
| | | | | | | | | Rename instructions `extern.internalize` into `any.convert_extern` and `extern.externalize` into `extern.convert_any` to follow more closely the spec. This was changed in https://github.com/WebAssembly/gc/issues/432. The legacy name is still accepted in text inputs and in the C and JS APIs.
* [DebugInfo] Add debug info to the values emitted in GlobalStructInference ↵Alon Zakai2024-07-022-15/+96
| | | | | | | | | (#6709) Previously the replacement select got the debug info, but we should also copy it to the values, as often optimizations lead to one of those values remaining by itself. Similar to #6652 in general form.
* ConstantFieldPropagation: Add a variation that picks between 2 values using ↵Alon Zakai2024-06-277-16/+1723
| | | | | | | | | | | | | | | | | | | | | | | | | | | RefTest (#6692) CFP focuses on finding when a field always contains a constant, and then replaces a struct.get with that constant. If we find there are two constant values, then in some cases we can still optimize, if we have a way to pick between them. All we have is the struct.get and its reference, so we must use a ref.test: (struct.get $T x (..ref..)) => (select (..constant1..) (..constant2..) (ref.test $U (..ref..)) ) This is valid if, of all the subtypes of $T, those that pass the test have constant1 in that field, and those that fail the test have constant2. For example, a simple case is where $T has two subtypes, $T is never created itself, and each of the two subtypes has a different constant value. This is a somewhat risky operation, as ref.test is not necessarily cheap. To mitigate that, this is a new pass, --cfp-reftest that is not run by default, and also we only optimize when we can use a ref.test on what we think will be a final type (because ref.test on a final type can be faster in VMs).
* [NFC] Add HeapType::getFeatures() (#6707)Alon Zakai2024-06-274-89/+95
|
* [threads] Ignore shared-array.wast in fuzzer initial contents (#6706)Thomas Lively2024-06-261-0/+1
|
* [threads] Fuzz shared types in type fuzzer (#6704)Thomas Lively2024-06-265-144/+182
| | | | | | | | | | | | | | Give the type fuzzer the ability to generate shared heap types when the shared-everything feature is enabled. It correctly ensures that shared structs and arrays cannot reference unshared heap types, but that unshared heap types can reference any heap type. Update the main fuzzer so that for the time being it never uses the shared-everything feature when generating additional heap types, so it never generates shared types. We can lift this restriction once the main fuzzer has been updated to properly handle shared types. As a drive-by, fix some logic for subtracting feature sets from each other that is used in this commit.
* [WasmGC] Heap2Local: Optimize RefEq (#6703)Alon Zakai2024-06-262-10/+352
| | | | | If an allocation does not escape, then we can compute ref.eq for it: when compared to itself the result is 1, and when compared to anything else it is 0 (since it did not escape, anything else must be different).
* [threads] Validate shared-polymorphic instructions (#6702)Thomas Lively2024-06-256-72/+150
| | | | Such as `ref.eq`, `i31.get_{s,u}`, and `array.len`. Also validate that struct and array operations work on shared structs and arrays.
* [threads] Validate shared-to-unshared edges in heap types (#6698)Thomas Lively2024-06-255-22/+195
| | | Add spec tests checking validation for structs and arrays.