| bf9273a3 | 25-Mar-2025 |
Nick Fitzgerald <[email protected]> |
`cranelift-frontend`: Propagate needs-stack-map from variables to values during finalization (#10468)
* cranelift-frontend: Propagate needs-stack-map from variables to values during finalization
Ra
`cranelift-frontend`: Propagate needs-stack-map from variables to values during finalization (#10468)
* cranelift-frontend: Propagate needs-stack-map from variables to values during finalization
Rather than trying to propagate the needs-stack-map bit from variables to values online, while we are building the IR and defining and using variables, wait until the function is being finalized, and then propagate everything all at once. This avoids potential repeated work and is easier to ensure that it is complete and covers all values associated with a variable, since by the time we are finalizing the function, we won't add any new values for a variable that we will need to keep track of and propagate this information to.
This also means that we can remove the `params_added_to_blocks` vector from the SSA side effects structure, since it was only used to online-update the `stack_map_values` set.
* Initialize the env-logger in `#[wasmtime_test]`
* Fix needs-stack-map set iteration
For reasons I do not understand, the `EntitySet::keys` method includes keys that are not in the set, and we have unit tests asserting this bizarre behavior. Very perplexing. So I added a new method to iterate over just the elements of the set.
show more ...
|
| dbc503f3 | 02-Aug-2024 |
Nick Fitzgerald <[email protected]> |
`cranelift-frontend`: Fix stack maps and liveness for loops (#9071)
* cranelift-frontend: Fix stack maps and liveness for loops
Previously, we were not properly handling back edges. This manifested
`cranelift-frontend`: Fix stack maps and liveness for loops (#9071)
* cranelift-frontend: Fix stack maps and liveness for loops
Previously, we were not properly handling back edges. This manifested in values incorrectly being considered not-live inside loop bodies where they definitely were live. Consider the following example:
block0: v0 = needs stack map
block1: call foo(v0) call foo(v0) jump block1
We were previously considering `v0` live only for the first `call foo(v0)` but not the second, because we mistakenly concluded that `v0` would not be used again after that second `call`. While it won't be used again in *this* iteration of the loop, it will be used again in the *next* iteration of the loop.
Trevor and I initially tried implementing a clever trick suggested by Chris where, if we know the minimum post-order index of all of a block's transitive predecessors, we can continue to compute liveness in a single pass over the IR. We believed we could compute the minimum predecessor post-order index via dynamic programming. It turns out, however, that approach doesn't provide correct answers out of the box for certain kinds of irreducible control flow, only nearly correct answers, and would require an additional clever fix-up pass afterwards. We deemed this cleverness on cleverness unacceptable.
Instead, Trevor and I opted to implement a worklist algorithm where we process blocks to a fixed-point. This has the advantages of being obviously correct and producing more-precise results. It has the disadvantage of requiring multiple passes over the IR in the face of loops and back edges. Because this analysis is only used when needs-stack-map values are present (i.e. when the function uses GC values) and is otherwise skipped, this additional compile-time overhead is tolerable.
Co-Authored-By: Trevor Elliott <[email protected]>
* Add and update some comments based on review
---------
Co-authored-by: Trevor Elliott <[email protected]>
show more ...
|