Browse Source
* 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 <telliott@fastly.com> * Add and update some comments based on review --------- Co-authored-by: Trevor Elliott <telliott@fastly.com>pull/9073/head
Nick Fitzgerald
3 months ago
committed by
GitHub
3 changed files with 1128 additions and 409 deletions
File diff suppressed because it is too large
Loading…
Reference in new issue