summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* wasm2asm: Add math aliases for floor, ceil and sqrt (#1549)Daniel Wirtz2018-05-141-0/+3
|
* Implement 64-bit rotation lowering for wasm2asm (#1545)Alex Crichton2018-05-141-2/+193
| | | | Not much fancy here, but rather each operation is naively lowered inline to the if/else chain to execute it.
* wasm2asm: Implement reinterpretation instructions (#1547)Alex Crichton2018-05-132-3/+58
| | | | | | | | | | | | | As mentioned in #1458 a naive implementation of these instructions is to round trip the value through address 0 in linear memory. Also pointed out in #1458 this isn't necessarily valid for all languages. For now, though, languages like Rust, C, and C++ would likely be horribly broken if valid data could be stored at low addresses, so this commit goes ahead and adds an implementation of the reinterpretation instructions by traveling data through address 0. This will likely need an update if a language comes a long which can validly store data in the first 8 bytes of linear memory, but it seems like that won't happen in the near future. Closes #1458
* Implement signed 64-bit shift right for wasm2asm (#1544)Alex Crichton2018-05-121-6/+72
| | | | Mostly piggy-back pon the previous 64-bit shift lowering code, just filling in a few gaps.
* Merge loop tails up (#1543)Alon Zakai2018-05-101-29/+93
| | | | | | | | | | | | | | | E.g. ``` (block .. (loop $l .. (br_if $l (..)) .. code that does not branch to the loop top ) .. that code could be moved here .. ) ``` Moving the code out of the loop may help the loop body become a singleton expression, and is more readable anyhow.
* Move the renaming of llvm-generated __invoke_XX functions from s2wasm into ↵Sam Clegg2018-05-104-86/+144
| | | | | | | | | wasm-emscripten (#1539) This allows the same functionality to be used also in wasm-emscripten-finalize (i.e. the lld path).
* Optimize equivalent locals (#1540)Alon Zakai2018-05-107-80/+329
| | | | | | | | | If locals are known to contain the same value, we can * Pick which local to use for a get_local of any of them. Makes sense to prefer the most common, to increase the chance of one dropping to zero uses. * Remove copies between a local and one that we know contains the same value. This is a consistent win, small though, around 0.1-0.2%.
* Fix MSVC warnings when compiling the binaryen target (#1535)Daniel Wirtz2018-05-098-24/+18
|
* Add a way to remove function types to Binaryen-C/.js (#1536)Daniel Wirtz2018-05-083-0/+24
|
* More reducer improvements (#1533)Alon Zakai2018-05-084-136/+409
| | | | | | * 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.
* Expose sign extension ops in Binaryen-C/.js (#1534)Daniel Wirtz2018-05-073-1/+31
|
* improve remove-unused-module-elements (#1532)Alon Zakai2018-05-044-13/+52
| | | | | 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)
* misc minor cleanups in the codebase (#1531)Alon Zakai2018-05-042-1/+3
|
* add missing atomics to getExpressionName, which is used in --metrics (#1529)Alon Zakai2018-05-041-0/+4
|
* Fix some fuzz bugs (#1528)Alon Zakai2018-05-012-16/+29
| | | | | * remove-unused-brs: handle an if declared as returning a value despite having an unreachable condition * simplify-locals: don't work on loops while the main pass is making changes, as set_locals are being tracked and modified.
* Generate loop return values in optimizer (#1527)Alon Zakai2018-05-011-0/+24
|
* More simplify-locals opts (#1526)Alon Zakai2018-05-013-22/+116
| | | | | | * 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-58/+99
| | | | | 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.
* Make generating atomics optional in translate-to-fuzz (#1513)Jonathan Foote2018-04-301-7/+8
|
* flatten improvement (#1522)Alon Zakai2018-04-301-8/+2
|
* do more optimizations after inlining: precompute-propagate plus all regular ↵Alon Zakai2018-04-301-10/+2
| | | | opts (#1523)
* add --converge option to wasm-opt (#1524)Alon Zakai2018-04-302-28/+51
| | | | | 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-271-0/+20
|
* improve --extract-function (#1517)Alon Zakai2018-04-271-4/+22
| | | Remove more of the unwanted stuff, and leave just an export to the function we are extracting. Then optimizations can do an effective cleanup.
* precompute-propagate may benefit from multiple passes (#1518)Alon Zakai2018-04-271-8/+19
| | | 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-262-4/+23
| | | | | | | | 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-261-5/+31
| | | Propagate constants through a tee_local. Found by Souper. Details in patch comments - basically we didn't differentiate precomputing a value and an expression.
* Refactor interpreter (#1508)Alon Zakai2018-04-133-199/+220
| | | | | | * Move more logic to the Literal class. We now leave all the work to there, except for handling traps. * Avoid switching on the type, then the opcode, then Literal method usually switches on the type again - instead, do one big switch for the opcodes (then the Literal method is unchanged) which is shorter and clearer, and avoids that first switching.
* Better binary error reporting (#1505)Alon Zakai2018-04-134-67/+79
| | | | | Report the offset with the error. Also fix a compiler warning about comparing signed/unsigned types in the LEB code.
* fix typo [ci skip]Alon Zakai (kripken)2018-04-111-1/+1
|
* More math opts (#1507)Alon Zakai2018-04-111-3/+20
| | | `xor` of 0, `and` and `or` of -1
* More simple math opts (#1506)Alon Zakai2018-04-111-2/+72
| | | | | * 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-1112-37/+312
| | | | | | | | | 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-104-8/+29
| | | 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-103-12/+116
| | | | | | | | | | 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.
* add a --no-validation option to the commandline tools. disabling validation ↵Alon Zakai2018-04-094-18/+34
| | | | makes loading large wasm files more than twice as fast (#1496)
* Handle literally unreachable brs (#1497)Alon Zakai2018-04-072-8/+32
| | | | | 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.
* when creating blocks in binary format parsing, we know if a block has a ↵Alon Zakai2018-04-054-13/+31
| | | | break to it - use that to avoid rescanning blocks for unreachability purposes (#1495)
* Use .set instead of = for aliases (#1491)Heejin Ahn2018-03-301-26/+27
| | | | | | | | | | | | 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.
* refactor Path utils: store the bin/ dir so that all users of the API can use ↵Alon Zakai2018-03-304-54/+109
| | | | 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-262-10/+130
|
* remap {get,set}_local indices (#1486)Nathan Froyd2018-03-231-7/+16
| | | | | | | | | | 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-221-0/+1
| | | | | | | 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-201-0/+9
| | | | | 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-2/+3
| | | | unreachable, the modified version is as well (#1481)
* check for errors when parsing s-expression load/store immediates (#1475)Alon Zakai2018-03-161-2/+6
|
* validate we are in a function context when adding a label in binary parsing. ↵Alon Zakai2018-03-162-18/+20
| | | | found by valgrind (#1478)
* create Math_{min,max} variables for wasm2asm-generated JS (#1476)Nathan Froyd2018-03-163-0/+6
| | | | | | | | | 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.
* 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.