summaryrefslogtreecommitdiff
path: root/src/passes/SimplifyLocals.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [NFC] Enforce use of `Type::` on type names (#2434)Thomas Lively2020-01-071-17/+19
|
* Add support for reference types proposal (#2451)Heejin Ahn2019-12-301-2/+4
| | | | | | | | | | | | 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.
* Make local.tee's type its local's type (#2511)Heejin Ahn2019-12-121-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | According to the current spec, `local.tee`'s return type should be the same as its local's type. (Discussions on whether we should change this rule is going on in WebAssembly/reference-types#55, but here I will assume this spec does not change. If this changes, we should change many parts of Binaryen transformation anyway...) But currently in Binaryen `local.tee`'s type is computed from its value's type. This didn't make any difference in the MVP, but after we have subtype relationship in #2451, this can become a problem. For example: ``` (func $test (result funcref) (local $0 anyref) (local.tee $0 (ref.func $test) ) ) ``` This shouldn't validate in the spec, but this will pass Binaryen validation with the current `local.tee` implementation. This makes `local.tee`'s type computed from the local's type, and makes `LocalSet::makeTee` get a type parameter, to which we should pass the its corresponding local's type. We don't embed the local type in the class `LocalSet` because it may increase memory size. This also fixes the type of `local.get` to be the local type where `local.get` and `local.set` pair is created from `local.tee`.
* Reflect instruction renaming in code (#2128)Heejin Ahn2019-05-211-49/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - Reflected new renamed instruction names in code and tests: - `get_local` -> `local.get` - `set_local` -> `local.set` - `tee_local` -> `local.tee` - `get_global` -> `global.get` - `set_global` -> `global.set` - `current_memory` -> `memory.size` - `grow_memory` -> `memory.grow` - Removed APIs related to old instruction names in Binaryen.js and added APIs with new names if they are missing. - Renamed `typedef SortedVector LocalSet` to `SetsOfLocals` to prevent name clashes. - Resolved several TODO renaming items in wasm-binary.h: - `TableSwitch` -> `BrTable` - `I32ConvertI64` -> `I32WrapI64` - `I64STruncI32` -> `I64SExtendI32` - `I64UTruncI32` -> `I64UExtendI32` - `F32ConvertF64` -> `F32DemoteI64` - `F64ConvertF32` -> `F64PromoteF32` - Renamed `BinaryenGetFeatures` and `BinaryenSetFeatures` to `BinaryenModuleGetFeatures` and `BinaryenModuleSetFeatures` for consistency.
* clang-tidy braces changes (#2075)Alon Zakai2019-05-011-10/+20
| | | 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.
* Properly handle optimizing out a set from inside the value of another set in ↵Alon Zakai2019-04-291-3/+56
| | | | | | | SimplifyLocals (#2064) Details in lengthy comment in the source. Fixes #2063
* Apply format changes from #2048 (#2059)Alon Zakai2019-04-261-90/+170
| | | 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
* Optimize added constants with propagation only if we see we will remove all ↵Alon Zakai2019-03-061-25/+3
| | | | uses of the original add, as otherwise we may just be adding work (both an offset, and an add). Refactor local-utils.h, and make UnneededSetRemover also check for side effects, so it cleanly removes all traces of unneeded sets.
* SmallVector (#1912)Alon Zakai2019-02-251-1/+1
| | | | | Trying to refactor the code to be simpler and less redundant, I ran into some perf issues that it seems like a small vector, with fixed-size storage and optional additional storage as needed, might help with. This implements that class and uses it in a few places. This seems to help, I see some 1-2% fewer instructions and cycles in `perf stat`, but it's hard to tell if it really makes a noticeable difference.
* Massive renaming (#1855)Thomas Lively2019-01-071-28/+28
| | | | | | Automated renaming according to https://github.com/WebAssembly/spec/issues/884#issuecomment-426433329.
* Properly optimize loop values (#1800)Alon Zakai2018-12-051-30/+42
| | | Remove the existing hack, and optimize them just like we do for ifs and blocks. This is now able to handle a few more cases than before.
* Speculate in simplify-locals that it is worth turning an if intoAlon Zakai (kripken)2018-12-041-27/+95
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | an if-else. If an if sets a local, (if (..condition..) (set_local $x (..value..)) ) we can turn it into (set_local $x (if (..condition..) (..value..) (get_local $x) ) ) This increases code size and adds a branch in the if, but allows the set to be optimized into a tee or optimized out entirely. In the worst case, other optimizations can break up an if with a copy in one of its arms later. Includes a determinism fix for EquivalentSets, which this patch triggered.
* Switch optimizations in remove-unused-brs (#1753)Alon Zakai2018-11-201-2/+3
| | | | | | * Switch optimizations in remove-unused-brs: thread switch jumps, and turn a switch with all identical targets into a br * refinalize in interm operations in remove-unused-brs, as we can be confused by it
* Improve local-cse (#1594)Alon Zakai2018-06-081-1/+1
| | | | | 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
* Fix optimizing equivalent locals bug introduced in #1540 (#1556)Alon Zakai2018-05-171-4/+2
| | | Don't skip through flowing tee values, just drop the current outermost which we find is redundant. the child tees may still be necessary.
* Optimize equivalent locals (#1540)Alon Zakai2018-05-101-72/+205
| | | | | | | | | 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 some fuzz bugs (#1528)Alon Zakai2018-05-011-15/+28
| | | | | * 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-011-22/+63
| | | | | | * 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-301-57/+96
| | | | | 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.
* notation change: AST => IR (#1245)Alon Zakai2017-10-241-4/+4
| | | The IR is indeed a tree, but not an "abstract syntax tree" since there is no language for which it is the syntax (except in the most trivial and meaningless sense).
* fix simplify-locals bug where we create a br_if value, which is dangerous if ↵Alon Zakai2017-10-111-0/+46
| | | | we are moving code out of the br_if's condition - the value executes before (#1213)
* Add a superclass typedef to WalkerPass to simplify overrides (#1211)jgravelle-google2017-10-041-2/+2
|
* clean up untaken => unreachable, as well as unnecessary named stuff in ↵Alon Zakai2017-09-061-1/+1
| | | | validation that was from when we differentiated reachable from unreachable breaks (#1166)
* Return to more structured type rules for block and if (#1148)Alon Zakai2017-09-051-2/+3
| | | | | | | | * if a block has a concrete final element (or a break with a value), then even if it has an unreachable child, keep it with that concrete type. this means we no longe allow the silly case of a block with an unreachable in the middle and a concrete as the final element while the block is unreachable - after this change, the block would have the type of the final element * if an if has a concrete element in one arm, make it have that type as a result, even if the if condition is unreachable, to parallel block * make type rules for brs and switches simpler, ignore whether they are reachable or not. whether they are dead code should not affect how they influence other types in our IR.
* add the option to seek named breaks, not just taken breaks; refactor headers ↵Alon Zakai (kripken)2017-07-111-1/+1
| | | | to make this practical
* finalize new drops in SimplifyLocalsAlon Zakai (kripken)2017-07-111-0/+2
|
* Validate finalization (#1014)Alon Zakai2017-05-181-0/+1
| | | | | | | * validate that types are properly finalized, when in pass-debug mode (BINARYEN_PASS_DEBUG env var): check after each pass is run that the type of each node is equal to the proper type (when finalizing it, i.e., fully recomputing the type). * fix many fuzz bugs found by that. * in particular, fix dce bugs with type changes not being fully updated during code removal. add a new TypeUpdater helper class that lets a pass update types efficiently, by the helper tracking deps between blocks and branches etc., and updating/propagating type changes only as necessary.
* Default Walker subclasses to using Visitor<SubType> (#921)jgravelle-google2017-02-231-4/+4
| | | | Most module walkers use PostWalker<T, Visitor<T>>, let that pattern be expressed as simply PostWalker<T>
* Improve handling of implicit traps (#898)Alon Zakai2017-02-061-6/+4
| | | | | | | | * add --ignore-implicit-traps option, and by default do not ignore them, to properly preserve semantics * implicit traps can be reordered, but are side effects and should not be removed * add testing for --ignore-implicit-traps
* improve local simplication: simplify without if/block structure values ↵Alon Zakai2016-11-061-6/+9
| | | | before coalesce, so that coalesce can remove all copies, then do another pass of full simplification after it
* add variants of simplify-locals with and without teeing and structural optsAlon Zakai2016-11-051-11/+43
|
* refactor get_local counting out of simplify-locals (#812)Alon Zakai2016-10-281-19/+7
|
* when simplify-locals give br_if a value, the br_if also returns it, so it ↵Alon Zakai2016-10-131-4/+8
| | | | must be dropped
* fix a simplify-locals bug where we didn't notice and if already had a result ↵Alon Zakai2016-09-231-3/+2
| | | | value
* when optimizing a block return value, replacing the sunk set with the value ↵Alon Zakai2016-09-141-5/+14
| | | | is only possible if the break is unconditional; if it is condition, we must tee the value so that if the break condition is false and we do not jump, then we have the new value in the local on the line after it
* do a first pass in SimplifyLocals that focuses on single-use localsAlon Zakai2016-09-071-12/+36
|
* add drop and tee expressionsAlon Zakai2016-09-071-12/+30
|
* Add initialization functions for passes to avoid missing pass registration ↵Jukka Jylänki2016-06-211-1/+3
| | | | due to linker dead code elimination. Fixes #577.
* move function parallelism to pass and pass runner, which allows more ↵Alon Zakai2016-06-031-3/+5
| | | | efficient parallel execution (#564)
* refactor walk logic into walk* and doWalk* methods, for a more regular API ↵Alon Zakai2016-05-301-5/+5
| | | | that is clearer where it should be overridden (#551)
* vacuum away everything not tied downAlon Zakai2016-05-191-2/+1
|
* clear sinkables on unoptimizable blocks, as they have a control flow mergeAlon Zakai2016-05-051-6/+10
|
* note defaults of switches in SimplifyLocalsAlon Zakai2016-05-051-0/+1
|
* optimize block and if returns, by merging set_locals that flow out of themAlon Zakai2016-04-241-72/+300
|
* handle dead stores in SimplifyLocalsAlon Zakai2016-04-181-2/+3
|
* remove old comments in SimplifyLocalsAlon Zakai2016-04-181-2/+1
|
* create a UnifiedExpressionVisitor for passes that want a single visitor ↵Alon Zakai2016-04-181-3/+3
| | | | function, to avoid confusion with having both visit* and visitExpression in a single pass (#357)
* use a vector for get_local counts in SimplifyLocals (#356)Alon Zakai2016-04-181-1/+2
|
* index locals, so that get_local and set_local have just an index, and local ↵Alon Zakai2016-04-181-13/+13
| | | | names are kept on the Function object (#354)