summaryrefslogtreecommitdiff
path: root/src/passes/RemoveUnusedBrs.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Reflect instruction renaming in code (#2128)Heejin Ahn2019-05-211-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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-28/+56
| | | 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.
* Apply format changes from #2048 (#2059)Alon Zakai2019-04-261-260/+321
| | | 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
* Massive renaming (#1855)Thomas Lively2019-01-071-10/+10
| | | | | | Automated renaming according to https://github.com/WebAssembly/spec/issues/884#issuecomment-426433329.
* remove-unused-brs: do not flow a value through a block if the block does not ↵Alon Zakai2018-12-181-6/+18
| | | | actually flow a value. fixes #1833 (#1835)
* remove unnecessary constraint on remove-unused-br optimization of if-br-* ↵Alon Zakai2018-12-041-1/+1
| | | | into br_if,* - we can handle a concretely typed if as well, which can happen at the end of a block (#1799)
* Improve selectification in remove-unused-brsAlon Zakai (kripken)2018-12-041-19/+37
| | | | | | | | We turned an if into a select when optimizing for size (and if side effects etc. allow so). This patch improves that, doing it not just when optimizing for size, but also when it looks beneficial given the amount of work on both sides of the if. As a result we can create selects in -O3 etc.
* Move if copy logic from coalesce-locals to remove-unused-brs.Alon Zakai (kripken)2018-12-041-31/+128
| | | | | | | | | | | | | | | | | | | | | | | If copies is the case where an if arm is a get that feeds into a set of the same local: (set_local $x (if (result i32) (..condition..) (..result) (get_local $x) ) ) We can rework this so that the if-else is only an if, which executes the code path not going to the get. This was done in coalesce-locals only because it is likely to work there as after coalescing there are more copies. However, the logic is of removing a branch, and so belongs in remove-unused-brs, and fits alongside existing logic there for handling ifs with an arm that is a br. Also refactor that code so that the two optimizations can feed into each other.
* Switch optimizations in remove-unused-brs (#1753)Alon Zakai2018-11-201-39/+55
| | | | | | * 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
* Fix a merge-blocks fuzz bug (#1755)Alon Zakai2018-11-191-2/+73
| | | | | | * Moving blocks into if arms may change the block type, and the code we had was written under the assumption that was not true. * Move block sinking merge-blocks => remove-unused-brs, as it's more natural there. that pass refinalizes everything anyhow
* Don't try to optimize away unused names in RemoveUnusedBrs (#1750)Alon Zakai2018-11-151-1/+0
| | | | | Rely on the dedicated pass for that. It's not worth the extra complexity to try, as we can't easily handle all the cases anyhow. Add another run of the dedicated name-removing pass in the default passes.
* Restructure ifs with a value (#1743)Alon Zakai2018-11-141-20/+70
| | | We previously had code to recreate an if from a block+branch when possible, but not when the block had a return value. This PR adds support to restructure that too, into an if with a value.
* Fix value flowing in remove-unused-brs (#1639)Alon Zakai2018-08-201-24/+28
| | | | | The fuzzer found a bug with flowing of values in that pass: when one arm of an if is none-typed, we can't flow a value through the other. Odd the fuzzer didn't find this earlier, as it's been a bug since the pass was written years ago, but in practice it seems you need a specific set of circumstances on the outside for it to be hit. The fix is to stop flowing a value in that case. Also, I realized after fixing it that the valueCanFlow global state variable is entirely unneeded. Removing it makes the pass significantly simpler: at all times, flows contains branches and values that might be flowing, and if the flow stops we remove them, etc. - we don't need an extra state variable to say if flowing is possible. So when we want to use the flows, we just check what is there (and then for a flowing branch we can remove it, and for a flowing value we can replace the branch with the value, etc., as in both cases they flow to the right place anyhow).
* Fix MSVC warnings when compiling the binaryen target (#1535)Daniel Wirtz2018-05-091-1/+1
|
* Fix some fuzz bugs (#1528)Alon Zakai2018-05-011-1/+1
| | | | | * 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.
* More simplify-locals opts (#1526)Alon Zakai2018-05-011-0/+52
| | | | | | * Use an if return value when one side is unreachable. * Undo an if return value if we can use a br_if instead
* br_table optimizations (#1502)Alon Zakai2018-04-101-12/+110
| | | | | | | | | | 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.
* Rename WasmType => Type (#1398)Alon Zakai2018-02-021-4/+4
| | | | * rename WasmType to Type. it's in the wasm:: namespace anyhow, and without Wasm- it fits in better alongside Index, Address, Expression, Module, etc.
* br_if-to-table (#1313)Alon Zakai2017-12-041-6/+170
| | | | | | | | | | | | | | | Implements #1309: subsequent br_ifs that compare the same value to various constants are converted into a br_table in a block, (br_if $x (i32.eq (get_local $a) (i32.const 0))) (br_if $y (i32.eq (get_local $a) (i32.const 1))) (br_if $z (i32.eq (get_local $a) (i32.const 2))) ==> (block $tablify (br_table $x $y $z $tablify (get_local $a) ) ) The constants for when to apply this (e.g., not if the range of values would make a huge jump table) are fairly conservative, I think, but hard to tell. Probably should be tweaked based on our experience with the pass in practice later on.
* notation change: AST => IR (#1245)Alon Zakai2017-10-241-3/+3
| | | 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).
* Use the type system to check if something is flowed out of (#1224)Alon Zakai2017-10-161-3/+3
| | | | now that the type system has a proper unreachable, we don't need obviouslyDoesNotFlowOut
* 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-2/+2
| | | | 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-1/+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.
* fix remove-unused-brs bug with merging br_ifs with unreachable codeAlon Zakai2017-08-281-2/+4
|
* fix flow of values stopping in remove-unused-brs: we must remove all flows ↵Alon Zakai2017-08-251-5/+21
| | | | with a value from the current state, not just set the global state as to whether we can flow or not (as it will be set later by other things)
* avoid trying to optimize ifs with unreachable conditions in ↵Alon Zakai2017-08-251-2/+5
| | | | remove-unused-brs, as they are dead code anyhow, and it is pointless to work hard to handle the type changes
* quickly avoid all unreachable branching in ifsAlon Zakai2017-08-251-0/+5
|
* don't turn unreachable ifs into br_ifs, they are dead anyhow, and would need ↵Alon Zakai2017-08-251-0/+2
| | | | special handling to emit valid code
* don't turn untaken br_ifs into ifs in remove-unused-brsAlon Zakai2017-08-051-1/+3
|
* add missing finalizations in removeUnusedBrs, when we change an if side and ↵Alon Zakai2017-07-171-0/+6
| | | | its outer block, we need to finalize the if first and then the block containing it
* fix blockifyMerge logic - it needs to not skip code in the block we merge ↵Alon Zakai2017-07-171-2/+30
| | | | to. since that's a fairly specific functionality needed in removeUnusedBrs, move it to there
* fix block removal in remove-unused-brs, even if not taken, if named, we must ↵Alon Zakai (kripken)2017-07-111-2/+2
| | | | preserve it
* add the option to seek named breaks, not just taken breaks; refactor headers ↵Alon Zakai (kripken)2017-07-111-2/+4
| | | | to make this practical
* afl-fuzz bug fixes (#1018)Alon Zakai2017-05-201-0/+3
| | | | | | | | * values cannot flow through an if without an else, they never return a value * check pass tests in pass-debug mode too * add missing finalization in binary reading
* Validate finalization (#1014)Alon Zakai2017-05-181-15/+8
| | | | | | | * 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.
* allow values to flow out of loops in RemoveUnneededBrs, and simplify some ↵Alon Zakai (kripken)2017-05-101-12/+4
| | | | unnecessary complexity in that pass as well
* Default Walker subclasses to using Visitor<SubType> (#921)jgravelle-google2017-02-231-6/+6
| | | | 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-12/+15
| | | | | | | | * 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
* merge adjacent br_ifsAlon Zakai2016-10-271-24/+46
|
* recreate simply ifsAlon Zakai2016-10-271-0/+25
|
* Pass options (#788)Alon Zakai2016-10-181-0/+6
| | | | * add PassOptions structure, and use it for new -Os param to wasm-opt
* Type check block/loop/if sigs (#717)Alon Zakai2016-09-281-1/+1
| | | | | | * type check using block/loop/if types provided in text and binary formats. * print if and loop sigs which were missing. * remove dsl from OptimizeInstructions as after those changes it needs rethinking.
* br_if returns its valueAlon Zakai2016-09-161-4/+3
|
* fix remove-unused-brs bug when checking if it is safe to conditionalize codeAlon Zakai2016-09-151-3/+3
|
* update br type when turning it into a br_if in remove-unused-brsAlon Zakai2016-09-131-0/+3
|
* fix bug with turning if into br_if without checking for reordering dangersAlon Zakai2016-09-121-10/+16
|
* simple jump threadingAlon Zakai2016-09-121-3/+74
|
* fix up types in remove-unused-brs at the first opportunity, not laterAlon Zakai2016-09-121-16/+20
|
* optimize if-else to br_if when in a blockAlon Zakai2016-09-101-6/+36
|