summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* RedundantSetElimination: Look at fallthrough values (#5213)Alon Zakai2022-11-031-2/+6
| | | | | | | | | | | This can help in rare cases in MVP wasm, say for the return value of a block. But for wasm GC it is very important due to casts. Similar logic was added as part of #5194 for SimplifyLocals. It should probably have been in a separate PR then. This does the right thing for RedundantSetElimination, as a separate PR. Full tests will appear in that later PR (it is not really possible to test the GC side yet - we need the logic in the later PR that actually switches to a more refined local index when available).
* [C API] Add APIs to inspect compound heap types (#5195)dcode2022-11-032-0/+73
| | | | | | | | | | | | | | | | | | | | | | Adds C APIs to inspect compound struct, array and signature heap types: Obtain field types, field packed types and field mutabilities of struct types: BinaryenStructTypeGetNumFields (to iterate) BinaryenStructTypeGetFieldType BinaryenStructTypeGetFieldPackedType BinaryenStructTypeIsFieldMutable Obtain element type, element packed type and element mutability of array types: BinaryenArrayTypeGetElementType BinaryenArrayTypeGetElementPackedType BinaryenArrayTypeIsElementMutable Obtain parameter and result types of signature types: BinaryenSignatureTypeGetParams BinaryenSignatureTypeGetResults
* SimplifyLocals: Fix handling of subtyping (#5210)Alon Zakai2022-11-021-16/+20
| | | | | | | We just checked if the new type we prefer (when switching a local to a more refined one in #5194) is different than the old type. But that check at the end must check it is a subtype as well. Diff without whitespace is smaller.
* ReorderGlobals pass (#4904)Alon Zakai2022-11-024-1/+177
| | | | | | | | | This sorts globals by their usage (and respecting dependencies). If the module has very many globals then using smaller LEBs can matter. If there are fewer than 128 globals then we cannot reduce size, and the pass exits early (so this pass will not slow down MVP builds, which usually have just 1 global, the stack pointer). But with wasm GC it is common to use globals for vtables etc., and often there is a very large number of them.
* [Wasm GC] SimplifyLocals: Switch local.get to use a more refined type when ↵Alon Zakai2022-11-011-16/+44
| | | | | | | | | | | | | | | possible (#5194) (local.set $refined (cast (local.get $plain))) .. .. (local.get $plain) .. ;; we can change this to read from $refined By using the more refined type we may be able to eliminate casts later. To do this, look at the fallthrough value (so we can look through a cast or a block value - this is the reason for the small wasm2js improvements in tests), and also extend the code that picks which local index to read to look at types (previously we just ignored any pairs of locals with different types).
* [NFC] Mention relevant flags in validator errors (#5203)Alon Zakai2022-11-011-93/+116
| | | | | | | | | | E.g. Atomic operation (atomics are disabled) => Atomic operations require threads [--enable-threads]
* Multi-Memories Lowering Pass (#5107)Ashley Nelson2022-11-015-0/+428
| | | | | | | | | | Adds a multi-memories lowering pass that will create a single combined memory from the memories added to the module. This pass assumes that each memory is configured the same (type, shared). This pass also: - replaces existing memory.size instructions with a custom function that returns the size of each memory as if they existed independently - replaces existing memory.grow instructions with a custom function, using global offsets to track the page size of each memory so data doesn't overlap in the singled combined memory - adjusts the offsets of active data segments - adjusts the offsets of Loads/Stores
* CodePushing: Push into If arms (#5191)Alon Zakai2022-11-011-24/+199
| | | | | | | | | | | | | | | | | | | | | | | | Previously the pass only pushed past an if or a br_if. This does the same but into an if arm. On Wasm GC for example this can perform allocation sinking: function foo() { x = new A(); if (..) { use(x); } } => function foo() { if (..) { x = new A(); // this moved use(x); } } The allocation won't happen if we never enter the if. This helps wasm MVP too, and in fact some existing tests benefit.
* Fix a fuzz issue with scanning heap read types (#5184)Alon Zakai2022-11-011-1/+13
| | | | | | | | | If a heap type only ever appears as the result of a read, we must include it in the analysis in ModuleUtils, even though it isn't written in the binary format. Otherwise analyses using ModuleUtils can error on not finding all types in the list of types. Fixes #5180
* [Wasm GC] Enable various passes in hybrid mode, not just nominal (#5202)Alon Zakai2022-10-316-11/+18
|
* Fix br_if fallthrough value (#5200)Alon Zakai2022-10-311-1/+15
| | | | | | | The fallthrough there is trickier because the value is evaluated before the condition. Unlike other fallthroughs, the value is not last, so we need to check if the condition (which is after it) interferes with it.
* Work around some gcc 10.x issues (#5199)Alon Zakai2022-10-311-5/+5
| | | See #5188
* Fix comment in Asyncify.cpp (#5196)William Stein2022-10-311-1/+1
|
* [NFC] Rewrite PossibleContents::combine to be static (#5192)Alon Zakai2022-10-282-53/+51
| | | | | This makes the logic symmetric and easier to read. Measuring speed, this seems identical to before, so that concern seems fine.
* [Wasm GC] Fix the depth of the new array heap type (#5186)Alon Zakai2022-10-281-2/+12
|
* [C API] Add essential heap type utilities (#5160)dcode2022-10-262-0/+21
| | | | | | | | | | Adds heap type utility to the C API: BinaryenHeapTypeIsBasic BinaryenHeapTypeIsSignature BinaryenHeapTypeIsStruct BinaryenHeapTypeIsArray BinaryenHeapTypeIsSubType
* Move removable code in CodePushing (#5187)Alon Zakai2022-10-251-3/+18
| | | | | | | | | | | | | | | | | | | | This is safe since we "partially remove" it: we don't move it to a place it might execute more, but make it possibly execute less. See the new comment for more details. Motivated by wasm GC but this can help wasm MVP as well. In both cases loads from memory can trap, which limits what the VM can do to optimize them past conditions, but in trapsNeverHappens we can do that at the toolchain level: x = read(); if () { .. } use(x); => if () { .. } x = read(); // moved to here, and might not execute if the if did a break/return use(x);
* [Parser] Parse `return` (#5181)Thomas Lively2022-10-251-2/+36
| | | | | | | | | Unlike in the legacy parser, we cannot depend on the folded text format to determine how many values to return, so we determine that solely based on the current function context. To handle multivalue return correctly, fix a bug in which we could synthesize new `unreachable`s and place them before existing unreachable instructions (like returns) at the end of instruction sequences.
* [NFC] Remove an ancient hack in ReFinalize (#5183)Alon Zakai2022-10-242-11/+0
| | | | | | | | | | | | Poking in the git history, this was some kind of hack for a problem that appears to no longer exist since at least 5 years ago. Logically, refinalize should never change a type from unreachable to none, or at least if we have a place that does this, we should manually do the necessary things around that, like updating the function's return type. The opposite, none (or anything else) to unreachable is the common case, where we use refinalize to propagate that type upwards. Fuzzing also finds no issues.
* [NFC] Inherit from Visitor in OverriddenVisitor (#5182)Alon Zakai2022-10-241-17/+1
| | | | | | | | | | | | | Doing so shortens the code by removing duplicate logic. Also this will avoid a compile error in a future PR, as by inheriting from Visitor we include functions like visitFunction which were otherwise missing from OverriddenVisitor. We could duplicate those like we duplicated the expression logic, but just removing all the duplication seems best. I manually verified OverriddenVisitor still provides the same error messages as before.
* [Parser][NFC] Combine InstrParserCtx into ParseDefsCtx (#5179)Thomas Lively2022-10-211-302/+312
| | | | | ParseDefsCtx was the only client of the CRTP InstrParserCtx utility and the separation between the two did not serve a real purpose. Simplify the code by combining them.
* [Parser] Parse `memory.copy` and `memory.fill` (#5178)Thomas Lively2022-10-211-2/+42
|
* [Wasm GC] Support BrOn* in CodePushing (#5177)Alon Zakai2022-10-211-2/+2
|
* [Parser] Parse loads and stores (#5174)Thomas Lively2022-10-215-95/+329
| | | | | | | | | | Add parsing functions for `memarg`s, the offset and align fields of load and store instructions. These fields are interesting because they are lexically reserved words that need to be further parsed to extract their actual values. On top of that, add support for parsing all of the load and store instructions. This required fixing a buffer overflow problem in the generated parser code and adding more information to the signatures of the SIMD load and store instructions. `SIMDLoadStoreLane` instructions are particularly interesting because they may require backtracking to parse correctly.
* [Wasm GC] Externalize/Internalize allow nulls (#5175)Alon Zakai2022-10-211-0/+6
| | | | | These are encoded as RefAs operations, and we have optimizations that assume those trap on null, but Externalize/Internalize do not. Skip them there to avoid an error on the type being incorrect later.
* [Parser] Parse shared memory declarations (#5173)Thomas Lively2022-10-212-14/+20
|
* [NFC] Avoid re-parsing instruction names (#5171)Thomas Lively2022-10-204-323/+237
| | | | | | | | | Since gen-s-parser.py is essentially a giant table mapping instruction names to the information necessary to construct the corresponding IR nodes, there should be no need to further parse instruction names after the code generated by gen-s-parser.py runs. However, memory instruction parsing still parsed instruction names to get information such as size and default alignment. The new parser does not have the ability to parse that information out of instruction names, so put it in the gen-s-parser.py table instead.
* Traverse data segments in walkModuleCode (#5169)Alon Zakai2022-10-201-0/+5
| | | | | This wasn't noticed since we apparently only use module code scanning to find stuff like function references atm (which can't be in a data segment). But newer passes will need to scan everything (#5163).
* Remove excessive validation that is not in the wasm spec (#5167)Alon Zakai2022-10-201-28/+1
| | | | | | | | Specifically if a segment offset was a const, we checked that it made sense. But the wasm spec doesn't do that, and it actually causes some issues (#5163). In theory this extra validation might be useful - compile-time error rather than runtime - but if we want this it should probably be an optional thing, like an opt-in flag or a --lint pass or such.
* [NFC] Add nullptr init for ElementSegment offset (#5168)Alon Zakai2022-10-201-1/+1
| | | | | I believe all locations that create one already set it (or else we'd see errors), but it's not easy to see that when reading the code. And other similar locations (like DataSegment) do initialize to null, so do so for consistency.
* [Parser] Parse `memory.size` and `memory.grow` (#5165)Thomas Lively2022-10-202-8/+80
| | | | | Also add the ability to parse memory indexes to correctly handle the multi-memory versions of these instructions. Add and use a conversion from `Result` to `MaybeResult` as well.
* [Parser] Parse memories (#5164)Thomas Lively2022-10-191-23/+204
| | | | | | | Parse 32-bit and 64-bit memories, including their initial and max sizes. Shared memories are left to a follow-up PR. The memory abbreviation that includes inline data is parsed, but the associated data segment is not yet created. Also do some minor simplifications in neighboring helper functions for other kinds of module elements.
* [NFC] Add a generic hash implementation for tuples (#5162)Thomas Lively2022-10-192-5/+22
| | | | | We already provided a specialization of `std::hash` for arbitrary pairs, so add one for `std::tuple` as well. Use the new specialization where we were previously using nested pairs just to be able to use the pair specialization.
* [NFC] Remove obsolete `makePush` functions (#5159)Thomas Lively2022-10-192-7/+0
| | | `Push` expressions were removed in #2867, so we no longer need to make them.
* [Parser] Parse SIMD ternary expressions and shifts (#5158)Thomas Lively2022-10-191-2/+22
|
* [Wasm GC] Use Cones in GUFA data reads and writes (#5157)Alon Zakai2022-10-192-78/+88
| | | | | | | | | | | When we read from a struct/array using a cone type, read from the types in the cone and nothing else. Previously we used the declared type in the wasm, which might be larger (both in the base type and the depth). Likewise, in a write. To do this, this extends ConeReadLocation with a depth (previously the depth there was assumed to be infinite, and now it is to a potentially limited depth). After this we are fully utilizing cone types in GUFA, as the test changes show (or at least I can't think of any other uses of cones).
* [C API] Align I31ref and Dataref to be nullable (#5153)dcode2022-10-191-2/+2
| | | The C API still returned non nullable types for `dataref` (`ref data` instead of `ref null data`) and `i31ref` (`ref i31` instead of `ref null i31`). This PR aligns with the current state of the GC proposal, making them nullable when obtained via the C API.
* [Parser] Parse SIMD lane manipulation instructions (#5156)Thomas Lively2022-10-191-5/+58
| | | Including all `SIMDExtract`, `SIMDReplace`, `SIMDShuffle` expressions.
* [Parser] Parse global.get and global.set (#5155)Thomas Lively2022-10-191-15/+75
| | | | Also add some missing error checking for the similar local instructions and make some neighboring styling more consistent.
* [Wasm GC] [NFC] Remove .type checks from GUFA that are not needed with ↵Alon Zakai2022-10-181-10/+4
| | | | | modern nulls (#5154) Modern nulls never compare equal unless they have the same type too.
* [Wasm GC] Filter GUFA expression locations by their type (#5149)Alon Zakai2022-10-181-17/+132
| | | | | | | | | | | | | | | | | Now that we have a cone type, we are able to represent in PossibleContents the natural content of a wasm location: a type or any of its subtypes. This allows us to enforce the wasm typing rules, that is, to filter the data arriving at a location by the wasm type of the location. Technically this could be unnecessary if we had full implementations of flowFoo and so forth, that is, tailored code for each wasm expression that makes sure we only contain and flow content that fits in the wasm type. Atm we don't have that, and until the wasm spec stabilizes it's probably not worth the effort. Instead, simply filter based on the type, which gives the same result (though it does take a little more work; I measured it at 3% or so of runtime). While doing so normalize cones to their actual maximum depth, which simplifies things and will help more later as well.
* [C API] Add bottom heap types and array heap type (#5150)dcode2022-10-182-0/+31
| | | Adds `BinaryenHeapTypeNone`, `BinaryenHeapTypeNoext` and `BinaryenHeapTypeNofunc` to obtain the bottom heap types. Also adds `BinaryenHeapTypeIsBottom` to test whether a given heap type is a bottom type, and `BinaryenHeapTypeGetBottom` to obtain the respective bottom type given a heap type.
* [NFC] Add namespacing to wasm-features.h (#5152)Alon Zakai2022-10-181-0/+4
|
* Parse and emit `array.len` without a type annotation (#5151)Thomas Lively2022-10-185-17/+15
| | | Test that we can still parse the old annotated form as well.
* Implement `array` basic heap type (#5148)Thomas Lively2022-10-1812-46/+125
| | | | | | | | | `array` is the supertype of all defined array types and for now is a subtype of `data`. (Once `data` becomes `struct` this will no longer be true.) Update the binary and text parsing of `array.len` to ignore the obsolete type annotation and update the binary emitting to emit a zero in place of the old type annotation and the text printing to print an arbitrary heap type for the annotation. A follow-on PR will add support for the newer unannotated version of `array.len`.
* Exhaustively test basic heap type relationships (#5147)Thomas Lively2022-10-171-4/+3
| | | | | | As the number of basic heap types has grown, the complexity of the subtype and LUB calculations has grown as well. To ensure that they are correct, test the complete matrix of basic types and trivial user-defined types. Fix the subtype calculation to make string types subtypes of `any` to make the test pass.
* Binary format: Don't emit empty Memory sections (#5145)Alon Zakai2022-10-171-1/+1
| | | | If the only memories are imported, we don't need the section. We were already doing that for tables, functions, etc.
* [Wasm GC][GUFA] Avoid Many in roots (#5142)Alon Zakai2022-10-132-8/+36
| | | Instead of Many, use a proper Cone Type for the data, as appropriate.
* [Parser] Validate type annotations on `select` (#5139)Thomas Lively2022-10-131-1/+5
| | | | | Since the type annotations are not stored explicitly in Binaryen IR, we have to validate them in the parser. Implement this and fix a newly-caught incorrect annotation in the tests.
* Add "struct" and "structref" as an alias for "data" and "dataref" (#5141)Thomas Lively2022-10-131-2/+4
| | | | | | | In the upstream spec, `data` has been replaced with a type called `struct`. To allow for a graceful update in Binaryen, start by introducing "struct" as an alias for "data". Once users have stopped emitting `data` directly, future PRs will remove `data` and update the subtyping so that arrays are no longer subtypes of `struct`.