summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* Refactor Effects (#2873)Alon Zakai2020-05-292-33/+52
| | | | | | | Avoid special work in analyze(). This lets breakTargets always reflect the breaks that we've seen and that might be external, and we check it in hasSideEffects etc. Also do some internal refactoring and renamings for clarity.
* Flat IR: local.set's value should not be a control flow (#2589)Alon Zakai2020-05-271-4/+10
|
* DeNaN pass (#2877)Alon Zakai2020-05-276-111/+156
| | | | | | This moves the fuzzer de-NaN logic out into a separate pass. This is cleaner and also better since the old way would de-NaN once, but then the reducer could generate code with nans. The new way lets us de-NaN while reducing.
* Fix DWARF location list updating with nonzero compilation unit base addr ↵Paolo Severini2020-05-271-3/+32
| | | | | | | | | | | | | | | | (#2862) In the .debug_loc section the Start/End address offsets in a location list are relative to the address of the compilation unit that refers that location list. There is a problem in function wasm::Debug:: updateLoc(), which compares these offsets with the actual module addresses of expressions and functions, causing the generation of invalid location lists. The fix is not trivial, because the DWARF debug_loc section does not specify which is the compilation unit associated to each location list entry. A simple workaround is to store, in LocationUpdater, a map of location list offsets to the base address of the compilation units referencing them, and that can be easily calculated in updateDIE().
* Flatten fuzz fix with unreachable special-casing (#2876)Alon Zakai2020-05-271-3/+2
| | | | | | | | | The special-casing of unreachable there could lead to bad behavior, where we did nothing to the unreachable and ended up moving something with side effects before it, see testcase in test/passes/flatten_all-features.wast. This emits less efficient code, but only if --dce was not run earlier, so probably not worth optimizing.
* Remove `Push` (#2867)Thomas Lively2020-05-2220-141/+5
| | | | | | Push and Pop have been superseded by tuples for their original intended purpose of supporting multivalue. Pop is still used to represent block arguments for exception handling, but there are no plans to use Push for anything now or in the future.
* Remove stackSave/stackAlloc/stackRestore code generation (#2852)Sam Clegg2020-05-203-165/+43
| | | | | | | These are now implemented in assembly as part of emscripten's compiler-rt. See: https://github.com/emscripten-core/emscripten/pull/11166
* Add EH support for SimplifyLocals (#2858)Heejin Ahn2020-05-192-5/+15
| | | | | | | - `br_on_exn`'s target block cannot be optimized to have a separate return value. This handles that in `SimplifyLocals`. - `br_on_exn` and `rethrow` can trap (when the arg is null). This handles that in `EffectAnalyzer`. - Fix a few nits
* Implement i64x2.mul (#2860)Thomas Lively2020-05-1914-1/+31
| | | | This is the only instruction in the current spec proposal that had not yet been implemnented in the tools.
* [dwarf] Handle a bad mapped base in debug_loc updating (#2859)Alon Zakai2020-05-181-3/+17
| | | | Turns out we had a testcase for this already, but were doing the wrong thing on it.
* Don't warn 'skipping debug location info' (#2855)Alon Zakai2020-05-151-4/+0
| | | | | | That is only for the old source maps logic, not DWARF, and it is only useful to debug source maps (it's not actually useful for regular users that see the message) which we do not plan to do since DWARF is the future.
* Fix br_on_exn handling in ReFinalize (#2854)Heejin Ahn2020-05-152-24/+20
| | | | | | | | | | | | In `ReFinalize`'s branch handling, `updateBreakValueType` is supposed to be executed only when the branch itself is not replaced with its argument (because it is guaranteed not to be taken). Also this moves `visitBrOnExn` from `RuntimeExpressionRunner` to its base class `ExpressionRunner`, because it does not depend on anything on the runtime instance to work. This is effectively NFC for now because `visitTry` is still only implemented only in `RuntimeExpressionRunner` because it relies on multivalue handling of it, and without it we cannot create a valid exception `Literal`.
* Skip generating emscripten stack functions if they already exist (#2853)Sam Clegg2020-05-141-0/+9
| | | | This should allow https://github.com/emscripten-core/emscripten/pull/11166 to land, afterwhich we can completely remove these functions.
* Make 'do' clause mandatory in 'try' (#2851)Heejin Ahn2020-05-141-8/+7
| | | | | | | | | | | | | | Previously we were able to omit the new syntax `do` when `try` body is empty. This makes `do` clause mandatory, so when a `try` body is empty, the folded text format will be ``` (try (do) (catch ... ) ``` Suggested in https://github.com/WebAssembly/exception-handling/issues/52#issuecomment-626696720.
* Add EH support in MergeBlocks (#2848)Heejin Ahn2020-05-131-1/+22
| | | | | | | This adds support for `throw`, `rethrow`, and `br_on_exn` in MergeBlocks. While unrelated instructions within blocks can be hoisted as in other instructions, `br_on_exn` requires a special handling in `ProblemFinder`, because unlike `br_if`, its `exnref` argument itself cannot be moved out of `br_on_exn`.
* Implement pseudo-min/max SIMD instructions (#2847)Thomas Lively2020-05-1214-0/+156
| | | As specified in https://github.com/WebAssembly/simd/pull/122.
* Add C/JS APIs to copy expressions (#2840)Daniel Wirtz2020-05-113-0/+10
| | | | | | This API enables use cases where we want to keep the original expression, yet utilize passes like `vacuum` or `precompute` to evaluate it without implicitly modifying the original. C-API: **BinaryenExpressionCopy**(expr, module) JS-API: **Module#copyExpression**(expr)
* Make try body start with 'do' (#2846)Heejin Ahn2020-05-113-7/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | In WebAssembly/exception-handling#52, We decided to put `try` bodies in a `do` clause to be more consistent with `catch`. - Before ```wast (try ... (catch ... ) ) ``` - After ```wast (try (do ... ) (catch ... ) ) ``` Another upside of this change is when there are multiple instructions within a `try` body, we no longer need to wrap them in a `block`.
* Handle throw and rethrow in DCE (#2844)Heejin Ahn2020-05-111-8/+12
| | | | This adds missing handlings for `throw` and `rethrow` in DCE. They should set `reachable` variable to `false`, like other branches.
* Remove C API tracing (#2841)Daniel Wirtz2020-05-083-2304/+194
| | | | | | This feature was very useful in the early days of the C API, but has not shown usefuless for quite a while, and has a significant maintenance burden, so it it's makes sense to remove it now.
* Mimic MODULARIZE_INSTANCE (#2838)Daniel Wirtz2020-05-072-0/+10
| | | | | | | Turned out that the behavior of MODULARIZE_INSTANCE, which has been removed from Emscripten lately, cannot be easily reproduced using MODULARIZE. So, instead of modularizing and attempting to undo it, this just uses some good old wrapper code to achieve the same.
* Move std::hash specializations into the std namespace (#2835)Thomas Lively2020-05-062-10/+17
| | | | This hopefully fixes a build problem on older GCC as reported in #2827.
* Add interpreter support for EH (#2780)Heejin Ahn2020-05-066-19/+125
| | | | | | | | | This adds interpreter support for EH instructions. This adds `ExceptionPackage` struct, which contains info of a thrown exception (an event tag and thrown values), and the union in `Literal` can take a `unique_ptr` to `ExceptionPackage`. We need a destructor, a copy constructor, and an assignment operator for `Literal`, because the union in `Literal` now has a member that cannot be trivially copied or deleted.
* Remove `constexpr` that causes GCC build to fail (#2828)Thomas Lively2020-05-041-1/+1
| | | | | | | GCC complains that the enclosing class of the constexpr member function is not a literal type. This change removes the constexpr qualifier to fix the GCC build. Fixes #2827.
* Final renumbering of SIMD opcodes (#2820)Thomas Lively2020-05-011-188/+203
| | | As described in https://github.com/WebAssembly/simd/pull/209.
* Add stack-pointer argument to post-emscripten pass. (#2823)Sam Clegg2020-05-013-7/+29
| | | | | | | This allows emscripten to statically set the initial value of the stack pointer. Should allow use to avoid doing it dynamically at startup: https://github.com/emscripten-core/emscripten/pull/11031
* Stop generating implementedFunctions in wasm-emscripten-finalize (#2819)Sam Clegg2020-04-281-9/+0
| | | | This list is identical to the export list no there is no need to output this twice.
* Fix wasm2c loop (#2816)Alon Zakai2020-04-281-5/+6
| | | | | | The refactoring of the loop in #2812 was wrong - we need to loop over all the exports and ignore the non-function ones. Rewrote it to stress that part.
* Use --detect-features in wasm-reduce. Fixes #2813 (#2815)Alon Zakai2020-04-281-6/+2
|
* Refactor ExpressionRunner (#2804)Daniel Wirtz2020-04-273-138/+178
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Tackles the concerns raised in https://github.com/WebAssembly/binaryen/issues/2797 directly related to https://github.com/WebAssembly/binaryen/pull/2702 by reverting merging all of `PrecomputeExpressionRunner` into the base `ExpressionRunner`, instead adding a common base for both the precompute pass and the new C-API to inherit. No functional changes. --- ### Current hierarchy after https://github.com/WebAssembly/binaryen/pull/2702 is ``` ExpressionRunner ├ [PrecomputeExpressionRunner] ├ [CExpressionRunner] ├ ConstantExpressionRunner └ RuntimeExpressionRunner ``` where `ExpressionRunner` contains functionality not utilized by `ConstantExpressionRunner` and `RuntimeExpressionRunner`. ### New hierarchy will be: ``` ExpressionRunner ├ ConstantExpressionRunner │ ├ [PrecomputeExpressionRunner] │ └ [CExpressionRunner] ├ InitializerExpressionRunner └ RuntimeExpressionRunner ``` with the precompute pass's and the C-API's shared functionality now moved out of `ExpressionRunner` into a new `ConstantExpressionRunner`. Also renames the previous `ConstantExpressionRunner` to `InitializerExpressionRunner` to [better represent its uses](https://webassembly.org/docs/modules/#initializer-expression) and to make its previous name usable for the new intermediate template, where it fits perfectly. Also adds a few comments answering some of the questions that came up recently. ### Old hierarchy before https://github.com/WebAssembly/binaryen/pull/2702 for comparison: ``` ExpressionRunner ├ [PrecomputeExpressionRunner] ├ ConstantExpressionRunner └ RuntimeExpressionRunner ```
* Emcc fuzzing followups (#2812)Alon Zakai2020-04-271-4/+3
| | | | | | Avoid pass-debug when fuzzing emcc, as it can be slow and isn't what we care about. Clean up a loop.
* Fuzz frequency tuning (#2806)Alon Zakai2020-04-271-97/+69
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We had some ad-hoc tuning of which nodes to emit more frequently in the fuzzer, but it wasn't very good. Things like loads and stores for example were far too rare. Also it wasn't easy to adjust the frequencies. This adds a simple way to adjust them, by passing a size_t which is the "weight" of that node. Then it just makes that number of copies of it, making it more likely to be picked. Example output comparison: node before after ================================ binary 281 365 block 898 649 break 278 144 call 182 290 call_indirect 9 42 const 808 854 drop 43 92 global.get 440 398 global.set 223 171 if 335 254 load 22 84 local.get 429 301 local.set 434 211 loop 176 99 nop 117 54 return 264 197 select 8 33 store 1 39 unary 405 304 unreachable 1 2 Lots of noise here obviously, but there are large increases for loads and stores compared to before. Also add a testcase of random data of the typical size the fuzzer runs, and print metrics on it. This might help us get a feel for how future tuning changes affect frequencies.
* Remove --fuzz-binary and simplify round trip (#2799)Thomas Lively2020-04-243-75/+20
| | | Since the --roundtrip pass is more general than --fuzz-binary anyways. Also reimplements `ModuleUtils::clearModule` to use the module destructor and placement new to ensure that no members are missed.
* Wasm2c2Wasm Fuzzer: wasm2c + emcc (#2791)Alon Zakai2020-04-241-15/+30
| | | | | | | | | This adds a variant on wasm2c that uses emcc instead of a native compiler. This helps us fuzz emcc. To make that practical, rewrite the setjmp glue to only use one setjmp. The wasm backend ends up doing linear work per setjmp, so it's quadratic with many setjmps. Instead, do a big switch-loop construct around a single setjmp.
* Fix RemoveUnusedNames on a loop with no name and a child with a different ↵Alon Zakai2020-04-241-1/+1
| | | | type. fixes #2807 (#2808)
* Emit section IDs as bytes (#2803)Thomas Lively2020-04-241-4/+4
| | | As described in the spec.
* Fix ExpressionRunner issues found by the fuzzer (#2790)Daniel Wirtz2020-04-233-17/+22
| | | | | | | Fixes #2788 found by the fuzzer, introduced in #2702, which turned out to be incorrect usage of std::move, by removing any std::moves introduced in that PR to be better safe than sorry. Also fixes problems with WASM_INTERPRETER_DEBUG spotted during debugging.
* Add snake_case method names for returnCall/returnCallIndirect in JS API (#2795)Shao Cheng2020-04-231-2/+5
|
* Emit text in pass reduction when in text mode (#2792)Alon Zakai2020-04-221-0/+3
| | | | | | | Without this we emitted a binary, which confused the size comparisons. (When reducing a smaller size is usually a good sign. And also it provides a deterministic way to know when to stop - we can't infinite loop if we keep going while the size shrinks.)
* [fuzzing] wasm2c integration (#2772)Alon Zakai2020-04-223-2/+202
| | | | | | | | | | | | | | | | | | | | | | | | | This adds support for fuzzing with wabt's wasm2c that @binji wrote. Basically we compile the wasm to C, then compile the C to a native executable with a custom main() to wrap around it. The executable should then print exactly the same as that wasm when run in either the binaryen interpreter or in a JS VM with our wrapper JS for that wasm. In other words, compiling the wasm to C is another way to run that wasm. The main reasons I want this are to fuzz wasm2c itself, and to have another option for fuzzing emcc. For the latter, we do fuzz wasm-opt quite a lot, but that doesn't fuzz the non-wasm-opt parts of emcc. And using wasm2c for that is nice since the starting point is always a wasm file, which means we can use tools like wasm-reduce and so forth, which can be integrated with this fuzzer. This also: Refactors the fuzzer harness a little to make it easier to add more "VMs" to run wasms in. Do not autoreduce when re-running a testcase, which I hit while developing this.
* Add BinaryenCallIsReturn/BinaryenCallIndirectIsReturn to C/JS API (#2779)Shao Cheng2020-04-223-0/+24
|
* Also update internal name in fixEmJsFuncsAndReturnWalker (#2782)Sam Clegg2020-04-211-17/+21
| | | | | | Without this change only the import gets renamed not the internal name. Since the internal name is the one that ends up in the name section this means that rename wasn't effecting the name section.
* Refactor expression runner so it can be used via the C and JS APIs (#2702)Daniel Wirtz2020-04-206-103/+493
| | | | | | | Refactors most of the precompute pass's expression runner into its base class so it can also be used via the C and JS APIs. Also adds the option to populate the runner with known constant local and global values upfront, and remembers assigned intermediate values as well as traversing into functions if requested.
* Fix issues with Types and Features (#2773)Thomas Lively2020-04-162-3/+7
| | | | | | | | | 1. Only emit exnref as part of a subtype if exception-handling is enabled in the fuzzer. 2. Correctly report that funcref and nullref require reference-types to be enabled. 3. Re-enable multivalue as a normal feature in the fuzzer. Possibly fixes #2770.
* Dummy interpreter support for EH (#2774)Heejin Ahn2020-04-161-6/+51
| | | | | | | | | | | | | | | | | | | | | | This adds dummy interpreter support for EH instructions, mainly for fuzzing. The plan is to make the interpreter support for EH instructions correctly using Asyncify in the future. Also to support the correct behavior we will need a `Literal` of `exnref` type too, which will be added later too. Currently what this dummy implementation does is: - `try`-`catch`-`end`: only runs `try` body and ignores `catch` body - `throw`: traps - `retyrow`: - Traps on nullref argument (correct behavior based on the spec) - Traps otherwise too (dummy implementation for now) - `br_on_exn`: - Traps on nullref (correct behavior) - Otherwise we assume the current expression matches the current event and extracts a 0 literal based on the current type. This also adds some interpreter tests, which tests the basic dummy behaviors for now. (Deleted tests are the ones that weren't tested before.)
* Validate that tuples have multiple operands (#2768)Thomas Lively2020-04-161-0/+2
| | | This was previously an unwritten and unchecked assumption.
* Fix OOB fuzzing (#2769)Alon Zakai2020-04-161-9/+15
| | | | | | | | | We should only do weird changes to the fuzz code if we allow out of bounds operations, because the OOB checks are generated as we build the IR, and changing them can remove the checks. (we fuzz 50% of the time with and 50% without OOBs, so this doesn't really hurt us)
* Emit tuples in the fuzzer (#2695)Thomas Lively2020-04-151-108/+170
| | | | | | | | Emit tuple.make, tuple.extract, and multivalue control flow, and tuple locals and globals when multivalue is enabled. Also slightly refactors the top-level `makeConcrete` function to be more selective about what it tries to make based on the requested type to reduce the number of trivial nodes created because the requested type is incompatible with the requested node.
* Enable cross-VM fuzzing + related improvements to fuzz_opt.py (#2762)Alon Zakai2020-04-151-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The main benefit here is comparing VMs, instead of just comparing each VM to itself after opts. Comparing VMs is a little tricky since there is room for nondeterminism with how results are printed and other annoying things, which is why that didn't work well earlier. With this PR I can run 10's of thousands of iterations without finding any issues between v8 and the binaryen interpreter. That's after fixing the various issues over the last few days as found by this: #2760 #2757 #2750 #2752 Aside from that main benefit I ended up adding more improvements to make it practical to do all that testing: Randomize global fuzz settings like whether we allow NaNs and out-of-bounds memory accesses. (This was necessary here since we have to disable cross-VM comparisons if NaNs are enabled.) Better logging of statistics like how many times each handler was run. Remove redundant FuzzExecImmediately handler (looks like after past refactorings it was no longer adding any value). Deterministic testcase handling: if you run e.g. fuzz_opt.py 42 it will run one testcase and exactly the same one. If you run without an argument it will run forever until it fails, and if it fails, it prints out that ID so that you can easily reproduce it (I guess, on the same binaryen + same python, not sure how python's deterministic RNG changes between versions and builds). Upgrade to Python 3.
* Fix reuse of constant nodes in Precompute (#2764)Heejin Ahn2020-04-141-28/+33
| | | | | | | | | | Previously we tried to reuse `Const` node if a precomputed value is a constant node. But now we have two more kinds of constant node (`RefNull` and `RefFunc`), so we shouldn't reuse them interchangeably, meaning we shouldn't try to reuse a `Const` node when the value at hand is a `RefNull`. This correctly checks the type of node and tries to reuse only if the types of nodes match. Fixes #2759.