summaryrefslogtreecommitdiff
path: root/src/passes/ReorderLocals.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Refactor interaction between Pass and PassRunner (#5093)Thomas Lively2022-09-301-1/+3
| | | | | | | | | | | | | | Previously only WalkerPasses had access to the `getPassRunner` and `getPassOptions` methods. Move those methods to `Pass` so all passes can use them. As a result, the `PassRunner` passed to `Pass::run` and `Pass::runOnFunction` is no longer necessary, so remove it. Also update `Pass::create` to return a unique_ptr, which is more efficient than having it return a raw pointer only to have the `PassRunner` wrap that raw pointer in a `unique_ptr`. Delete the unused template `PassRunner::getLast()`, which looks like it was intended to enable retrieving previous analyses and has been in the code base since 2015 but is not implemented anywhere.
* [Wasm GC] Support non-nullable locals in the "1a" form (#4959)Alon Zakai2022-08-311-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | An overview of this is in the README in the diff here (conveniently, it is near the top of the diff). Basically, we fix up nn locals after each pass, by default. This keeps things easy to reason about - what validates is what is valid wasm - but there are some minor nuances as mentioned there, in particular, we ignore nameless blocks (which are commonly added by various passes; ignoring them means we can keep more locals non-nullable). The key addition here is LocalStructuralDominance which checks which local indexes have the "structural dominance" property of 1a, that is, that each get has a set in its block or an outer block that precedes it. I optimized that function quite a lot to reduce the overhead of running that logic after each pass. The overhead is something like 2% on J2Wasm and 0% on Dart (0%, because in this mode we shrink code size, so there is less work actually, and it balances out). Since we run fixups after each pass, this PR removes logic to manually call the fixup code from various places we used to call it (like eh-utils and various passes). Various passes are now marked as requiresNonNullableLocalFixups => false. That lets us skip running the fixups after them, which we normally do automatically. This helps avoid overhead. Most passes still need the fixups, though - any pass that adds a local, or a named block, or moves code around, likely does. This removes a hack in SimplifyLocals that is no longer needed. Before we worked to avoid moving a set into a try, as it might not validate. Now, we just do it and let fixups happen automatically if they need to: in the common code they probably don't, so the extra complexity seems not worth it. Also removes a hack from StackIR. That hack tried to avoid roundtrip adding a nondefaultable local. But we have the logic to fix that up now, and opts will likely keep it non-nullable as well. Various tests end up updated here because now a local can be non-nullable - previous fixups are no longer needed. Note that this doesn't remove the gc-nn-locals feature. That has been useful for testing, and may still be useful in the future - it basically just allows nn locals in all positions (that can't read the null default value at the entry). We can consider removing it separately. Fixes #4824
* Avoid a code pattern of vec.resize() followed by std::fill() as suboptimal. ↵juj2022-04-051-3/+3
| | | | Instead do a clear()+resize() (#4580)
* Preserve Function HeapTypes (#3952)Thomas Lively2021-06-301-1/+1
| | | | | | | | | When using nominal types, func.ref of two functions with identical signatures but different HeapTypes will yield different types. To preserve these semantics, Functions need to track their HeapTypes, not just their Signatures. This PR replaces the Signature field in Function with a HeapType field and adds new utility methods to make it almost as simple to update and query the function HeapType as it was to update and query the Function Signature.
* Avoid wasted work when there are no locals (#3060)Max Graey2020-08-241-4/+5
| | | Adds early returns to local optimizations passes in cases where there are no locals to optimize.
* Fix ReorderLocals handling of local names (#2728)Alon Zakai2020-04-081-2/+3
| | | | | I think the history here is that localNames used to be a vector, then we made it a map, but didn't update this pass... so in rare cases it could end up emitting wrong stuff.
* Work around a compiler issue on MacOS (#2730)Alon Zakai2020-04-081-7/+8
| | | | | | | | | | | | | | | | | | The post-commit Mac bot on github failed to compile #2727 with Undefined symbols for architecture x86_64: "wasm::ReorderLocals::UNSEEN", referenced from: wasm::ReorderLocals::doWalkFunction(wasm::Function*) in ReorderLocals.cpp.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) That seems odd, it's defined like this? static const Index UNSEEN = -1; Perhaps we are hitting a weird compiler bug. Anyhow, just use an enum to be safe. Also for clarity switch to 0 for the unseen value.
* Optimize ReorderLocals maps to vectors (#2727)Alon Zakai2020-04-071-8/+21
| | | | | | | | The original code here is quite old and I guess we assumed that it was ok to use maps for this, but on really huge amounts of locals it ends up mattering a lot. This makes the pass 3x faster on poppler after --flatten --flatten (double flatten creates lots of new locals, and is generally similar to what wasm2js does).
* Remove FunctionType (#2510)Thomas Lively2019-12-111-11/+8
| | | | | | | | | | | | | | | | | Function signatures were previously redundantly stored on Function objects as well as on FunctionType objects. These two signature representations had to always be kept in sync, which was error-prone and needlessly complex. This PR takes advantage of the new ability of Type to represent multiple value types by consolidating function signatures as a pair of Types (params and results) stored on the Function object. Since there are no longer module-global named function types, significant changes had to be made to the printing and emitting of function types, as well as their parsing and manipulation in various passes. The C and JS APIs and their tests also had to be updated to remove named function types.
* Reflect instruction renaming in code (#2128)Heejin Ahn2019-05-211-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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-3/+6
| | | 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-23/+27
| | | 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
* misc minor cleanups in the codebase (#1531)Alon Zakai2018-05-041-0/+2
|
* Make localNames into a map (#1189)Thomas Lively2017-09-231-1/+0
|
* Default Walker subclasses to using Visitor<SubType> (#921)jgravelle-google2017-02-231-2/+2
| | | | Most module walkers use PostWalker<T, Visitor<T>>, let that pattern be expressed as simply PostWalker<T>
* Remove unused captures to fix warnings/errors when compiling with Clang (#896)Eric Holk2017-02-031-1/+1
|
* 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-1/+3
| | | | efficient parallel execution (#564)
* canonicalize the order in reorder-locals, by using first-appearance to break ↵Alon Zakai2016-05-281-5/+14
| | | | ties
* handle missing local names in ReorderLocalsAlon Zakai2016-05-051-2/+5
|
* create a UnifiedExpressionVisitor for passes that want a single visitor ↵Alon Zakai2016-04-181-2/+2
| | | | function, to avoid confusion with having both visit* and visitExpression in a single pass (#357)
* index locals, so that get_local and set_local have just an index, and local ↵Alon Zakai2016-04-181-11/+76
| | | | names are kept on the Function object (#354)
* Function parallelism (#343)Alon Zakai2016-04-151-0/+1
| | | | * allow traversals to mark themselves as function-parallel, in which case we run them using a thread pool. also mark some thread-safety risks (interned strings, arena allocators) with assertions they modify only on the main thread
* rename function locals, to params and vars, which together are all the ↵Alon Zakai2016-04-141-5/+5
| | | | locals. preparation for #336 (#349)
* drop completely unused locals in ReorderLocalsAlon Zakai2016-04-111-1/+6
|
* De-recurse traversals (#333)Alon Zakai2016-04-111-1/+1
| | | | | | | | | | | | * refactor core walking to not recurse * add a simplify-locals test * reuse parent's non-branchey scan logic in SimpleExecutionWalker, reduce code duplication * update wasm.js * rename things following comments
* ensure a stable sort in ReorderLocalsAlon Zakai2016-02-191-1/+4
|
* Remove empty function.Michael2016-02-191-4/+0
|
* Reorder locals.Michael2016-02-191-0/+55