summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* Only write explicit names to name section (#3241)Sam Clegg2020-10-154-28/+40
| | | | Fixes: #3226
* Fuzz fix for MemoryPacking on trampled data (#3222)Alon Zakai2020-10-152-3/+150
| | | | | | | | | | | | | I believe originally wasm did not allow overlapping segments, that is, where one memory segment tramples the data from a previous one. But then the spec changed its mind and we allowed it. Binaryen seems to have assumed the original case, and not checked for trampling. If there is a chance of trampling, we cannot optimize out zeros - the zero may have an effect if it tramples data from a previous segment. This does not occur in practice in LLVM output, which is why this wasn't a problem so far, I think. An existing testcase hit this issue, so I split it up.
* Log nested pass names in BINARYEN_PASS_DEBUG=2 (#3214)Alon Zakai2020-10-152-12/+20
| | | | We can't validate or print out the wasm in that case, but at least logging the names as they run can help debug some situations.
* Assign import names consistently between text and binaryn reader (#3238)Sam Clegg2020-10-143-7/+16
| | | | | | | | | The s-parser was assigning numbers names per-type where as the binaryn reader was using the global import count as the number to append. This change switches to use per-element count which I think it preferable as it increases the stability of the auto-generated names. e.g. memory is now always named `$mimport0`.
* [MemoryPacking] Emit the correct segment indices on memory.init (#3239)Thomas Lively2020-10-141-1/+6
| | | | | | | | | | | This PR fixes a bug in which the segment index of a memory.init instruction was incorrect in some circumstances. Specifically, the first segment index used in output memory.init instructions was always the index of the first segment created from splitting up the corresponding input segment. This was incorrect when the input memory.init had an offset that caused it to skip over that first emitted segment so that the first output memory.init should have referred to a subsequent output segment. Fixes #3225.
* Improve partial evaluation (#3236)Max Graey2020-10-141-2/+11
|
* PickLoadSigns fuzz fix: cannot make an atomic operation signed (#3235)Alon Zakai2020-10-131-0/+4
|
* Optimize power of two float divisions (#3018)Max Graey2020-10-133-5/+71
|
* EmscriptenPIC: Remove internalization of GOT entries (#3211)Sam Clegg2020-10-131-82/+3
| | | | | | | wasm-ld now does this better than binaryen and does it by default when linking and executable and optionally with `-Bsymbolic` when linking a shared library. See https://reviews.llvm.org/D89152
* Added Initial Memory64Lowering pass (#3230)Wouter van Oortmerssen2020-10-134-0/+93
| | | | This pass will convert a module with 64-bit loads and stores accessing a 64-bit memory to a regular 32-bit one. Pointers remain 64-bit but are truncated just before use.
* Fix Wasm capitalization in binaryen-c.h comments (#3233)Max Desiatov2020-10-131-2/+2
| | | According to the WebAssembly spec, Wasm is an abbreviation, not an acronym.
* Optimize unsigned divisions when rhs is negative constant (#2991)Max Graey2020-10-131-7/+22
| | | | | | | | `(uint32_t)x / C` --> `x >= C`, where `C > 2^31` `(uint32_t)x / -1` --> `x != -1` and for `shrinkLevel == 0`: `(uint64_t)x / C` --> `uint64_t(x >= C)`, where `C > 2^63` `(uint64_t)x / -1` --> `x != -1`
* Interpreter: Add a limit to how much we try to grow memory, to avoid DOS (#3227)Alon Zakai2020-10-123-5/+16
| | | | | growMemory() now also returns whether we succeeded. Without this it could eventually start to swap etc., which is annoying.
* Fuzzer: Do not emit random global.get/sets of the hang limit global (#3229)Alon Zakai2020-10-121-3/+16
| | | | | | | | | That global is for internal use. If we emit random sets to it, we could prevent it from doing its job of preventing an infinite loop (normally it decreases each time a loop runs or we recurse, until we reach 0 - if we set it to a nonzero value in that code, that would be bad). Random gets are less of a problem, but may be confusing when debugging a testcase.
* Slightly improve validator error text on segments (#3215)Alon Zakai2020-10-121-2/+2
| | | Mentioning if it's a memory or a table segment is convenient.
* Memory64 fuzzing preparations (#3223)Alon Zakai2020-10-121-7/+13
|
* Rename Emscripten EHSjLj functions in wasm backend (#3191)Heejin Ahn2020-10-104-150/+3
| | | | | | | | | | | Now that we are renaming invoke wrappers and `emscripten_longjmp_jmpbuf` in the wasm backend, this deletes all related renaming routines and relevant tests. Depends on #3192. Addresses: #3043 and #3081 Companions: https://reviews.llvm.org/D88697 emscripten-core/emscripten#12399
* RemoveUnusedBrs fuzz fix for switches with a single target and with a value ↵Alon Zakai2020-10-091-5/+12
| | | | | | (#3220) We turn a br_table with a single target into a br, but we reverse the order of the condition and the value when doing so, which we forgot to take into account.
* Refactor naming convention for functions handling tuples (#3196)Max Graey2020-10-0918-43/+73
| | | When there are two versions of a function, one handling tuples and the other handling non-tuple values, the previous naming convention was to have "Single" in the name of the non-tuple handling function. This PR simplifies the convention and shortens function names by making the names plural for the tuple-handling version and singular for the non-tuple-handling version.
* Add a little code to prepare exception handling support in fuzzer (#3207)Alon Zakai2020-10-091-4/+6
| | | | | | | fixLabels() in the fuzzer looks for invalid labels and fixes them up, after doing some random changes to existing wasm (which checks for types while doing so, but it may invalidate labels if we remove the target of a branch, for example). This adds trivial support for BrOnExn and Try there.
* Optimize getLoggableTypes in fuzzer, and add isLoggableType (#3208)Alon Zakai2020-10-091-7/+17
| | | | | | | Previously getLoggableType would allocate a vector every time. This caches it. Also add isLoggableType which will need this caching as I will be calling it quite a lot in a future patch to the fuzzer.
* Validate memory64 (#3202)Alon Zakai2020-10-082-1/+6
|
* Fuzz fix for DuplicateFunctionElimination (#3204)Alon Zakai2020-10-081-1/+3
| | | | The replaceFunctions utility replaced exports by name, but did not check the kind, so it could get confused when names happen to overlap.
* Add static guards for cast and dynCast (#3201)Max Graey2020-10-081-1/+13
|
* Remove RelooperJumpThreading pass, which was just for fastcomp (#3199)Alon Zakai2020-10-084-286/+0
| | | See emscripten-core/emscripten#11860
* Remove old attempted DSL beginnings from OptimizeInstructions (#3200)Alon Zakai2020-10-083-73/+0
| | | | | | Wasm turned out to not be that good for a DSL for such peephole optimizations, so that never made progress. Meanwhile we have the new matcher stuff which works well.
* Add optimization rules for some shift operations (#3099)Max Graey2020-10-072-0/+42
| | | Specifically, truncates constant shift values that are greater than the number of bits available and optimizes out explicit masking of the shift value that is redundant with the implicit masking performed by shift operations.
* Revert some changes for #3193 (#3197)Max Graey2020-10-061-15/+14
| | | `(signed)x % (i32|i64).min_s ==> (x & (i32|i64).max_s)` is not valid unless compared to zero.
* refactor makeFromUInt64 to makeFromInt64 (#3194)Max Graey2020-10-053-6/+9
| | | For consistency with `makeFromInt32`.
* fast-math: Fold `fp * -1` to `-fp` (#3189)Max Graey2020-10-051-2/+5
|
* Generalize transforms for #3153 (#3193)Max Graey2020-10-052-11/+97
| | | | | | | | | | | | | | Implement a more general (additional) version of #3153 which also handles negative constant divisors: `(int32)x % -4 == 0` --> `(x & 3) == 0` `x % -C_pot == 0` --> `(x & (abs(C_pot) - 1)) == 0` and special two-complement values as well: `(int32)x % 0x80000000 == 0` --> `(x & 0x7fffffff) == 0` `(int64)x % 0x8000000000000000 == 0` --> `(x & 0x7fffffffffffffff) == 0` as separete rules: `(int32)x % 0x80000000` --> `x & 0x7fffffff` `(int64)x % 0x8000000000000000` --> `x & 0x7fffffffffffffff` The [previous pr](https://github.com/WebAssembly/binaryen/pull/3153) didn't use these possibilities.
* Ordering correction fix in OptimizeInstructions for #3047 (#3195)Alon Zakai2020-10-051-2/+12
| | | | | | | | | | | | (found by the fuzzer) It is not valid to replace x | (y | x) ==> y | x, if x, y cannot be reordered. It is also not valid to replace x ^ (y ^ x) ==> y, if x, y cannot be reordered, for a more subtle reason: if they cannot be reordered then y can affect the value of x (the opposite is not possible as we checked x for side effects so that we could remove one copy). If so, then the second appearance of x could be different, if e.g. it reads a local y writes to. Whereas, if it's ok to reorder, then it's ok to do x ^ (y ^ x) ==> x ^ (x ^ y) ==> y.
* Let GenerateDynCalls generate dynCalls for invokes (#3192)Heejin Ahn2020-10-023-76/+87
| | | | | | This moves dynCall generating functionaity for invokes from `EmscriptenGlueGenerator` to `GenerateDynCalls` pass. So now `GenerateDynCalls` pass will take care of all cases we need dynCalls: functions in tables and invokes.
* Simplify some numeric code (#3186)Max Graey2020-10-014-19/+7
|
* Optimize "clear bit mask" combination to cyclic rotation over preinverted ↵Max Graey2020-10-012-0/+24
| | | | mask (#3184)
* Add comment about signed => unsigned lowering (#3187)Max Graey2020-10-011-0/+5
|
* Stop generating __growWasmMemory (#3180)Sam Clegg2020-10-015-17/+0
| | | This depends on https://github.com/emscripten-core/emscripten/pull/12391
* Add C and JS APIs for fast math (#3188)Max Graey2020-10-013-0/+26
| | | Adds `BinaryenGetFastMath` and `BinaryenSetFastMath` to the C API, respectively `binaryen.getFastMath` and `binaryen.setFastMath` to the JS API.
* wasm2js: override incoming memory's grow method (#3185)Sam Clegg2020-09-301-6/+40
| | | | | | | | | | This will allow for the completely removal of `__growWasmMemory` as a followup. We currently unconditionally generate this function in `generateMemoryGrowthFunction`. See #3180
* Clean up support/bits.h (#3177)Thomas Lively2020-09-308-90/+93
| | | | | Use overloads instead of templates where applicable and change function names from PascalCase to camelCase. Also puts the functions in the Bits namespace to avoid naming conflicts.
* Remove unnecessary "new" on Table generation in wasm2js (#3163)Alon Zakai2020-09-301-2/+1
| | | It's not an actual constructor, just a JS function that returns the object.
* Add --fast-math mode (#3155)Alon Zakai2020-09-304-46/+27
| | | | | | | | | | | | Similar to clang and gcc, --fast-math makes us ignore corner cases of floating-point math like NaN changes and (not done yet) lack of associativity and so forth. In the future we may want to have separate fast math flags for each specific thing, like gcc and clang do. This undoes some changes (#2958 and #3096) where we assumed it was ok to not change NaN bits, but @binji corrected us. We can only do such things in fast math mode. This puts those optimizations behind that flag, adds tests for it, and restores the interpreter to the simpler code from before with no special cases.
* Fold i32.eqz(wrap_i64(x)) -> i64.eqz(x) where possible (#3181)Max Graey2020-09-301-0/+12
| | | Specifically, when `x` has at most 32 bits so that wrapping doesn't change its value.
* Simplify signed remainders compared with zero (#3153)Max Graey2020-09-291-9/+29
| | | | | | Specifically when the divisor is a power of two. `eqz((signed)x % C_pot)` -> `eqz(x & (C_pot - 1))` `(signed)x % C_pot != 0` -> `x & (C_pot - 1) != 0`
* Fix applying default / unify SExpr and Wasm builder names (#3179)Daniel Wirtz2020-09-301-5/+7
| | | SExpressionWasmBuilder was not applying default memory and table import names on the memory and table, unlike on functions, globals and events, where it applies them. Also aligns default import names to use the same shorter forms as in binary parsing.
* GC: Add stubs for the remaining instructions (#3174)Daniel Wirtz2020-09-2924-44/+1513
| | | NFC, except adding most of the boilerplate for the remaining GC instructions. Each implementation site is marked with a respective `TODO (gc): theInstruction` in between the typical boilerplate code.
* Add also non-equal with zero simplification for boolean context (#3178)Max Graey2020-09-291-2/+3
|
* GC: Fuzzing support for i31 (#3169)Daniel Wirtz2020-09-297-31/+61
| | | Integrates `i31ref` types and instructions into the fuzzer, by assuming that `(i31.new (i32.const N))` is constant and hence suitable to be used in global initializers.
* Prototype extended-name-section proposal (#3162)Daniel Wirtz2020-09-292-26/+182
| | | Implements the parts of the Extended Name Section Proposal that are trivially applicable to Binaryen, in particular table, memory and global names. Does not yet implement label, type, elem and data names.
* Refactor literal equality and hashing to not depend on getBits (#3159)Daniel Wirtz2020-09-292-33/+107
| | | Comparing and hashing literals previously depended on `getBits`, which was fine while there were only basic numeric types, but doesn't map well to reference types anymore. Hence this change limits the use of `getBits` to basic numeric types, and implements reference types-aware comparisons and hashing do deal with the newer types.