summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* Remove function index printing (#2742)Thomas Lively2020-04-093-63/+53
| | | | | | | | `BinaryIndexes` was only used in two places (Print.cpp and wasm-binary.h), so it didn't seem to be a great fit for module-utils.h. This change moves it to wasm-binary.h and removes its usage in Print.cpp. This means that function indexes are no longer printed, but those were of limited utility and were the source of annoying noise when updating tests, anyway.
* Performance optimizations for Type (#2733)Thomas Lively2020-04-093-30/+57
| | | | | | | Cache type sizes in unused bits from the type ID and rewrite some Type methods to avoid unnecessary calls to `expand` when the type is known to be a basic non-tuple type. This eliminates most of the locking traffic and reduces wall clock time by 52% and CPU time by 73% percent for one real-world program on my machine.
* Fix an old misleading comment (#2738) [ci skip]Alon Zakai2020-04-091-2/+2
|
* Avoid g$ in main modules where possible (#2721)Alon Zakai2020-04-081-1/+28
| | | | | | | | | | We realized it is not valid to do these f$, g$ optimizations in main and side modules, as a symbol might appear in both (like RTTI or a weak symbol). We do need one of the appearances to "win". This does the g$ optimization in main modules only, that is, if a global appears in a main module then we can avoid a g$ import and instead compute its location directly in the module, since we will "win" over other modules with the same symbol anyhow.
* Run reorder-locals more in wasm2js (#2729)Alon Zakai2020-04-082-0/+6
| | | | | | | | | | | coalesce-locals is nonlinear in the number of locals, so it is greatly beneficial to reorder the locals (which then drops the unused ones at the end automatically). The default passes do this already, but wasm2js does some custom work, and this was missing. With this change that pass takes 10x less time on poppler with --flatten --flatten --simplify-locals-notee-nostructure which approximates what wasm2js does.
* Fix ReorderLocals handling of local names (#2728)Alon Zakai2020-04-081-2/+3
| | | | | I think the history here is that localNames used to be a vector, then we made it a map, but didn't update this pass... so in rare cases it could end up emitting wrong stuff.
* Work around a compiler issue on MacOS (#2730)Alon Zakai2020-04-081-7/+8
| | | | | | | | | | | | | | | | | | The post-commit Mac bot on github failed to compile #2727 with Undefined symbols for architecture x86_64: "wasm::ReorderLocals::UNSEEN", referenced from: wasm::ReorderLocals::doWalkFunction(wasm::Function*) in ReorderLocals.cpp.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) That seems odd, it's defined like this? static const Index UNSEEN = -1; Perhaps we are hitting a weird compiler bug. Anyhow, just use an enum to be safe. Also for clarity switch to 0 for the unseen value.
* Optimize ReorderLocals maps to vectors (#2727)Alon Zakai2020-04-071-8/+21
| | | | | | | | The original code here is quite old and I guess we assumed that it was ok to use maps for this, but on really huge amounts of locals it ends up mattering a lot. This makes the pass 3x faster on poppler after --flatten --flatten (double flatten creates lots of new locals, and is generally similar to what wasm2js does).
* Only do fp$ optimization in the main module (#2720)Alon Zakai2020-04-071-7/+11
| | | | | | | | Weak symbols and interposition etc. mean that we should not replace an fp$ call with a symbol from the module itself if there is a chance there is another symbol that would have overridden it. In side modules this risk exists and so this PR makes us stop doing that. In main modules it is ok because they are loaded first and so any symbol they provide will "win" over others anyhow.
* JS/Wasm BigInt support for wasm-emscripten-finalize (#2726)Alon Zakai2020-04-071-2/+10
| | | | | If wasm-emscripten-finalize is given the BigInt flag, then we will be using BigInts on the JS side, and need no legalization at all since i64s will just be BigInts.
* Do not emit multivalue events in fuzzer (#2723)Thomas Lively2020-04-031-2/+3
| | | | | | Unless the multivalue feature is enabled. The validation for events recently changed to disallow events returning multiple items unless the multivalue feature is enabled, but the fuzzer was not updated accordingly. This PR fixes the glitch.
* Tuple globals (#2718)Thomas Lively2020-04-0212-61/+120
| | | | | | | Since it wasn't easy to support tuples in Asyncify's call support using temporary functions, we decided to allow tuple-typed globals after all. This PR adds support for parsing, printing, lowering, and interpreting tuple globals and also adds validation ensuring that imported and exported globals do not have tuple types.
* Revert to using globals in Asyncify call support (#2719)Thomas Lively2020-04-011-71/+53
| | | | | | | | This reverts commit 5ddda8d2e6a3287ff6adcd69493e1e1c8b6c3872. We decided it would be easier to allow tuple-typed globals than to make calls work here after all. Reverts that change, but keeps small improvements it made for clarity.
* Avoid unnecessary fp$ in side modules (#2717)Alon Zakai2020-03-313-41/+55
| | | | | | | | | | | | | | | | Now that we update the dylink section properly, we can do the same optimization in side modules as in main ones: if the module provides a function, don't call an $fp method during startup, instead add it to the table ourselves and use the relative offset to the table base. Fix an issue when the table has no segments initially: the code just added an offset of 0, but that's not right. Instead, an a __table_base import and use that as the offset. As this is ABI-specific I did it on wasm-emscripten-finalize, leaving TableUtils to just assert on having a singleton segment. Add a test of a wasm file with a dylink section to the lld tests.
* Represent dylink section in IR, so we can update it. (#2715)Alon Zakai2020-03-305-15/+86
| | | | Update it from wasm-emscripten-finalize when we append to the table.
* Error out when EH is used in unsupported code (#2713)Heejin Ahn2020-03-273-0/+11
| | | | | This calls `Fatal()` when EH instructions are used in unsupported code. Currently EH instructions are unsupported in Flatten, ReReloop, and DataFlow-using passes.
* Avoid fp$ access in MAIN_MODULES (#2704)Alon Zakai2020-03-277-24/+98
| | | | | | | | | | | | | | | | Depends on emscripten-core/emscripten#10741 which ensures that table indexes are unique. With that guarantee, a main module can just add its function pointers into the table, and use them based on that index. The loader will then see them in the table and then give other modules the identical function pointer for a function, ensuring function pointer equality. This avoids calling fp$ functions during startup for the main module's own functions (which are slow). We do still call fp$s of things we import from outside, as we don't have anything to put in the table for them, we depend on the loader for that. I suspect this can also be done with SIDE_MODULES, but did not want to try too much at once.
* Tuple operations in C and JS APIs (#2711)Thomas Lively2020-03-263-66/+174
| | | | Adds functions for creating and inspecting tuple.make and tuple.extract expressions in the C and JS APIs.
* Convert Asyncify fake globals to fake calls. NFC (#2706)Alon Zakai2020-03-251-46/+71
| | | | | This will be easier to extend for tuples. Also add more clarifying comments.
* Disallow tuples in MVP (#2707)Thomas Lively2020-03-242-1/+11
| | | | | | | | | Previously the multivalue feature enabled tuples in control flow positions, but tuples elsewhere did not require the multivalue feature. However, allowing tuple operations and locals in MVP modules means that all passes and tools need to support tuples, even if it isn't a high priority for them to support multivalue. Allowing tuples in MVP modules doesn't provide much value, so this changes disallows them entirely unless multivalue is enabled.
* Fix Event section ordering (#2708)Thomas Lively2020-03-241-1/+1
| | | The version of V8 pulled in by JSVU recently updated to expect the new ordering of the event section, so this PR should fix the CI.
* Allow subtypes in tuple operations (#2700)Thomas Lively2020-03-231-10/+13
| | | | | | Some optimizations may replace tuple elements with simpler values, and those simpler values may be a subtype of the original value. Tuple operations should continue to validate without being refinalized in these cases.
* SIMD integer abs and bitmask instructions (#2703)Thomas Lively2020-03-2015-12/+204
| | | | | | Adds full support for the {i8x16,i16x8,i32x4}.abs instructions merged to the SIMD proposal in https://github.com/WebAssembly/simd/pull/128 as well as the {i8x16,i16x8,i32x4}.bitmask instructions proposed in https://github.com/WebAssembly/simd/pull/201.
* Emit unreachable tuple.make properly (#2701)Thomas Lively2020-03-181-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We previously thought unreachable `tuple.make` instructions did not require special unreachable handling, but consider the following wast: ``` (module (func $foo (tuple.make (unreachable) (i32.const 42) ) ) ) ``` This validates because the only expression in the body is unreachable, but when it is emitted as a binary it becomes ``` unreachable i32.const 42 ``` This does not validate because it ends with an i32, but the function expected an empty stack at the end. The fix is to emit an extra `unreachable` after unreachable `tuple.make` instructions. Unfortunately it is impossible to write a test for this right now because the binary parser silently drops the `i32.const 42`, making the function valid again.
* Support tuple locals in Asyncify (#2696)Thomas Lively2020-03-172-49/+70
| | | Iterate over tuple locals and separately load or store each component.
* makeConstExpression => makeConstantExpression (#2698)Alon Zakai2020-03-175-10/+12
| | | | | | The meaning we intend is "constant", and not the "Const" node (which contains a number). So I think the full name is less confusing.
* Fix binary emitting of signature indices (#2694)Thomas Lively2020-03-162-1/+4
| | | | | It should be a signed LEB128, not an unsigned LEB128. This bug was causing modules to be invalid when the number of signatures in the type section was large and multivalue blocks were present.
* Handle tuples in RemoveUnusedBrs (#2693)Thomas Lively2020-03-161-2/+6
| | | | | RemoveUnusedBrs produces selects for some patterns, but selects of multivalue types are not valid. This change checks that types are not tuple types before producing selects.
* Collect signatures from all block kinds (#2691)Thomas Lively2020-03-165-15/+32
| | | | | | | | | Previously the signature collection mechanism responsible for populating the type section with signatures used by instructions only collected signatures from indirect call and block instructions. This works as long as all other control flow constructs like ifs, loops, and tries contain blocks with the same signature. But it is possible to have an if with non-block children, and we would need to collect its signature as well.
* Interpret tuple locals and tail-calls correctly (#2690)Thomas Lively2020-03-162-40/+16
|
* Handle tuples in wasm-reduce (#2689)Thomas Lively2020-03-162-5/+26
| | | | Also increases the usefulness of a couple wasm-builder methods that are useful here.
* Handle unreachable in TupleExtract::finalize (#2692)Thomas Lively2020-03-161-1/+7
|
* Update RedundantSetElimination to work with tuples (#2688)Thomas Lively2020-03-112-2/+29
| | | | | | | | Also makes it work with any other constant expression such as a ref.func or ref.null instructions. This optimization may not be very important, but it illustrates how simple it can be to update a pass to handle tuples (and also I was already looking at it because of the prior changes that had to be made to it).
* Update Precompute to handle tuples (#2687)Thomas Lively2020-03-1012-65/+118
| | | | | | This involves replacing `Literal::makeZero` with `Literal::makeZeroes` and `Literal::makeSingleZero` and updating `isConstantExpression` to handle constant tuples as well. Also makes `Literals` its own struct and adds convenience methods on it.
* Handle multivalue returns in the interpreter (#2684)Thomas Lively2020-03-1012-104/+169
| | | | Updates the interpreter to properly flow vectors of values, including at function boundaries. Adds a small spec test for multivalue return.
* Add a non-const iterator to SmallVector (#2685)Thomas Lively2020-03-101-15/+22
| | | Using CRTP, yay!
* Add 'warning:' to names section warning. Helps #2680 (#2683)Alon Zakai2020-03-091-1/+1
|
* Asyncify: Fix wasm-only instrumentation of unnamed imports (#2682)Alon Zakai2020-03-052-24/+40
| | | | | | | | | | | | | We assumed that the imports were already named (in their internal name) properly. When processing a binary file without names, or if the names don't match in general, that's not true. To fix this, use ModuleUtils::renameFunctions to do a proper renaming up front. Also fix renameFunctions to not assert on the case of renaming a function to the same name it already has. Helps #2680
* Initial multivalue support (#2675)Thomas Lively2020-03-0525-166/+672
| | | | | | | | | Implements parsing and emitting of tuple creation and extraction and tuple-typed control flow for both the text and binary formats. TODO: - Extend Precompute/interpreter to handle tuple values - C and JS API support/testing - Figure out how to lower in stack IR - Fuzzing
* DWARF: Ignore a compile unit with no abbreviations (#2678)Alon Zakai2020-03-041-1/+1
| | | | | | | | | | Such a module can't have valid DIEs, since we have no way to interpret them. Also check if DWARF sections from LLVM have contents - when they are empty the section may exist but have a null for its data. Fixes #2673
* Expose asyncify state via a getter (#2679)Alon Zakai2020-03-041-1/+16
| | | | | | | | | | Normally, a wrapper has to track state separately to know when to unwind/rewind and when to actually call import functions. Exposing Asyncify state can help avoid this duplication and avoid subtle bugs when internal and wrapper state get out of sync. Since this is a tiny function and it's useful for any Asyncify embedder, I've decided to expose it by default rather than hide behind an option.
* Improve a comment on unreachability [ci skip] (#2672)Alon Zakai2020-03-031-2/+13
|
* Simplify binary block parsing (#2674)Thomas Lively2020-02-282-37/+24
|
* Generalize binary writing for tuples (#2670)Thomas Lively2020-02-272-91/+26
| | | | | | | | | Updates `BinaryInstWriter::mapLocalsAndEmitHeader` so it no longer hardcodes each possible local type. Also adds a new inner loop over the elements of any local tuple type in the IR. Updates the map from IR local indices to binary indices to be additionally keyed on the index within a tuple type. Since we do not generate tuple types yet, this additional index is hardcoded to zero everywhere it is used for now. A later PR adding tuple creation operations will extend this functionality and add tests.
* Add multivalue feature (#2668)Thomas Lively2020-02-278-27/+22
|
* Add EH support for CodeFolding (#2665)Heejin Ahn2020-02-262-0/+35
| | | | | | | | | | | This does two things: - Treats the target branch of `br_on_exn` as unoptimizables, because it is a conditional branch. - Makes sure we don't move expressions that contain `exnref.pop`, which should follow right after `catch`. - Adds `containsChild` utility function, which can search all children, optionally with limited depth. This was actually added to be used in CodeFolding but ended up not being used, but wasn't removed in case there will be uses later.
* Fix to https://github.com/WebAssembly/binaryen/issues/2170 (#2654)juj2020-02-251-0/+6
| | | | | | | | * Fix to https://github.com/WebAssembly/binaryen/issues/2170 * Adjust fix * clang-format
* Add AutoDrop support for Try (#2663)Heejin Ahn2020-02-202-0/+17
| | | | | This adds AutoDrop (+ ReFinalize) support for Try. We don't have `--autodrop` option so I can't add a separate test for this, but this is basically the same as what If does.
* Add the GetFunctionTable JS API (#2554)COFFEETALES2020-02-203-2/+88
|
* Add br_on_exn support for UniqueNameMapper (#2659)Heejin Ahn2020-02-191-0/+3
| | | | This adds support for UniqueNameMapper, and adds a test in Inlining pass, which uses UniqueNameMapper.