Skip to content

Commit

Permalink
cranelift-frontend: Support moving GCs with user stack maps (byteco…
Browse files Browse the repository at this point in the history
…dealliance#8978)

* cranelift-frontend: Support moving GCs with user stack maps

This refactors the way that user stack maps work such that they are compatible
with moving GCs. We now keep every GC value in a stack slot, spill to the stack
slot on the value's definition, and reload from the stack slot on every
use. This means that we can generate a bunch of redundant loads, but we let the
mid-end's alias analysis clean that up. This has the added benefit of reducing
the length of live ranges for GC values and also means we don't need to
proactively spill every single live GC values at each safepoint, because we know
they are already spilled. This latter bit actually helps us avoid an
accidentally quadratic issue with many, long, overlapping live ranges where we
would do `O(n^2)` spills for a series of safepoints that keep creating more GC
refs.

We also implement two further optimizations:

1. We lazily allocate slots for live GC values, which means that if a GC value
is not ever live across a safepoint, then we do never allocate a stack slot for
it and never spill it to the stack slot. If we didn't do this, then frames would
be larger and we'd have a dead store to the stack slot that would otherwise
require the mid-end to grow a dead-store-elimination pass.

2. We keep a free list of available slots that will never be used again, and we
reuse slots from here when possible. This means that a chain of non-overlapping
live ranges, each of which still needs to appear in some safepoint's stack map,
will all reuse the same stack slot, keeping frames from being bloated.

Finally, this commit also introduces some logs for the liveness analysis to ease
future debugging.

Co-Authored-By: Trevor Elliott <telliott@fastly.com>

* review feedback

---------

Co-authored-by: Trevor Elliott <telliott@fastly.com>
  • Loading branch information
fitzgen and elliottt authored Jul 22, 2024
1 parent 9a3508d commit 2028224
Show file tree
Hide file tree
Showing 3 changed files with 570 additions and 166 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cranelift/frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ hashbrown = { workspace = true, optional = true }
smallvec = { workspace = true }

[dev-dependencies]
env_logger = { workspace = true }
similar = { workspace = true }
cranelift-codegen = { workspace = true, features = ['x86'] }

Expand Down
Loading

0 comments on commit 2028224

Please sign in to comment.