summaryrefslogtreecommitdiff
path: root/test
Commit message (Collapse)AuthorAgeFilesLines
...
* More simplify-locals opts (#1526)Alon Zakai2018-05-0120-31692/+31739
| | | | | | * Use an if return value when one side is unreachable. * Undo an if return value if we can use a br_if instead
* --simplify-locals-nonesting (#1525)Alon Zakai2018-04-303-29/+479
| | | | | Add a version of simplify-locals which does not create nesting. This keeps the IR flat (in the sense of --flatten). Also refactor simpify-locals to be a template, so the various modes are all template parameters.
* flatten improvement (#1522)Alon Zakai2018-04-302-107/+173
|
* do more optimizations after inlining: precompute-propagate plus all regular ↵Alon Zakai2018-04-3017-1971/+1528
| | | | opts (#1523)
* add --converge option to wasm-opt (#1524)Alon Zakai2018-04-302-0/+761
| | | | | The option keeps running the passes (that we were told to run) in cycles until we converge in terms of the binary size, that is, keep optimizing until we can't shrink any more. Also fix a --metrics bug this uncovered: we can't expect the Metrics object to still be around if running passes later in another PassRunner.
* optimize selects of constant conditions (#1516)Alon Zakai2018-04-272-14/+95
|
* precompute-propagate may benefit from multiple passes (#1518)Alon Zakai2018-04-272-0/+23
| | | One pass may remove code that includes a tee which then makes more optimization possible. Found by the Souper investigations.
* code-folding improvements (#1512)Alon Zakai2018-04-2611-99/+151
| | | | | | | | Noticed by Souper. * We only folded identical code in an if-else when both arms were blocks, so we were missing the case of one arm being just a singleton expression. This PR will wraps that in a block so the rest of the optimization can work on it, if it sees it is going to be folded out. Turns out this is common for phis. * We only ran code-folding in -Os, because I assumed it was just good for code size, but as it may remove phis in the wasm VM later, seems like we should run it when not optimizing for size as well. Together, these two shrink lua -O3 by almost 1%.
* Improve precompute-propagate (#1514)Alon Zakai2018-04-264-36/+53
| | | Propagate constants through a tee_local. Found by Souper. Details in patch comments - basically we didn't differentiate precomputing a value and an expression.
* More math opts (#1507)Alon Zakai2018-04-112-0/+69
| | | `xor` of 0, `and` and `or` of -1
* More simple math opts (#1506)Alon Zakai2018-04-112-4/+359
| | | | | * Optimize shifts of 0. * Optimize f(x, x) for various f (e.g., x & x => x).
* Some simple integer math opts (#1504)Alon Zakai2018-04-115-6/+632
| | | | | | | | | Stuff like x + 5 != 2 => x != -3. Also some cleanups of utility functions I noticed while writing this, isTypeFloat => isFloatType. Inspired by https://github.com/golang/go/blob/master/src/cmd/compile/internal/ssa/gen/generic.rules
* Fix bad param/var type error handling (#1499)Alon Zakai2018-04-102-0/+344
| | | Improve error handling, validation, and assertions for having a non-concrete type in an inappropriate place. Fixes a fuzz testcase.
* br_table optimizations (#1502)Alon Zakai2018-04-1017-111/+566
| | | | | | | | | | Inspired by #1501 * remove unneeded appearances of the default switch target (at the front or back of the list of targets) * optimize a switch with 0, 1 or 2 targets into an if or if-chain * optimize a br_if br pair when they have the same target Makes e.g. fastcomp libc++ 2% smaller. Noticeable improvements on other things like box2d etc.
* Handle literally unreachable brs (#1497)Alon Zakai2018-04-072-0/+9
| | | | | The optimization in #1495 had a bug which was found by the fuzzer: our binary format parsing will not emit unreachable code (it may be stacky, so we ignore it). However, while parsing it we note breaks that are taken there, and then we removed that code, leading to a state where a break was not taken in the code, but we thought it was. This PR clarifies the difference between unreachable code in the wasm sense (anything from the start of a block til an unreachable is "reachable") and the literal sense (even that code at the start may not be literally reachable if the block is not reachable), and then we use literal unreachability to know what code will be ignored and therefore we should ignore breaks in.
* Use .set instead of = for aliases (#1491)Heejin Ahn2018-03-301-4/+4
| | | | | | | | | | | | llvm-mirror/llvm@9273bb3([Phabricator](https://reviews.llvm.org/D44256)) changed alias assignment syntax from ``` x = y ``` to ``` .set x, y ``` This patch reflects the change.
* remap {get,set}_local indices (#1486)Nathan Froyd2018-03-232-0/+101
| | | | | | | | | | When lowering i64 values in a function, we create new local variables for all of the i64 local variables, one local for the low bits, and one for the high bits. We create a mapping between the old locals and the new as well. During translation, when we encountered a `get_local` that didn't have type `i64`, we skipped it, on the supposition that there was nothing to do. But that's not true; the local it was getting may have been remapped to a new index in the lowered function, and we need to account for that change. Similar logic holds for `set_local`.
* reorder locals in wasm2asm (#1482)Nathan Froyd2018-03-2215-443/+338
| | | | | | | The documentation for the simplify-locals pass suggests running reorder-locals after it to clean up unnecessary locals. wasm2asm wasn't doing this, which meant that generated code had a number of unused variables. A good minimizer will probably clean that up, but let's go ahead and clean it up in wasm2asm itself.
* add the highbits global to the IR (#1483)Nathan Froyd2018-03-2015-0/+15
| | | | | We were using the global to return 64-bit values from functions, but said global wasn't actually present in the IR. This omission caused the generated code to fail validation.
* fix a fuzz bug in fpcast-emu: if the call_indirect we are modifying is ↵Alon Zakai2018-03-192-0/+59
| | | | unreachable, the modified version is as well (#1481)
* create Math_{min,max} variables for wasm2asm-generated JS (#1476)Nathan Froyd2018-03-1615-0/+30
| | | | | | | | | We were using Math_{min,max} in wasm2asm-generated files without declaring said functions. This decision created problems for tests, because Math_min (resp. max) would first be used on f32s, thus returning f32, and then validation would fail when it was used on f64s. The resulting changes make wasm2asm tests pass with MOZJS asm.js validation, which moves #1443 forward.
* Function pointer cast emulation (#1468)Alon Zakai2018-03-134-6/+348
| | | | | | | | | | | This adds a pass that implements "function pointer cast emulation" - allows indirect calls to go through even if the number of arguments or their types is incorrect. That is undefined behavior in C/C++ but in practice somehow works in native archs. It is even relied upon in e.g. Python. Emscripten already has such emulation for asm.js, which also worked for asm2wasm. This implements something like it in binaryen which also allows the wasm backend to use it. As a result, Python should now be portable using the wasm backend. The mechanism used for the emulation is to make all indirect calls use a fixed number of arguments, all of type i64, and a return type of also i64. Thunks are then placed in the table which translate the arguments properly for the target, basically by reinterpreting to i64 and back. As a result, receiving an i64 when an i32 is sent will have the upper bits all zero, and the reverse would truncate the upper bits, etc. (Note that this is different than emscripten's existing emulation, which converts (as signed) to a double. That makes sense for JS where double's can contain all numeric values, but in wasm we have i64s. Also, bitwise conversion may be more like what native archs do anyhow. It is enough for Python.) Also adds validation for a function's type matching the function's actual params and result (surprised we didn't have that before, but we didn't, and there was even a place in the test suite where that was wrong). Also simplifies the build script by moving two cpp files into the wasm/ subdir, so they can be built once and shared between the various tools.
* Let s2wasm emit binary output (#1465)Jacob Gravelle2018-03-0896-96/+96
| | | | | | | | | | | | | | | | | | | | * Emit invokeFuncs list as metadata * Refactor s2wasm to use ModuleWriter * Fix wasm-emscripten-finalize metadata output for binary output * Add a flag to emit binary from s2wasm NOTE: I chose to emit text by default, and binary behind a flag. This mismatches with asm2wasm (and the expectations of users of a "2wasm" tool), but doesn't break any existing users of s2wasm. If s2wasm is deprecated in favor of lld, this will be the least disruptive change, and we won't have to live with awkward defaults for too long. * Emit source maps in the binary output of s2wasm * Only emit binary with an outfile specified
* Allow small names in test/passes (#1450)Alon Zakai2018-03-053-0/+1
| | | | | * allow tests in test/passes/ to have a numeric name, in which case there is a name.passes file with the names instead of the name containing the passes (which might be long, see #1020)
* eliminate multiple return statements for wasm2asm functions (#1448)Nathan Froyd2018-03-0115-204/+101
| | | | This change eliminates one issue that prevents asm.js validation of the generated code, see #1443.
* Drop 'start' in RemoveUnusedModuleElements if the function is empty (#1449)Daniel Wirtz2018-02-282-3/+22
| | | | | | * Drop start function in RemoveUnusedModuleElements if empty * Update tests and dist files
* Fuzz parameter improvements: more params&vars (#1451)Alon Zakai2018-02-281-979/+1030
|
* Flexible param numbers in asm2wasm (#1439)Alon Zakai2018-02-277-0/+183
| | | | | | | | | | * refactor BINARYEN_PASS_DEBUG code for writing byn-* files, make it easy to emit binaries instead of text * fix up bad argument numbers in asm2wasm. This can be caused by undefined behavior on the LLVM side, which happens to work natively. it's nicer to fix it up like it would be in a native build, and give a warning, instead of failing to compile * update build-js.sh * updated builds
* EM_JS binaryen support (#1410)Jacob Gravelle2018-02-262-0/+79
| | | | | | | | | | | * Emit EM_JS metadata * Include s2wasm-style em_js support * Change em_js metadata to be keyed on name * Add testcase for em_js, don't always emit emJsFuncs metadata * Better error handling for unexpectedly-formatted __em_js__ functions
* fix and implement more unary ops (#1442)Nathan Froyd2018-02-262-0/+313
| | | | | | | | | | | | | | | | | | * add tests for i32.popcnt * lower i64.popcnt * add tests for i64.extend_u/i32 * lower i64.extend_s/i32 * fix lowering i64.eqz * lower i64.eqz more efficiently * add tests for i32.clz/i32.ctz * lower i64.clz/i64.ctz
* Generate all s2wasm metadata in binaryen (#1440)Jacob Gravelle2018-02-2695-95/+95
| | | | | | | | | * Extract comma-handling logic into a lambda function * Start emitting all metadata from binaryen - handle declares and externs * Add implementedFunctions and exports metadata * Remove EM_ASM calls from declares
* fix an ssa bug: we can't assume that even if all set locations assign to the ↵Alon Zakai2018-02-222-10/+125
| | | | same local that it is ok to read that local, as locals may also be written elsewhere (#1423)
* ensure unique import names for each type, by giving them a prefix, avoiding ↵Alon Zakai2018-02-228-57/+57
| | | | collisions between say a global import and a function with a name from the name section that happens to match it (#1424)
* Add i64 high bits (tempRet0) helper funcs when legalizing JS interface (#1428)Alon Zakai2018-02-2214-0/+165
| | | | * add tempRet0 helpers when necessary in legalize-js-interface
* Improve name mangling of asm.js identifiers (#1433)Daniel Wirtz2018-02-2114-925/+925
| | | | | | Also refactors mangling to its own file so it can be reused by generators and consumers, i.e., where it is important to know that an import must be named 'switch_' where it otherwise would be 'switch'. * Update tests and JS dist files
* wasm2asm fixes (#1436)Alon Zakai2018-02-201-6/+6
| | | | | | * don't look for asm.js compilation message if almost asm * fix wasm2asm f32 operations
* better handling of float ops in wasm2asm (#1427)Nathan Froyd2018-02-152-0/+378
| | | | | | | | | | | | | | | | | | | | * explicitly handle binary float operations in processFunctionBody We weren't handling them before, but it wasn't obvious. Make the (non-) handling of them explicit in the code. We'll add handlers for them shortly. * add handling for simple binary float operations min, max, and copysign will require more sophisticated handling. * add handling for float comparisons * move float min/max handling to the correct place It was previously grouped with the i32 ops. * handle float promotion and demotion
* implement lowering for i64 subtraction (#1429)Nathan Froyd2018-02-142-0/+169
| | | | | | | | | * fix lowering of i64 adds We're not permitted to reuse the input as temporary variables for the results. Weird things happen otherwise. * add support for lowering i64 subtraction
* add wasm2asm lowering for 64-bit signed comparisons (#1421)Nathan Froyd2018-02-142-0/+485
| | | Plus some tests, to make sure we implemented things correctly.
* Fold wasm-link-metadata into wasm-emscripten-finalize (#1408)Jacob Gravelle2018-02-1422-77/+99
| | | | | | | * wasm-link-metadata: Use `__data_end` symbol. * Add --global-base param to emscripten-wasm-finalize to compute staticBump properly * Let ModuleWriter write to a provided Output object
* More simple math opts (#1414)Alon Zakai2018-02-148-80/+289
| | | | | | | | * optimize more simple math operations: mul of 0, or of 0, and of 0, mul of 1, mul of a power of 2, urem of a power of 2 * fix asm2wasm callImport parsing: the optimizer may get rid of the added offset to a function table * update js builds
* Fix safe-heap bounds checking (#1415)Alon Zakai2018-02-121-185/+185
| | | | | * fix safe heap check for load/store of fewer bytes than the type
* Emscripten addFunction support for Wasm backend (#1395)Heejin Ahn2018-02-0710-0/+1083
| | | This adds necessary command line options for addFunction support, and generates required jsCall imports and generates jsCall thunk functions.
* Dedupe function names when reading a binary (#1396)Jacob Gravelle2018-02-064-0/+26
| | | | | | | | * Dedupe function names when reading a binary * More robust name deduplication, use .s instead of _s * Add name-duplicated wasm binaries
* Update wasm2asm to generate "almost asm" if grow_memory is used (#1340)Kris Selden2018-02-065-0/+176
| | | | | | | | | | * Allow wasm2asm to generate "almost asm" If grow_memory, current_memory or export memory is used then generate "almost asm" with memory growth support. * Log reason for "almost asm" to stderr
* Note isAtomic in loads and stores (#1406)Alon Zakai2018-02-052-0/+33
| | | | | | * check isAtomic in comparisons * hash isAtomic
* Inlining improvements (#1397)Alon Zakai2018-02-028-327/+392
| | | | | | | Simplify inlining logic: don't special case the first iteration or change behavior based on when we are optimizing or not. Instead, use one simpler set of heuristics for both inlining and inlining-optimizing. We only run inlining-optimizing by default anyhow, no point to try to make inlining without optimizations useful by itself, it's not a realistic use case. (inlining is still useful for debugging, and if you will run optimizations anyhow later on everything, in which case inlining-optimizing might add some redundancy.) The simpler heuristics after this let us do a somewhat better job as we are no longer paranoid about inlining in multiple iterations. Also raise limit on inlining things that are obviously worth it from size 1 to size 2: things of size 2 will never lead to an increase in code size after we optimize (it takes at least 3 nodes to generate something that reads two locals and reverses their order, which would require a temp local in the outside scope etc.). Also fix infinite recursion of inlining an infinitely recursive set of calls.
* Fix hard-wired buffer limit in the JS API (#1394)Daniel Wirtz2018-02-011-1/+1
|
* Sourcemap support for Binaryen C/JS (#1392)Daniel Wirtz2018-01-292-0/+47
| | | | | | * Initial source map support for C/JS * Also test getDebugInfoFileName
* ThreadPool refactoring (#1389)Alon Zakai2018-01-262-0/+62
| | | | | | | | Refactor ThreadPool code for clarity and to fix some bugs with using the pool from different threads in parallel. We have a singleton pool, and need to ensure it is created only once and used only by one thread at a time. This model is a simple way to ensure we use a number of threads equal to the number of cores, more or less (a pool per Module might lead to number of cores * number of Modules being optimized). This refactoring adds a parent pointer in the worker threads (giving them direct access to the pool makes it simpler to make sure that pool and thread creation and teardown are threadsafe). This commit also adds proper locking around pool creation and pool usage.