[RISCV] Add support for static chain
authormelonedo <funanzeng@gmail.com>
Tue, 16 Aug 2022 04:56:59 +0000 (12:56 +0800)
committermelonedo <funanzeng@gmail.com>
Wed, 9 Nov 2022 08:10:32 +0000 (16:10 +0800)
commitf4f6c63f0df7465b3f4e64e1637405e641f19dc2
treed99996621e67019a9fbfae6e36ba1bbbf27f6957
parent000588d9c4c015ae4c9abe778ab54903c299eebb
[RISCV] Add support for static chain

The static chain parameter is a special parameter that is not passed in the usual argument registers or stack space. For example, in x64 System V ABI it is always passed in R10. Although the ABI of RISCV does not assign a register for this purpose, GCC had support for it on RISC-V a long time ago, and it is exposed via `__builtin_call_with_static_chain` intrinsic, and assign t2 for static chain parameters. This patch also chose t2 for compatibility.

In LLVM, static chain parameters are handled by the `nest` attribute of an argument to a function ([D6332](https://reviews.llvm.org/D6332)), so tests are added to ensure `nest` arguments are handled correctly.

Reviewed By: kito-cheng, MaskRay

Differential Revision: https://reviews.llvm.org/D129106
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/ghccc-nest.ll [new file with mode: 0644]
llvm/test/CodeGen/RISCV/nest-register.ll [new file with mode: 0644]