Repository navigation
[EVM] Support spills in recursive functions - #150
Conversation
9c59e77 to
68a5871
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
There are confirmed correctness/maintainability issues in the solver’s entry-stack modeling and error reporting that can mis-model callee-saved spill slots and emit misleading fatal errors for non-recursive functions.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (3)
What changed in this PR
Adds support for register spills in recursive EVM functions by introducing callee-save handling for spill slots (so fixed spill addresses can be safely reused across activations), plus call-graph SCC tagging to distinguish re-entrant vs non-re-entrant calls, and a comprehensive suite of MIR tests covering the new behaviors.
Changes:
- Mark recursive functions with a per-recursive-SCC id (
evm-recursive-scc) and use it to detect potentially re-entrant calls. - Introduce
CalleeSavedSlottracking in the stack model and emit prologue/epilogue save/restore code for spills that cross re-entrant calls. - Add multiple MIR tests validating callee-save vs call-free spill behavior, return-path handling, and SCC-related re-entrancy distinctions.
| File | Description |
|---|---|
| llvm/lib/Target/EVM/EVMMarkRecursiveFunctions.cpp | Adds evm-recursive-scc attribute assignment per recursive SCC. |
| llvm/lib/Target/EVM/EVMStackModel.h | Introduces SK_CalleeSaved and CalleeSavedSlot plumbing + APIs for callee-save spill reasoning. |
| llvm/lib/Target/EVM/EVMStackModel.cpp | Implements re-entrant call detection, callee-save spill creation, and return-stack integration. |
| llvm/lib/Target/EVM/EVMStackSolver.h | Updates solver documentation around recursive spill strategy. |
| llvm/lib/Target/EVM/EVMStackSolver.cpp | Enables spilling in recursive functions (after forced compression) and biases toward call-free spill candidates; models callee-saved slots at entry. |
| llvm/lib/Target/EVM/EVMStackifyCodeEmitter.h | Adds emitter APIs for callee-save spill/load/restore and entry-block spill handling. |
| llvm/lib/Target/EVM/EVMStackifyCodeEmitter.cpp | Implements callee-save prologue/restore emission and integrates it into stackification. |
| llvm/test/CodeGen/EVM/evm-recursive.ll | Updates checks to validate evm-recursive-scc emission. |
| llvm/test/CodeGen/EVM/bps-recursive-func-spills.mir | Adjusts regression test to expect spills (without callee-save) for recursive unreachable/no-RET case. |
| llvm/test/CodeGen/EVM/recursive-spills-args.mir | New test for fused callee-save+spill of recursive function arguments. |
| llvm/test/CodeGen/EVM/recursive-spills-call-boundary.mir | New test distinguishing callee-saved vs non-callee-saved spill slots around the recursive call. |
| llvm/test/CodeGen/EVM/recursive-spills-call-free.mir | New test ensuring no callee-save code when all spilled live ranges are call-free. |
| llvm/test/CodeGen/EVM/recursive-spills-callee-save.mir | New stress test ensuring multiple callee-saved spill slots are saved/restored correctly. |
| llvm/test/CodeGen/EVM/recursive-spills-ret.mir | New test covering spilled register used by RET without requiring callee-save. |
| llvm/test/CodeGen/EVM/recursive-spills-scc-mutual.mir | New test for mutual recursion SCC requiring callee-save across re-entrant call. |
| llvm/test/CodeGen/EVM/recursive-spills-scc-unrelated.mir | New test ensuring calls into a different SCC don’t force callee-save. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
1277832 to
28fbaad
Compare
e6a2037 to
c5beb79
Compare
vladimirradosavljevic
left a comment
There was a problem hiding this comment.
Just a few comments, still need to do full review. Thanks for fixing this!
vladimirradosavljevic
left a comment
There was a problem hiding this comment.
Again, thanks for adding this support, it looks awesome! I have left some nits to address, and I will approve it after that.
c5beb79 to
86a7566
Compare
vladimirradosavljevic
left a comment
There was a problem hiding this comment.
Much better now, thanks! I have some nits/questions to address, and it seems that there is an issue with the implementation, as some unit tests are failing.
b46589f to
389c0dc
Compare
vladimirradosavljevic
left a comment
There was a problem hiding this comment.
LGTM, amazing work!
da4d1e4 to
f8b6e39
Compare
…drops it The spill stores of an instruction's definitions walk down from the stack top. A spilled definition that the next layout does not hold is stored without a copy and leaves the stack, which exposes the definition below. The walk stops at the first definition that stays, and every spilled definition below it is copied before its store, as before.
f8b6e39 to
48f7b89
Compare


NomicFoundation/solx#715