summaryrefslogtreecommitdiff
path: root/test
Commit message (Collapse)AuthorAgeFilesLines
* Initial implementation of "Memory64" proposal (#3130)Wouter van Oortmerssen2020-09-1845-5/+16157
| | | Also includes a lot of new spec tests that eventually need to go into the spec repo
* Update JS API function wrapper (#3128)Daniel Wirtz2020-09-183-1/+55
| | | Updates the JS API `Function` wrapper introduced in #3115 with bindings for more C API functions. Also adds additional comments to describe the inner workings of wrappers in more detail.
* Optimize binary operations with 1-bit on lhs and 1 const on rhs (#2948)Max Graey2020-09-173-10/+122
| | | | | | | `expr | 1` --> `1` `expr & 1` --> `expr` `expr == 1` --> `expr` `expr != 1` --> `!expr` where `maxBits(expr) == 1` i.e `expr` is boolean
* Implement more cases for getMaxBits (#2879)Max Graey2020-09-173-25/+533
| | | | | | | | | | | | | | | - Complete 64-bit cases in range `AddInt64` ... `ShrSInt64` - `ExtendSInt32` and `ExtendUInt32` for unary cases - For binary cases - `AddInt32` / `AddInt64` - `MulInt32` / `MulInt64` - `RemUInt32` / `RemUInt64` - `RemSInt32` / `RemSInt64` - `DivUInt32` / `DivUInt64` - `DivSInt32` / `DivSInt64` - and more Also more fast paths for some getMaxBits calculations
* Improve testing on Windows (#3142)Wouter van Oortmerssen2020-09-172-2/+3
| | | | | | This PR contains: - Changes that enable/disable tests on Windows to allow for better local testing. - Also changes many abort() into Fatal() when it is really just exiting on error. This is because abort() generates a dialog window on Windows which is not great in automated scripts. - Improvements to CMake to better work with the project in IDEs (VS).
* Unary and binary duplicate expression elimination (#3047)Max Graey2020-09-172-4/+490
| | | | | | | | | | | | | | | | | | Simplifies patterns in which an expression is applied twice to its operands. `abs(abs(x))` -> `abs(x)` `ceil(ceil(x))` -> `ceil(x)` `floor(floor(x))` -> `floor(x)` `trunc(trunc(x))` -> `trunc(x)` `nearest(nearest(x))` -> `nearest(x)` `eqz(eqz(bool(x)))` -> `bool(x)` `sext(sext(x))` -> `sext(x)` `neg(neg(x))` -> `x` `y - (y - x)` -> `x` `(x ^ y) ^ y` -> `x` `(x | y) | y` -> `x | y` `(x & y) & y` -> `x & y` `(x % y) % y` -> `x % y`
* Refactor Host expression to MemorySize and MemoryGrow (#3137)Daniel Wirtz2020-09-177-61/+113
| | | Aligns the internal representations of `memory.size` and `memory.grow` with other more recent memory instructions by removing the legacy `Host` expression class and adding separate expression classes for `MemorySize` and `MemoryGrow`. Simplifies related APIs, but is also a breaking API change.
* Add GC feature flag (#3135)Daniel Wirtz2020-09-179-110/+25
| | | Adds the `--enable-gc` feature flag, so far enabling the `anyref` type incl. subtyping, and removes the temporary `--enable-anyref` feature flag that it replaces.
* Fix inner block problem with 'catch' (#3129)Heejin Ahn2020-09-152-0/+19
| | | Fixes #3114.
* Add float operations for isSymmetric util (#3127)Max Graey2020-09-143-12/+12
| | | Add floating point Eq and Ne operators to Properties::isSymmetric. Also treat additional float ops as symmetric specifically in OptimizeInstructions when their operands are known to be non-NaN.
* Implement module and local names in name section (#3115)Daniel Wirtz2020-09-148-156/+220
| | | | | | | | | | | | | | | Adds support for the module and local subsections of the name section plus the respective C and JS APIs to populate and obtain local names. C API: * BinaryenFunctionGetNumLocals(func) * BinaryenFunctionHasLocalName(func, index) * BinaryenFunctionGetLocalName(func, index) * BinaryenFunctionSetLocalName(func, index, name) JS API: * Function.getNumLocals(func) * Function.hasLocalName(func, index) * Function.getLocalName(func, index) * Function.setLocalName(func, index, name)
* Simplify subtracting zero from float expressions (#3125)Max Graey2020-09-132-0/+98
| | | | | | | `x - 0.0` -> `x` `x + (-0.0)` -> `x` `x - (-0.0)` -> `x + 0.0` where `x` is `f32` or `f64`.
* Fix RefNull issues (#3123)Daniel Wirtz2020-09-132-4/+20
| | | | | | | | | * ExpressionAnalyzer: Fix `ref.null ht` equality check to include `ht`. * Precompute: Fix `ref.null ht` expression reuse to also update `ht`. * Fuzzing: Fix `ref.null func` becoming canonicalized to `ref.func $funcref` when evaluating execution results, by adding a check for `isNull`. * Fuzzing: Print actual and expected execution results when aborting. * Tests: Update `if-arms-subtype` test in `optimize-instructions` to check that identical `if` arms become folded while not identical arms are kept.
* Update Pop text format to handle tuples (#3116)Thomas Lively2020-09-1139-183/+202
| | | | | | | | | | | Previously Pops were printed as ({type}.pop), and if the popped type was a tuple, something like ((i32, i64).pop) would get printed. However, the parser didn't support pops of anything besides single basic types. This PR changes the text format to be (pop <type>*) and adds support for parsing pops of tuples of basic types. The text format change is designed to make parsing simpler. This change is necessary for writing Poppy IR tests (see #3059) that contain break or return instructions that consume multiple values, since in Poppy IR that requires tuple-typed pops.
* Stop renaming longjmp in wasm-emscripten-finalize (#3111)Alon Zakai2020-09-114-10/+38
| | | | | | | | | | | Instead of finalize renaming emscripten_longjmp_jmpbuf to emscripten_longjmp, do nothing in finalize. But in the optional --post-emscripten pass, rename it there if both exist, so that we don't end up using two imports (other optimization passes can then remove an unneeded import). Depends on emscripten-core/emscripten#12157 to land first so that emscripten can handle both names, and it is just an optimization to have one or the other. See https://github.com/WebAssembly/binaryen/issues/3043
* Add anyref feature and type (#3109)Daniel Wirtz2020-09-1029-895/+3277
| | | Adds `anyref` type, which is enabled by a new feature `--enable-anyref`. This type is primarily used for testing that passes correctly handle subtype relationships so that the codebase will continue to be prepared for future subtyping. Since `--enable-anyref` is meaningless without also using `--enable-reference-types`, this PR also makes it a validation error to pass only the former (and similarly makes it a validation error to enable exception handling without enabling reference types).
* Simplify BinaryenIRWriter (#3110)Thomas Lively2020-09-105-4241/+4234
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | BinaryenIRWriter was previously inconsistent about whether or not it emitted an instruction if that instruction was not reachable. Instructions that produced values were not emitted if they were unreachable, but instructions that did not produce values were always emitted. Additionally, blocks continued to emit their children even after emitting an unreachable child. Since it was not possible to tell whether an unreachable instruction's parent would be emitted, BinaryenIRWriter had to be very defensive and emit many extra `unreachable` instructions around unreachable code to avoid type errors. This PR unifies the logic for emitting all non-control flow instructions and changes the behavior of BinaryenIRWriter so that it never emits instructions that cannot be reached due to having unreachable children. This means that extra `unreachable` instructions now only need to be emitted after unreachable control flow constructs. BinaryenIRWriter now also stops emitting instructions inside blocks after the first unreachable instruction as an extra optimization. This change will also simplify Poppy IR stackification (see #3059) by guaranteeing that instructions with unreachable children will not be emitted into the stackifier. This makes satisfying the Poppy IR rule against unreachable Pops trivial, whereas previously satisfying this rule would have required about about 700 additional lines of code to recompute the types of all unreachable children for any instruction.
* Fix wasm2js memory import in case it is minified (#3113)Alon Zakai2020-09-103-0/+134
| | | | | | | | | | | | | | | It was hardcoded as "env.memory", which is usually correct. But if we minify import names, as in -O3 in emscripten, we need to use the minified name. Note how in the test it now emits var memory = env.a; for the import. Fixes emscripten-core/emscripten#12123 This was not noticed earlier since that import is only used in memory growth. The tests that would catch it are wasm2js3.test*memory_growth* but we only run wasm2js1 on CI. I'll add testing after this lands.
* Poppy IR wast parsing and validation (#3105)Thomas Lively2020-09-091-0/+203
| | | | | Adds an IR profile to each function so the validator can determine which validation rules to apply and adds a flag to have the wast parser set the profile to Poppy for testing purposes.
* Interpreter: Don't change NaN bits when multiplying by 1 (#3096)Alon Zakai2020-09-093-30/+45
| | | | | | | | | | Similar to #2958, but for multiplication. I thought this was limited only to division (it doesn't happen for addition, for example), but the fuzzer found that it does indeed happen for multiplication as well. Overall these are kind of workarounds for the interpreter doing normal f32/f64 multiplications using the host CPU, so we pick up any oddness of its NaN behavior. Using soft float might be safer (but much slower).
* Update reference types (#3084)Daniel Wirtz2020-09-0951-1616/+1719
| | | | | | | Align with the current state of the reference types proposal: * Remove `nullref` * Remove `externref` and `funcref` subtyping * A `Literal` of a nullable reference type can now represent `null` (previously was type `nullref`) * Update the tests and temporarily comment out those tests relying on subtyping
* Stack utils (#3083)Thomas Lively2020-09-072-0/+460
| | | | | | Implement and test utilities for manipulating and analyzing a new stacky form of Binaryen IR that is able to express arbitrary stack machine code. This new Poppy IR will eventually replace Stack IR, and new optimization passes will be built with these utilities. See #3059.
* Improve inlining "heavyweight" (#3085)Max Graey2020-09-046-97/+179
| | | | | | | | | Split that mode into an option to check for loops (which indicate a function is "heavy") and a constant check for having calls. The case of calls is different as we would need more logic to avoid infinite recursion if we are willing to inling functions with calls. Practically, this renames allowHeavyweight to allowFunctionsWithLoops.
* Remove old stack function from StackCheck (#3100)Alon Zakai2020-09-034-31/+1
|
* MinifyImportsAndExports: Minify the memory and table as well. (#3089)Alon Zakai2020-09-023-20023/+20029
| | | | | | | | | | | | We were careful not to minify those, as well as the stack pointer, which makes sense in dynamic linking. But we don't run this pass in dynamic linking anyhow - we need the proper names of symbols in that case. So this was not helping us, and was just a leftover from an early state. This both a useful optimization and also important for #3043, as the wasm backend exports the table as __indirect_function_table - a much longer name than emscripten's table. So just changing to that would regress code size on small projects. Once we land this, the name won't matter as it will be minified anyhow.
* StackCheck: Check both under and overflow (#3091)Alon Zakai2020-09-025-65/+216
| | | | | | | | | | | | | | | | | | | See emscripten-core/emscripten#9039 (comment) The valid stack area is a region [A, B] in memory. Previously we just checked that new stack positions S were S >= A, which prevented us from growing too much (the stack grows down). But that only worked if the growth was small enough to not overflow and become a big unsigned value. This PR makes us check the other way too, which requires us to know where the stack starts out at. This still supports the old way of just passing in the growth limit. We can remove it after the roll. In principle this can all be done on the LLVM side too after emscripten-core/emscripten#12057 but I'm not sure of the details there, and this is easy to fix here and get testing up (which can help with later LLVM work). This helps emscripten-core/emscripten#11860 by allowing us to clean up some fastcomp-specific stuff in tests.
* Add Binaryen(Get|Set)AllowHeavyweight to binaryen-c.h (#3082)Max Graey2020-08-282-0/+5
| | | These declarations were previously missing causing the respective APIs to be not exposed. Also makes sure that a Boolean is returned by the JS API and adds a test to verify that it is working now.
* Add allowHeavyweight inlining option (#3032)Max Graey2020-08-262-0/+93
| | | | | As discussed in #2921, this allows inlining of functions not identified as "lightweight" (that include a loop, for example).
* Add new compound Rtt type (#3076)Daniel Wirtz2020-08-262-3/+164
| | | Extends compound types introduced in #3012 with a representation of `Rtt`s as described in the GC proposal, by also introducing the concept of a `HeapType` shared between `TypeInfo` and `Rtt`. Again, this should be a non-functional change since `Rtt`s are not used anywhere yet. Subtyping rules and updating the `xref` aliases is left for future work.
* wasm-emscripten-finalize: Add flags to limit dynCall creation (#3070)Sam Clegg2020-08-262-0/+30
| | | | | | Two new flags here, one to completely removes dynCalls, and another to limit them to only signatures that contains i64. See #3043
* SAFE_HEAP: remove fastcomp, prepare for new emscripten approach (#3078)Alon Zakai2020-08-252-2/+8
| | | | | | | | | | | | | | | In fastcomp we implemented emscripten_get_sbrk_ptr in wasm, and exported _emscripten_get_sbrk_ptr. We don't need that anymore and can remove it. However I want to switch us to implementing emscripten_get_sbrk_ptr in wasm in upstream too, as part of removing DYNAMICTOP_PTR and other silliness that we have around link (#3043). This makes us support an export of emscripten_get_sbrk_ptr (no prefix), and also it makes sure not to instrument that function, which may contain some memory operations itself, but if we SAFE_HEAP-ify them we'd get infinite recursion, as the SAFE_HEAP methods need to call that.
* also drop size for memory.copy(x, x, y) (#3075)Max Graey2020-08-241-0/+3
| | | This fixes a bug in which a side effect in the calculation of the size could be lost.
* Add new compound Signature, Struct and Array types (#3012)Daniel Wirtz2020-08-242-0/+288
| | | | | 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>
* memory.copy: use nop reductions only for ignoreImplicitTraps (#3074)Max Graey2020-08-244-8/+37
| | | | | | | | | According to changes in spec: WebAssembly/bulk-memory-operations#124 WebAssembly/bulk-memory-operations#145 we unfortunately can't fold to nop even for memory.copy(x, y, 0). So this PR revert all reductions to nop but do this only under ignoreImplicitTraps flag
* Remove optimization for memory.copy(x, x, C) (#3073)Max Graey2020-08-232-2/+6
| | | | | That can trap, so we can only remove it if traps are ignored, which was not handled properly. Revert it as we consider the options.
* OptimizeInstructions on memory.copy: check size for side effect as well (#3072)Max Graey2020-08-232-1/+16
| | | Fix issue found by fuzzer: #3038 (comment)
* Optimize bulk memory.copy (#3038)Max Graey2020-08-222-0/+140
| | | Replace it with a load and a store when the size is a small constant and remove it entirely when it would be a nop.
* Remove old EM_ASM handling method (#3069)Alon Zakai2020-08-216-23/+29
| | | | | | | The minimizeWasmChanges flag now does nothing (but new changes are coming, so keep it around) - this moves us to always doing the new way of things. With that we can update the tests. See #3043
* Remove asm2wasm (#3042)Alon Zakai2020-08-17139-289250/+0
| | | | | | | Now that fastcomp has been removed from Emscripten, there is no need for the asm2wasm tool which it used to compile fastcomp's asm.js output to wasm. See emscripten-core/emscripten#11860
* Make wasm-emscripten-finalize's output optional (#3055)Alon Zakai2020-08-172-2/+31
| | | | | | | | | | This helps towards the goal of allowing emscripten to not always modify the wasm during link. Until now wasm-emscripten-finalize always wrote an output, while with this PR it only does so if it was asked to, either by giving it an output filename, or asking for text output. The only noticeable change from this should be to make what was an error before (not specify an output or ask for text) into a non-error (run and print metadata, but do not write the wasm).
* Add a C source for for test/lld/em_asm_O0 (#3045)Alon Zakai2020-08-1712-68/+168
| | | | | | | | | | | | That had just a wat file, with no C. This adds a C file as best I can guess - looks pretty close - and updates all the lld tests with scripts/test/generate_lld_tests.py and ./auto_update_tests.py lld As the diff shows, the handwritten wat was very different than what emcc+lld emit now. I think we must have switches EM_ASMs to be variadic at some point? That is what they currently are, and would explain the diff. See the discussion that led to this in #3044
* Skip tests that fail on windows and enable all the rest (#3035)Alon Zakai2020-08-1127-2/+9
| | | | | | | | | | | | | | This lets us run most tests at least on that platform. Add a new function for skipping those tests, skip_if_on_windows, so that it's easy to find which tests are disabled on windows for later fixing efforts. This fixes a few minor issues for windows, like comparisons should ignore \r in some cases. Rename all passes tests that use --dwarfdump to contain "dwarf" in their name, which makes it easy to skip those (and is clearer anyhow).
* DWARF: Fix debug_info references to the abbreviations section (#2997)Alon Zakai2020-08-073-0/+1
| | | | | | | | | | | | | | | | The previous code assumed that each compile unit had its own abbreviation section, and they are all in order. That's normally how LLVM emits things, but in #2992 there is a testcase in which linking of object files with IR files somehow ends up with a different order. The proper fix is to track the binary offsets of abbreviations in the abbreviation section. That section is comprised of null-terminated lists, which each CU has an offset to the beginning of. With those offsets, we can match things properly. Add a testcase that crashes without this, to prevent regressions. Fixes #2992 Fixes #3007
* StubUnsupportedJSOps: Remove CallIndirects (#3027)Alon Zakai2020-08-062-0/+47
| | | | | | wasm2js does not have full call_indirect support as we don't trap if the type is incorrect, which wasm does. Therefore the StubUnsupportedJSOps pass needs to remove those operations so that the fuzzer doesn't find spurious issues.
* Asyncify verbose option (#3022)Alon Zakai2020-08-062-0/+372
| | | | | | | | | | | | | | | | This logs out the decisions made about instrumenting functions, which can help figure out why a function is instrumented, or to get a list of what might need to be. As the test shows, it can print things like this: [asyncify] import is an import that can change the state [asyncify] calls-import can change the state due to import [asyncify] calls-calls-import can change the state due to calls-import [asyncify] calls-calls-calls-import can change the state due to calls-calls-import (the test has calls-calls-calls-import => calls-calls-import => calls-import -> import).
* Refactor wasm-emscripten-finalize to use a single pass runner (#2987)Sam Clegg2020-08-0510-77/+77
|
* Add StubUnsupportedJSOps to remove operations that JS does not support (#3024)Alon Zakai2020-08-052-0/+38
| | | | | | | | This doesn't lower them - it just replaces the unsupported operation with a drop. This will be useful for fuzzing, where to compare JS to the correct semantics we must avoid operations where JS is not always accurate. Also fully document the i64 -> f32 conversion issue in JS.
* Move generateDynCallThunks into its own pass. NFC. (#3000)Sam Clegg2020-08-042-0/+37
| | | | | | The core logic is still living in EmscriptenGlueGenerator because its used also by fixInvokeFunctionNames. As a followup we can figure out how to make these more independent.
* Refactor getMaxBits() out of OptimizeInstructions and add beginnings of unit ↵Alon Zakai2020-08-041-5/+29
| | | | | | | | | testing for it (#3019) getMaxBits just moves around, no logic is changed. Aside from adding getMaxBits, the change in bits.h is 99% whitespace. helps #2879
* Implement prototype v128.load{32,64}_zero instructions (#3011)Thomas Lively2020-08-035-4/+48
| | | | | | | | Specified in https://github.com/WebAssembly/simd/pull/237. Since these are just prototypes necessary for benchmarking, this PR does not add support for these instructions to the fuzzer or the C or JS APIs. This PR also renumbers the QFMA instructions that previously used the opcodes for these new instructions. The renumbering matches the renumbering in V8 and LLVM.