Prefer caller-save registers and emit callee-save clobber comments#437
Open
dop-amin wants to merge 1 commit into
Open
Prefer caller-save registers and emit callee-save clobber comments#437dop-amin wants to merge 1 commit into
dop-amin wants to merge 1 commit into
Conversation
* Add `callee_saved_registers()` to Arm v8.1-M/Helium and RISC-V ISA models * Add `config.constraints.prefer_caller_save_registers`: biases allocation toward input registers and away from callee-saved ones via CP-SAT hints and a secondary minimisation objective (never sacrifices stall counts) * Add `config.emit_clobbered_callee_saves_comment` (default True): prepends a comment listing clobbered callee-saved registers to the output * Accumulate clobber set across preamble, kernel, and postamble in `Heuristics.periodic`; store on `Result` * Add four AArch64 naive tests covering the new features including a forced callee-save allocation case and a SW-pipelining path
mkannwischer
requested changes
Jun 24, 2026
mkannwischer
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @dop-amin. Looks like a useful feature! It's not very clear how it interacts with other secondary objectives to me. Have you considered that?
Comment on lines
+1261
to
+1262
| Requires the ISA model to define callee_saved_registers(). When the | ||
| ISA model does not provide this method the option has no effect. |
Collaborator
There was a problem hiding this comment.
Can we make it error instead? Sounds easy to misuse otherwise.
| used = set() | ||
| for t in self._get_nodes(): | ||
| used.update(t.inst.args_out) | ||
| used.update(t.inst.args_in) |
Collaborator
There was a problem hiding this comment.
Why are args_in considered clobbered?
Comment on lines
+4043
to
+4051
| # Secondary objective: prefer caller-save registers. | ||
| # This runs only in the force_objective (step-2 re-optimization) path, | ||
| # where stalls are already fixed via a hard constraint. | ||
| if force_objective and self._model._callee_saved_used and len(maxlist) == 0: | ||
| callee_vars = list(self._model._callee_saved_used.values()) | ||
| if len(minlist) == 0: | ||
| minlist = callee_vars | ||
| name = "minimize callee-saved register usage" | ||
|
|
Collaborator
There was a problem hiding this comment.
What happens here if you combine it with another secondary objective, e.g., maximize_register_lifetimes?
| if not (self.config.emit_clobbered_callee_saves_comment and clobbered): | ||
| return code | ||
| comment_text = "Clobbered callee-saved registers: " + ", ".join( | ||
| sorted(clobbered) |
Collaborator
There was a problem hiding this comment.
sorting lexicographically is probably not what you want to do here. Can we instead use a more natural order?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
callee_saved_registers()to Arm v8.1-M/Helium and RISC-V ISA modelsconfig.constraints.prefer_caller_save_registers: biases allocation toward input registers and away from callee-saved ones via CP-SAT hints and a secondary minimisation objective (never sacrifices stall counts)config.emit_clobbered_callee_saves_comment(default True): prepends a comment listing clobbered callee-saved registers to the outputHeuristics.periodic; store onResult