Calling Conventions and Live Values Across Calls
Track the caller’s and callee’s register obligations and relate those contracts to compiler allocation choices.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
A shared contract lets independent code call each other
A calling convention specifies where arguments and results are passed, which registers may change, and which must be restored before return. A caller with a live value in a caller-saved register must protect it if needed after a call. A callee using a callee-saved register must restore its incoming value. Stack alignment and layout obligations matter at the boundary even if the function itself does little work.
The better register can depend on the function’s shape
A value used across many calls might reside in a callee-saved register, paying save and restore once in the current function. A short-lived temporary may fit a caller-saved register without either cost. Tail calls need a compatible stack and result contract. Register allocation combines these constraints with live ranges. Stack frames show where local values and saved machine state reside.[1][2]