[clang] [llvm] [SPARC] Support reserving arbitrary general purpose registers (PR #74927)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 8 13:52:32 PST 2024
================
@@ -1125,6 +1130,10 @@ Register SparcTargetLowering::getRegisterByName(const char* RegName, LLT VT,
.Case("g4", SP::G4).Case("g5", SP::G5).Case("g6", SP::G6).Case("g7", SP::G7)
.Default(0);
+ const SparcRegisterInfo *TRI = Subtarget->getRegisterInfo();
+ if (!TRI->isReservedReg(MF, Reg))
+ Reg = 0;
----------------
s-barannikov wrote:
> Becomes a nop function on clang unless `l0` is reserved.
> Other LLVM backends also do this (and differ from GCC behavior) so I don't think the issue is localized to ours.
>
> So I believe it is better for us to throw an error instead of silently miscompiling code?
Reserving a register assigned to a global variable makes sense. Not sure about local variables.
llvm language reference manual says this about llvm.read_register / llvm.write_register intrinsics:
> The compiler doesn’t check for register availability or use of the used register in surrounding code, including inline assembly. Because of that, allocatable registers are not supported.
>
> Warning: So far it only works with the stack pointer on selected architectures (ARM, AArch64, PowerPC and x86_64). Significant amount of work is needed to support other registers and even more so, allocatable registers.
That said, I think we can go with the current implementation as long as it satisfies the need of the targeted software (Linux kernel I presume).
https://github.com/llvm/llvm-project/pull/74927
More information about the llvm-commits
mailing list