Skip to content

SSA CFG: stack to memory spilling#16767

Merged
clonker merged 9 commits into
developfrom
ssa-cfg-kiss-memspill
Jun 9, 2026
Merged

SSA CFG: stack to memory spilling#16767
clonker merged 9 commits into
developfrom
ssa-cfg-kiss-memspill

Conversation

@clonker

@clonker clonker commented May 22, 2026

Copy link
Copy Markdown
Member

Implements stack to memory spilling for the SSA CFG pipeline in a simple stupid version.

Adds:

  • ssa/spill/MemoryAddressing is a per-subobject owner of spill memory
    • sums numSpilled() across each CFGs SpillSet and bumps memory guard accordingly, allocates non-overlapping memory addresses for spilled values
  • ssa/spill/Emitter emits bytecode against the symbolic stack for spilled values
  • ssa/spill/SpillSet got a new method closeUnderReachabilityConstraints which will check for all spilled values whether they can be feasibly spilled at the point of origin, may add more things to spill accordingly

Modifies

  • ssa/StackLayoutGenerators generate() to return {layout, spillSet} instead of just the layout and also validates back-edges asserting that back-edge targets can be safely shuffled to
  • ssa/CodeTransform is reworked to first generate per-CFG layouts and spill sets (and close them under reachability constraints), then build a single global MemoryAddressing to hand into the CodeTransform instance

Test

  • Adds SpillTest suite under test/libyul/ssa/spill which runs the generate -> closeUnderReachabilityConstraints -> address sequence and emits that plus a text representation of the input object. does not generate any code.

@clonker clonker marked this pull request as ready for review May 22, 2026 09:27
@clonker clonker requested a review from blishko May 22, 2026 10:00
Comment thread test/libyul/ssa/SpillTest.h
Comment thread test/libyul/ssa/spill/phi_spilled_at_definition.yul
Comment thread libyul/backends/evm/ssa/spill/SpillSet.cpp Outdated
Comment thread libyul/backends/evm/ssa/spill/MemoryAddressing.cpp
Comment thread libyul/backends/evm/ssa/spill/Emitter.h
Comment thread libyul/backends/evm/ssa/spill/Emitter.h
@clonker clonker force-pushed the ssa-cfg-kiss-memspill branch from b93b4ac to 821b1df Compare June 2, 2026 08:30
Comment thread libyul/backends/evm/ssa/spill/Emitter.h
@clonker clonker force-pushed the ssa-cfg-kiss-memspill branch 2 times, most recently from ceb18c3 to 633b9db Compare June 9, 2026 14:09

@blishko blishko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I have just a few small comments, but I think we can merge this today!

Comment thread libyul/backends/evm/ssa/spill/SpillSet.cpp Outdated
Comment thread libyul/backends/evm/ssa/StackShuffler.h Outdated
Comment thread test/libyul/ssa/stackShuffler/spilled_to_pop_deep_junk.stack
@clonker clonker force-pushed the ssa-cfg-kiss-memspill branch from 633b9db to 6300a56 Compare June 9, 2026 14:35

@blishko blishko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@blishko

blishko commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

@clonker can you update the PR description to use the new method name instead of feasilize?

clonker added 9 commits June 9, 2026 18:32
Dual to `dupDeepSlotIfRequired`: A deep, still-incorrect target slot whose wanted value is not on the stack at all. A push/dup grows the stack, pushing that slot one deeper.  So if the deepest incorrect args slot would be pushed out of reach by growing, shrink first to keep it reachable.
@clonker clonker force-pushed the ssa-cfg-kiss-memspill branch from 6300a56 to c48728e Compare June 9, 2026 16:32
@clonker clonker merged commit 1c4e9a5 into develop Jun 9, 2026
82 of 83 checks passed
@clonker clonker deleted the ssa-cfg-kiss-memspill branch June 9, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants