summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* [GC] Small fuzz fixes for GC (#3540)Alon Zakai2021-02-031-35/+49
| | | | | | | | * Fix label fixup code to use delegates-fields. This makes it support BrOn etc. * Add an isRtt() in places RTTs are not supported. * Implement makeConst for arbitrary RTTs. This is enough to get the fuzzer working for more than a few iterations at a time, but no more.
* [GC] Feedback for #3536 (#3539)Alon Zakai2021-02-021-5/+5
|
* Support Stack IR for new try-catch(_all) (#3538)Heejin Ahn2021-02-033-12/+43
| | | | | This adds missing stack IR printing support for the new form of try-catch-catch_all. Also uses `printMedium` when printing instructions consistently.
* [GC] dataref typing fixes (#3536)Alon Zakai2021-02-031-18/+29
| | | | | | | dataref was not noted as isRef, and we also did not handle the LUB for it, which caused validation errors. After these two fixes, it is possible to add a testcase that goes through the optimizer. View without whitespace as the LUB change has a lot of that.
* Allow printing expressions based on feature set (#3537)Abbas Mashayekh2021-02-021-68/+83
| | | | | | | | | | As discussed in #3517, we need a way to maintain the ability to print expressions in a backward-compatible way. This adds a FeatureSet to PrintExpressionContents which defaults to FeatureSet::All in case a feature set is not available. This will be used for CallIndirect to decide whether to print the table name arg.
* Prototype i32x4.widen_i8x16_{s,u} (#3535)Thomas Lively2021-02-0116-1/+123
| | | | | | | | As proposed in https://github.com/WebAssembly/simd/pull/395. Note that the other instructions in the proposal have not been implemented in LLVM or in V8, so there is no need to implement them in Binaryen right now either. This PR introduces a new expression class for the new instructions because they uniquely take an immediate argument identifying which portion of the input vector to widen.
* [GC] isGCData => isData (#3534)Alon Zakai2021-02-015-21/+43
| | | | | | | | | We added isGCData() before we had dataref. But now there is a clear parallel of Function vs Data. This PR makes us more consistent there, renaming isGCData to isData and using that throughout. This also fixes a bug where the old isGCData just checked if the input was an Array or a Struct, and ignored the data heap type itself. It is not possible to test that, however, due to other bugs, so that is deferred.
* [GC] br_on_null (#3528)Alon Zakai2021-02-018-9/+51
| | | | | | | | | | | This is only partial support, as br_on_null also has an extra optional value in the spec. Implementing that is cumbersome in binaryen, and there is ongoing spec discussions about it (see https://github.com/WebAssembly/function-references/issues/45 ), so for now we only support the simple case without the default value. Also fix prefixed opcodes to be LEBs in RefAs, which was noticed here as the change here made it noticeable whether the values were int8 or LEBs.
* [GC] Don't emit i31ref in fuzzer (#3531)Alon Zakai2021-02-011-11/+10
| | | | | | | That type is non-nullable, so we need to disable it until we fully support that. Right now if we emit such locals we immediately get a validation error. With this change the fuzzer can run at least a few thousand iterations with no errors once more.
* Remove unnecessary breakStack pushes for if/try (NFC) (#3533)Heejin Ahn2021-02-021-9/+0
| | | | | | This break stack is maintained to compute branch depths, but it seems we don't need to push and pop for each of if and else block or every single catch/catch_all block; it would be sufficient to have just one stack entry for the whole try-catch or if-else.
* Don't error out when EH is used for Flatten (#3526)Heejin Ahn2021-01-291-4/+0
| | | | | | | We used to error out in Flatten when EH is used because Flatten makes all block types `none` by setting their return values to locals and getting them later, but `br_on_exn` by definition pops value from the value stack at the end of a block so it couldn't be flattened. Now that we don't have `br_on_exn` we don't need these restriction.
* [GC] ref.as_non_null (#3527)Alon Zakai2021-01-288-0/+24
| | | | | | This is different than the other RefAs variants in that it is part of the typed functions proposal, and not GC. But it is part of GC prototype 3. Note: This is not useful to us yet as we don't support non-nullable types.
* [GC] Add br_on_func/data/i31 (#3525)Alon Zakai2021-01-2820-70/+204
| | | | | | | | This expands the existing BrOnCast into BrOn that can also handle the func/data/i31 variants. This is not as elegant as RefIs / RefAs in that BrOnCast has an extra rtt field, but I think it is still the best option. We already have optional fields on Break (the value and condition), so making rtt optional is not odd. And it allows us to share all the behavior of br_on_* which aside from the cast or the check itself, is identical - returning the value if the branch is not taken, etc.
* [GC] Update br_on_cast: the text format also no longer has a heap type (#3523)Alon Zakai2021-01-278-25/+19
| | | | | | | As a result, we cannot handle a br_on_cast with an unreachable RTT. The binary format solves the problem by ignoring unreachable code, and this makes the text format do the same. A nice benefit of this is that we can remove the castType extra field.
* Memcpy data instead of bytewise copies (#3521)Philip Pfaffe2021-01-272-19/+23
| | | | | | wasm-finalize currently makes byte-wise copies of section data in the user and data sections. If the section is large, that's extraordinarily expensive. With a memcpy instead I see a speedup of 1.6 for a large wasm binary with DWARF data.
* Simplfy getExpressionName (#3522)Alon Zakai2021-01-275-164/+20
| | | | | | | | | | This used to return a simple name like "if" for an If, but it is redundant with our proper printing logic. This PR turns it into a trivial helper that just prints out the name of the class, so it now prints "If" with a capital. That is useful for some logging, like in Metrics I think it is clearer than it was earlier (since we are actually counting the classes, and our old emitting of text-format-like names are just confusing, as we emitted "binary" there which is not valid). Also replace some usages of that method with proper printing.
* [GC] ref.as_* (#3520)Alon Zakai2021-01-2717-2/+195
| | | | | | | | These are similar to is, but instead of returning an i32 answer, they trap on an invalid value, and return it otherwise. These could in theory be in a single RefDoThing, with opcodes for both As and Is, but as the return values are different, that would be a little odd, and the name would be less clear.
* [GC] ref.is_func/data/i31 (#3519)Alon Zakai2021-01-2613-14/+93
|
* [GC] RefIsNull => RefIs. (#3516)Alon Zakai2021-01-2622-63/+115
| | | | | | | | This internal refactoring prepares us for ref.is_func/data/i31, by renaming the node and adding an "op" field. For now that field must always be "Null" which means it is a ref.is_null. This adjusts the C API to match the new IR shape. The high-level JS API is unchanged.
* Warn when running a pass not compatible with DWARF (#3506)Alon Zakai2021-01-2612-93/+135
| | | | | | | | | | | | Previously the addDefault* methods would avoid adding opt passes that we know are incompatible with DWARF. However, that didn't handle the case of passes that are added in other ways. For example, when running Asyncify, emcc will run --flatten before, and that pass is not compatible with DWARF. This PR lets us warn on that by annotating the passes themselves. Then we use those annotation to either not run a pass at all (matching the previous behavior) or to show a warning when necessary. Fixes emscripten-core/emscripten#13288 . That is, concretely after this PR running asyncify + DWARF will show a warning to the user.
* Debug info handling for new EH try-catch (#3496)Alon Zakai2021-01-257-45/+85
| | | | | | | | We now have multiple catches in each try, and a possible catch-all. This changes our "extra delimiter" storage to store either an "else" (unchanged from before) or an arbitrary list of things - we use that for catches.
* Reorder i31ref and dataref (#3509)Heejin Ahn2021-01-2315-69/+78
| | | | | | | | | | The binary spec (https://docs.google.com/document/d/1yAWU3dbs8kUa_wcnnirDxUu9nEBsNfq0Xo90OWx6yuo/edit#) lists `dataref` after `i31ref`, and `dataref` also comes after `i31ref` in its binary code in the value-increasing order. This reorders these two in wasm-type.h and other places, although in most of those places the order is irrelevant. This also adds C and JS API for `dataref`.
* [GC] Update GC binary format for prototype v3 (#3507)Alon Zakai2021-01-222-16/+0
| | | | | Some fields were removed, see https://docs.google.com/document/d/1yAWU3dbs8kUa_wcnnirDxUu9nEBsNfq0Xo90OWx6yuo/edit#
* Remove exnref and br_on_exn (#3505)Heejin Ahn2021-01-2246-557/+14
| | | This removes `exnref` type and `br_on_exn` instruction.
* [GC] Add dataref type (#3500)Alon Zakai2021-01-2122-6/+122
| | | | | This is not 100% of everything, but is enough to get tests passing, which includes full binary and text format support, getting all switches to compile without error, and some additions to InstrumentLocals.
* Update interpreter for new EH spec (#3498)Heejin Ahn2021-01-216-41/+63
| | | | | | | | | | | | | This updates the interpreter for the EH instructions (modulo `delegate`) to match the new spec. Before we had an `exnref` type so threw a `Literal` of `exnref` type which contained `ExceptionPackage`. But now that we don't have `exnref` anymore, so we add the contents of `ExceptionPackage` to `WasmException`, which is used only for the `ExpressionRunner` class hierarchy. `exnref` and `ExceptionPackage` will be removed in a followup CL. This allows nonzero depths for `rethrow` for now for testing; we disallowed that for safety measure, but given that there are no passes that modifies that field, I think the risk is low.
* CFG traversal for the new EH spec (#3494)Heejin Ahn2021-01-212-43/+120
| | | | | | | | | | | | | | | | | | | | | | This updates CFG traversal to match the new spec. Previously there was only a single `catch` block that caught all exceptions, so all throwing instructions needed to have a link to its innermost catch BB. But now we can have multiple catches per try, requiring all throwing instrutions to have an edge to all of those innermost catch BBs. Furthermore, if there are only `catch`es and not a `catch_all` in a try, throwing instructions can further unwind to outer catches until they find a `catch_all`. `unwindCatchStack` and `unwindExprStack` are necessary to track and make correct links between throwing instructions and their unwind destination BBs. `processCatchStack` is used to remember the catch BBs currently being processed, so that after processing all of them, we can make a link from each of those catch's last block to the continuation block after the try-catch. RSE test cases are updated because they use the CFG traversal. The tests there mainly test that if all possible CFG edge to a `local.set` sets the same value to a local, the `local.set` is redundant and thus can be removed.
* Simplify set/gets of vectors in binaryen.js (#3495)Heejin Ahn2021-01-201-174/+39
| | | | | This uses existing `getAllNested` function in `ExpressionWrapper` functions. Also adds `setAllNested` which works in the other direction and uses it within `ExpressionWrapper` functions.
* Prototype additional f64x2 conversions (#3501)Thomas Lively2021-01-1910-23/+175
| | | | As proposed in https://github.com/WebAssembly/simd/pull/383, with opcodes coordinated with the WIP V8 prototype.
* wasm-reduce: Fix setting of feature flags after loading (#3493)Alon Zakai2021-01-151-2/+6
| | | | | We mistakenly did not set the flags to all, which meant that if the features section was not present, we'd not have the proper features set, leading to errors on writing.
* wasm-reduce: default to -all, and make it customizable (#3492)Alon Zakai2021-01-151-11/+20
| | | | | | | | | This goes back to the downsides of #2813, but that seems unavoidable as without this, testcases without the features section but that use features did not work. This PR at least makes it easy to customize the flags send to the commands. See also #3393 (comment)
* [GC] Read and lower Let instructions (#3485)Alon Zakai2021-01-152-12/+105
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For now we don't support non-nullability, and can therefore lower a let into simpler things. That is, (let $x = ... ;; ) => (block $x = ... ;; ) This lets us handle wasm binaries with let, so that we can optimize them (with the current downside of losing non-nullability). This is still not trivial to do, sadly, because the indexing of lets is somewhat odd in the binary. A let modifies the indexes of other things declared before it, which means that index "0" means different things at different times. And this is trickier for us because we add more locals as needed for tuples and stacky code. So this PR makes us track the absolute local indexes from which each let started to allocate its locals. The binary testcase was created from this wat using wasp: (module (type $vector (array (field (mut f64)))) (func $main (local $x i32) (local $y i32) (drop (local.get $x)) ;; 0 is the index appearing in the binary ;; first let (array.new_with_rtt $vector (f64.const 3.14159) (i32.const 1) (rtt.canon $vector) ) (let (local $v (ref $vector)) (drop (local.get $v)) ;; 0 (drop (local.get $x)) ;; 1 ;; another one, nested (array.new_with_rtt $vector (f64.const 1234) (i32.const 2) (rtt.canon $vector) ) (let (local $w (ref $vector)) (drop (local.get $v)) ;; 1 (drop (local.get $w)) ;; 0 (drop (local.get $x)) ;; 2 ) ) ;; another one, later (array.new_with_rtt $vector (f64.const 2.1828) (i32.const 3) (rtt.canon $vector) ) (let (local $v (ref $vector)) (drop (local.get $v)) ;; 0 (drop (local.get $x)) ;; 1 ) (drop (local.get $x)) ;; 0 ) )
* Reducer: Improve warning on scripts that ignore the input (#3490)Alon Zakai2021-01-151-9/+20
| | | | | | | | | | | | | The risk the warning checks for is giving the reducer a script that ignores the input. To do so it runs the command in the input, and runs it on a garbage file, and checks if the result is different. However, if the script does immediately fail on the input - because the input is a crash testcase or such - then this does not work, as the result on a garbage input may be the same error. To avoid that, also check what happens on a trivial valid wasm as input. Only show the warning if the result on the original input, on a garbage wasm, and on a trivial wasm, are all the same - in that case, likely the script really is ignoring the input.
* Basic EH instrucion support for the new spec (#3487)Heejin Ahn2021-01-1529-156/+565
| | | | | | | | | | | | | | | | | | | | This updates `try`-`catch`-`catch_all` and `rethrow` instructions to match the new spec. `delegate` is not included. Now `Try` contains not a single `catchBody` expression but a vector of catch bodies and events. This updates most existing routines, optimizations, and tests modulo the interpreter and the CFG traversal. Because the interpreter has not been updated yet, the EH spec test is temporarily disabled in check.py. Also, because the CFG traversal for EH is not yet updated, several EH tests in `rse_all-features.wast`, which uses CFG traversal, are temporarily commented out. Also added a few more tests in existing EH test functions in test/passes. In the previous spec, `catch` was catching all exceptions so it was assumed that anything `try` body throws is caught by its `catch`, but now we can assume the same only if there is a `catch_all`. Newly added tests test cases when there is a `catch_all` and cases there are only `catch`es separately.
* Avoid usedElements around code that modifys that value (#3488)Alon Zakai2021-01-141-6/+6
| | | | | | | | Followup to #3486, I wonder if it isn't a little more clear this way, which avoids the confusion of usedElements being changed while we are using it. In general I think it's best to only use usedElements in the most internal methods, and to call size() otherwise.
* [GC] RTT types are not defaultable (#3489)Alon Zakai2021-01-131-1/+1
| | | See WebAssembly/gc#175
* Fix an index error in ArenaVectorBase (#3486)Heejin Ahn2021-01-141-1/+1
| | | | | | | | Because `resize()` sets `usedElements` to its argument, we were accessing `data[usedElements]`, which can be outside of allocated memory depending the internal state, i.e., `allocatedElements`'s value. It is hard to come up with a test case for this because apparently the failure condition depends on the vector's internal state.
* [GC] Fix casts of non-GC data (#3483)Alon Zakai2021-01-121-2/+10
| | | | | The code previously assumed it could always call getGCData, but that assumes the input is an array or a struct. It could also be an anyref etc. that contains something other than GC data.
* [GC] Add Type::IsDefaultable and use that to do more validation (#3456)Alon Zakai2021-01-113-6/+11
|
* [GC] More HeapType instead of Type (#3475)Alon Zakai2021-01-112-55/+92
| | | | | | | | To handle both nullable and non-nullable i31s and other heap types, we cannot just look at the isBasic case (which is just one of the two). This may fix this issue on the release builder: https://github.com/WebAssembly/binaryen/runs/1669944081?check_suite_focus=true but the issue does not reproduce locally, so I worry it is something else...
* [GC] Fix minor binary format issues of ordering and immediates (#3472)Alon Zakai2021-01-113-29/+26
| | | | | | | | | Noticed by comparing to V8 and Wasp. After this things are almost identical, but there is also at least https://bugs.chromium.org/p/v8/issues/detail?id=11300 Test updates are due to having an instruction with two operands of which one is unreachable. The new order puts the non-unreachable first, so it is not removed by round-tripping through the binary format like before (which removes all unreachable code).
* finalize: remove initializers from metadata output (#3479)Sam Clegg2021-01-113-22/+3
| | | See https://github.com/emscripten-core/emscripten/pull/13208
* Add more verbose logging of an assert that only happens on the release ↵Alon Zakai2021-01-081-1/+6
| | | | | builder for some inexplicable reason (#3477) See #3459
* [GC] Validate that struct.set is to a mutable field. (#3473)Alon Zakai2021-01-081-1/+4
| | | | This required a few test fixes, to ensure we don't have invalid wasts with writes to immutable fields.
* [GC] Fix the opcode of i31 (#3471)Alon Zakai2021-01-081-1/+1
|
* [GC] Fix parsing/printing of ref types using i31 (#3469)Alon Zakai2021-01-077-63/+74
| | | | | | | | | | | | This lets us parse (ref null i31) and (ref i31) and not just i31ref. It also fixes the parsing of i31ref, making it nullable for now, which we need to do until we support non-nullability. Fix some internal handling of i31 where we had just i31ref (which meant we just handled the non-nullable type). After fixing a bug in printing (where we didn't print out (ref null i31) properly), I found some a simplification, to remove TypeName.
* Prototype prefetch instructions (#3467)Thomas Lively2021-01-0617-3/+152
| | | | As proposed in https://github.com/WebAssembly/simd/pull/352, using the opcodes used in the LLVM and V8 implementations.
* Prototype SIMD extending pairwise add instructions (#3466)Thomas Lively2021-01-0517-77/+102
| | | | | | As proposed in https://github.com/WebAssembly/simd/pull/380, using the opcodes used in LLVM and V8. Since these opcodes overlap with the opcodes of i64x2.all_true and i64x2.any_true, which have long since been removed from the SIMD proposal, this PR also removes those instructions.
* Improve C and JS API module inspection features (#3464)Daniel Wirtz2021-01-053-37/+82
| | | | | | * BinaryenGetFunction, BinaryenGetGlobal, BinaryenGetEvent now return NULL if an element does not exist * Adds BinaryenGetExport, BinaryenGetNumGlobals, BinaryenGetGlobalByIndex * Corrects BinaryenGetNumFunctions return type * Adds related descriptions of C API functions
* MemoryPacking: Preserve segment names (#3458)Sam Clegg2020-12-185-18/+44
| | | | | Also, avoid packing builtin llvm segments names so that segments such as `__llvm_covfun` (use by llvm-cov) are preserved in the final output.