summaryrefslogtreecommitdiff
path: root/src/tools/wasm-reduce.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Add new compound Signature, Struct and Array types (#3012)Daniel Wirtz2020-08-241-1/+1
| | | | | Extends the `Type` hash-consing infrastructure to handle type-parameterized and constructed types introduced in the typed function references and GC proposals. This should be a non-functional change since the new types are not used anywhere yet. Recursive type construction and canonicalization is also left as future work. Co-authored-by: Thomas Lively <tlively@google.com>
* Prepare for compound types that are single but not basic (#3046)Daniel Wirtz2020-08-171-5/+10
| | | | | | | | | | | | | | As a follow-up to https://github.com/WebAssembly/binaryen/pull/3012#pullrequestreview-459686171 this PR prepares for the new compound Signature, Struct and Array types that are single but not basic. This includes: * Renames `Type::getSingle` to `Type::getBasic` (NFC). Previously, its name was not representing its implementation (`isSingle` excluded `none` and `unreachable` while `getSingle` didn't, i.e. `getSingle` really was `getBasic`). Note that a hypothetical `Type::getSingle` cannot return `ValueType` anyway (new compound types are single but don't map to `ValueType`), so I figured it's best to skip implementing it until we actually need it. * Marks locations where we are (still) assuming that all single types are basic types, as suggested in https://github.com/WebAssembly/binaryen/pull/3012#discussion_r465356708, but using a macro, so we get useful errors once we start implementing the new types and can quickly traverse the affected locations. The macro is added where * there used to be a `switch (type.getSingle())` or similar that handled any basic type (NFC), but in the future will also have to handle single types that are not basic types. * we are not dealing with `Unary`, `Binary`, `Load`, `Store` or `AtomicXY` instructions, since these don't deal with compound types anyway.
* Add a builder.makeConst helper template (#2971)Alon Zakai2020-07-211-2/+2
|
* Rename anyref to externref to match proposal change (#2900)Jay Phelps2020-06-101-5/+5
| | | | | | | anyref future semantics were changed to only represent opaque host values, and thus renamed to externref. [Chromium](https://bugs.chromium.org/p/v8/issues/detail?id=7748#c360) was just updated to today (not yet released). I couldn't find a Mozilla bugzilla ticket mentioning externref so I don't immediately know if they've updated yet. https://github.com/WebAssembly/reference-types/pull/87
* Use --detect-features in wasm-reduce. Fixes #2813 (#2815)Alon Zakai2020-04-281-6/+2
|
* 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.)
* makeConstExpression => makeConstantExpression (#2698)Alon Zakai2020-03-171-1/+1
| | | | | | The meaning we intend is "constant", and not the "Const" node (which contains a number). So I think the full name is less confusing.
* Handle tuples in wasm-reduce (#2689)Thomas Lively2020-03-161-4/+9
| | | | Also increases the usefulness of a couple wasm-builder methods that are useful here.
* Remove implicit conversion operators from Type (#2577)Thomas Lively2020-01-081-5/+5
| | | | | | | | | | * Remove implicit conversion operators from Type Now types must be explicitly converted to uint32_t with Type::getID or to ValueType with Type::getVT. This fixes #2572 for switches that use Type::getVT. * getVT => getSingle
* [NFC] Enforce use of `Type::` on type names (#2434)Thomas Lively2020-01-071-60/+60
|
* Add support for reference types proposal (#2451)Heejin Ahn2019-12-301-0/+14
| | | | | | | | | | | | This adds support for the reference type proposal. This includes support for all reference types (`anyref`, `funcref`(=`anyfunc`), and `nullref`) and four new instructions: `ref.null`, `ref.is_null`, `ref.func`, and new typed `select`. This also adds subtype relationship support between reference types. This does not include table instructions yet. This also does not include wasm2js support. Fixes #2444 and fixes #2447.
* Remove FunctionType (#2510)Thomas Lively2019-12-111-6/+3
| | | | | | | | | | | | | | | | | Function signatures were previously redundantly stored on Function objects as well as on FunctionType objects. These two signature representations had to always be kept in sync, which was error-prone and needlessly complex. This PR takes advantage of the new ability of Type to represent multiple value types by consolidating function signatures as a pair of Types (params and results) stored on the Function object. Since there are no longer module-global named function types, significant changes had to be made to the printing and emitting of function types, as well as their parsing and manipulation in various passes. The C and JS APIs and their tests also had to be updated to remove named function types.
* Add string parameter to WASM_UNREACHABLE (#2499)Sam Clegg2019-12-051-9/+9
| | | | | This works more like llvm's unreachable handler in that is preserves information even in release builds.
* Remove 'none' type as a branch target in ReFinalize (#2492)Alon Zakai2019-12-041-2/+2
| | | | | | | | | | | | | | | | | That was needed for super-old wasm type system, where we allowed (block $x (br_if $x (unreachable) (nop) ) ) That is, we differentiated "taken" branches from "named" ones (just referred to by name, but not actually taken as it's in unreachable code). We don't need to differentiate those any more. Remove the ReFinalize code that considered it, and also remove the named/taken distinction in other places.
* Multivalue type creation and inspection (#2459)Thomas Lively2019-11-221-5/+5
| | | | | | | | | | | | | Adds the ability to create multivalue types from vectors of concrete value types. All types are transparently interned, so their representation is still a single uint32_t. Types can be extracted into vectors of their component parts, and all the single value types expand into vectors containing themselves. Multivalue types are not yet used in the IR, but their creation and inspection functionality is exposed and tested in the C and JS APIs. Also makes common type predicates methods of Type and improves the ergonomics of type printing.
* Fix autoreducing when not in the binaryen directory (#2390)Alon Zakai2019-10-171-1/+6
| | | | This uses argv[0] as the default way to find the location of the wasm binaries (wasm-reduce needs to call wasm-opt).
* Fix case of `windows.h` include (#2372)Mike J Innes2019-10-091-1/+1
| | | | The capitalisation causes issues on case-sensitive file systems, for example when cross-compiling binaryen for windows.
* Add initial support for anyref as an opaque type (#2294)Jay Phelps2019-08-201-0/+5
| | | | | | | | | | | | | Another round of trying to push upstream things from my fork. This PR only adds support for anyref itself as an opaque type. It does NOT implement the full [reference types proposal](https://github.com/WebAssembly/reference-types/blob/master/proposals/reference-types/Overview.md)--so no table.get/set/grow/etc or ref.null, ref.func, etc. Figured it was easier to review and merge as we go, especially if I did something fundamentally wrong. *** I did put it under the `--enable-reference-types` flag as I imagine that even though this PR doesn't complete the full feature set, it probably is the right home. Lmk if not. I'll also be adding a few github comments to places I want to point out/question.
* Rename except_ref type to exnref (#2224)Heejin Ahn2019-07-141-5/+5
| | | | In WebAssembly/exception-handling#79 we agreed to rename `except_ref` type to `exnref`.
* Allow color API to enable and disable colors (#2111)Siddharth2019-05-171-1/+1
| | | | | | This is useful for front-ends which wish to selectively enable or disable coloring. Also expose these APIs from the C API.
* Add except_ref type (#2081)Heejin Ahn2019-05-071-5/+10
| | | | This adds except_ref type, which is a part of the exception handling proposal.
* clang-tidy braces changes (#2075)Alon Zakai2019-05-011-40/+80
| | | Applies the changes in #2065, and temprarily disables the hook since it's too slow to run on a change this large. We should re-enable it in a later commit.
* Apply format changes from #2048 (#2059)Alon Zakai2019-04-261-217/+345
| | | Mass change to apply clang-format to everything. We are applying this in a PR by me so the (git) blame is all mine ;) but @aheejin did all the work to get clang-format set up and all the manual work to tidy up some things to make the output nicer in #2048
* Change default feature set to MVP (#1993)Thomas Lively2019-04-161-2/+7
| | | | | In the absence of the target features section or command line flags. When there are command line flags, it is an error if they do not exactly match the target features section, except if --detect-features has been provided. Also adds a --print-features pass to print the command line flags for all enabled options and uses it to make the feature tests more rigorous.
* Move features from passOptions to Module (#2001)Thomas Lively2019-04-121-1/+1
| | | | | This allows us to emit a (potentially modified) target features section and conditionally emit other sections such as the DataCount section based on the presence of features.
* Fuzz fixes (#1991)Alon Zakai2019-04-101-1/+5
| | | | | | | Get fuzzer to attempt to create almost all features. Pass v8 all the flags to allow that. Fix fuzz bugs where we read signed_ even when it was irrelevant for that type of load. Improve wasm-reduce on fuzz testcases, try to replace a node with drops of its children, not just the children themselves.
* NaN fuzzing improvements (#1913)Alon Zakai2019-02-191-3/+27
| | | | | | | | | * make DE_NAN avoid creating nan literals in the first place * add a reducer option `--denan` to not introduce nans in destructive reduction * add a `Literal::isNaN()` method * also remove the default exception logging from the fuzzer js glue, which is a source of non-useful VM differences (like nan nondeterminism) * added an option `--no-fuzz-nans` to make it easy to avoid nans when fuzzing (without hacking the source and recompiling). Background: trying to get fuzzing on jsc working despite this open issue: https://bugs.webkit.org/show_bug.cgi?id=175691
* Code style improvements (#1868)Alon Zakai2019-01-151-1/+1
| | | | * Use modern T p = v; notation to initialize class fields * Use modern X() = default; notation for empty class constructors
* SIMD (#1820)Thomas Lively2018-12-131-1/+1
| | | | | | | | | Implement and test the following functionality for SIMD. - Parsing and printing - Assembling and disassembling - Interpretation - C API - JS API
* Feature options (#1797)Thomas Lively2018-12-031-1/+1
| | | | Add feature flags and struct interface. Default feature set has all feature enabled.
* Add --strip that removes debug info (#1787)Alon Zakai2018-12-031-0/+1
| | | | This is sort of like --strip on a native binary. The more specific use case for us is e.g. you link with a library that has -g in its CFLAGS, but you don't want debug info in your final executable (I hit this with poppler now). We can make emcc pass this to binaryen if emcc is not building an output with intended debug info.
* Add v128 type (#1777)Thomas Lively2018-11-291-0/+5
|
* Remove default cases (#1757)Thomas Lively2018-11-271-8/+16
| | | | | | Where reasonable from a readability perspective, remove default cases in switches over types and instructions. This makes future feature additions easier by making the compiler complain about each location where new types and instructions are not yet handled.
* add an option to work on text files in wasm-reduce (#1772)Alon Zakai2018-11-271-6/+19
| | | Reducing on text files can be useful as in binaryen the binary reading and writing has some noticeable effects (due to wasm and binaryen IR not being identical, while the text format is a closer match.
* wasm-reduce: reduce switch targets (#1752)Alon Zakai2018-11-161-2/+21
| | | This tries to reduce by replacing targets with the default, and by shrinking the list of targets.
* More #1678 fixes (#1685)Alon Zakai2018-09-201-4/+6
| | | While debugging to fix the waterfall regressions I noticed that wasm-reduce regressed. We need to be more careful with visitFunction which now may visit an imported function - I found a few not-well-tested passes that also regressed that way.
* -O4: When -O3 isn't enough (#1596)Alon Zakai2018-06-081-0/+1
| | | | | | | | | This defines a new -O4 optimization mode, as flatten + flat-only opts (currently local-cse) + -O3. In practice, flattening is not needed for LLVM output, which is pretty flat already (no block or if values, etc., even if it does use tees and does nest expressions; and LLVM has already done gvn etc. anyhow). In general, though, wasm generated by a non-LLVM compiler may naturally be nested because wasm allows that. See for example #1593 where an AssemblyScript testcase requires flattening to be fully optimized. So -O4 can help there. -O4 takes 3x longer to run than -O3 in my testing, basically because flat IR is much bigger. But when it's useful it may be worth it. It does handle that AssemblyScript testcase and others like it. There's not much big real-world code that isn't LLVM yet, but running the fuzzer - which happily creates nested stuff all the time - I see -O4 consistently shrink the size by around 20% over -O3.
* Improve local-cse (#1594)Alon Zakai2018-06-081-19/+18
| | | | | This makes it much more effective, by rewriting it to depend on flatten. In flattened IR, it is very simple to check if an expression is equivalent to one already available for use in a local, and use that one instead, basically we just track values in locals. Helps with #1521
* More reducer improvements (#1533)Alon Zakai2018-05-081-45/+92
| | | | | | * Add a helper class to iterate over all a node's children, and use that when attempting to replace a node with its children. * If a child has a different type than the parent, try to replace the parent with a conversion + the child (for example, a call may receive two f32 inputs and return an i32; we can try to replace the call with one of those f32s and a conversion to an i32). * When possible, try to replace the function body with a child even if the child has a different type, by changing the function return value.
* improve remove-unused-module-elements (#1532)Alon Zakai2018-05-041-0/+1
| | | | | Remove the entire memory/table when possible, in particular, when not imported, exported, or used. Previously we did not look at whether they were imported, so we assumed we could never remove them. Also add a variant that removes everything but functions, which can be useful when reducing a testcase that only cares about code in functions.
* reducer improvements: more if, block, loop and other node reduction attempts ↵Alon Zakai2018-05-041-0/+52
| | | | (#1530)
* refactor Path utils: store the bin/ dir so that all users of the API can use ↵Alon Zakai2018-03-301-30/+30
| | | | it by the standard calls, even if it was modified by user input (move it out of just being in wasm-reduce.cpp) (#1489)
* Support wasm-reduce for Windows (#1488)Michael Ferris2018-03-261-7/+125
|
* More reducer improvements (#1471)Alon Zakai2018-03-151-5/+22
| | | | | | * After we see a function can't be removed, deprioritize trying to remove it again (it may just be unremovable). * Focus on reducing segments exponentially first, before zeroing out what is left (which is not exponential). This was helpful in reducing a massive sqlite testcase.
* wasm-reduce improvement: while function removal works, keep doing it (#1459)Alon Zakai2018-03-061-2/+6
|
* wasm-reduce tweaks and improvements (#1405)Alon Zakai2018-02-111-12/+52
| | | | | * wasm-reduce tweaks and improvements: better error messages, better validation, better function removal, etc.
* Rename WasmType => Type (#1398)Alon Zakai2018-02-021-1/+1
| | | | * rename WasmType to Type. it's in the wasm:: namespace anyhow, and without Wasm- it fits in better alongside Index, Address, Expression, Module, etc.
* Optimize wasm-reduce (#1359)Alon Zakai2018-01-201-30/+99
|
* Fix wasm-reduce testing out of tree (#1284)Alon Zakai2017-11-211-2/+3
| | | | * fix wasm-reduce when out-of-tree: do not use a hardcoded bin/wasm-opt, instead add a Path namespace with utilities to get the proper path, and use BINARYEN_ROOT which our test setup code ensures
* fix wasm-reduce bug, the second validator param is the features, not the ↵Alon Zakai2017-11-091-1/+1
| | | | flags (#1277)