RISC-V: Add optional register argument to tail pseudo
Patch adds support for an optional register argument to the RISC-V 'tail' pseudo-instruction for software-guarded tail calls.
This patch introduces support for an optional register argument to the RISC-V ‘tail’ pseudo-instruction. This addition enables compilers to emit software-guarded tail calls using a scratch register, ensuring correct execution even on CPUs that do not support the Zicfilp extension. The change includes modifications to gas test suites and opcode definitions.
- proposer
Submits a patch to add an optional register argument to the RISC-V 'tail' pseudo-instruction, enabling software-guarded tail calls.
“The lpad instruction of Zicfilp is encoded using an auipc hint encoding, so an instrumented binary still runs correctly on a CPU without Zicfilp. For that to work, compilers must be able to emit a software guarded tail call using t2 as the scratch register without Zicfilp appearing in the ISA string. Add `tail <symbol>, <rt>' for that, which expands the same way as `jump <symbol>, <rt>'.”
In Details
This patch affects the GNU Assembler (gas) for the RISC-V architecture. It adds support for a new operand to the tail pseudo-instruction, allowing a register to be specified as a scratch register. This is motivated by the Zicfilp extension's instruction encoding and the need for backward compatibility, enabling software-guarded tail calls that function correctly on older hardware.
- tail pseudo-instruction
- A directive in assembly language that indicates a tail call, a function call that replaces the current stack frame instead of pushing a new one.
- Zicfilp
- A RISC-V extension that provides instructions for profile-guided optimization, including features that can be leveraged for tail calls.
- software-guarded tail call
- A tail call implemented using software instructions to ensure correctness, especially when hardware support might be absent or for compatibility reasons.
- scratch register
- A general-purpose register used temporarily during computation, often for intermediate results or as a parameter for specific instructions.