diff --git a/llvm/include/llvm/IR/CallingConv.h b/llvm/include/llvm/IR/CallingConv.h --- a/llvm/include/llvm/IR/CallingConv.h +++ b/llvm/include/llvm/IR/CallingConv.h @@ -237,6 +237,9 @@ /// Preserve X2-X15, X19-X29, SP, Z0-Z31, P0-P15. AArch64_SME_ABI_Support_Routines_PreserveMost_From_X2 = 103, + /// Used by GraalVM. Two additional registers are reserved. + GRAAL = 104, + /// The highest possible ID. Must be some 2^k - 1. MaxID = 1023 }; diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -6178,6 +6178,7 @@ case CallingConv::Swift: case CallingConv::SwiftTail: case CallingConv::Tail: + case CallingConv::GRAAL: if (Subtarget->isTargetWindows() && IsVarArg) { if (Subtarget->isWindowsArm64EC()) return CC_AArch64_Arm64EC_VarArg; @@ -9635,9 +9636,10 @@ getRegisterByName(const char* RegName, LLT VT, const MachineFunction &MF) const { Register Reg = MatchRegisterName(RegName); if (AArch64::X1 <= Reg && Reg <= AArch64::X28) { - const MCRegisterInfo *MRI = Subtarget->getRegisterInfo(); + const AArch64RegisterInfo *MRI = Subtarget->getRegisterInfo(); unsigned DwarfRegNum = MRI->getDwarfRegNum(Reg, false); - if (!Subtarget->isXRegisterReserved(DwarfRegNum)) + if (!Subtarget->isXRegisterReserved(DwarfRegNum) && + !MRI->isReservedReg(MF, Reg)) Reg = 0; } if (Reg) diff --git a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp --- a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp @@ -434,6 +434,13 @@ markSuperRegs(Reserved, AArch64::FPCR); + if (MF.getFunction().getCallingConv() == CallingConv::GRAAL) { + markSuperRegs(Reserved, AArch64::X27); + markSuperRegs(Reserved, AArch64::X28); + markSuperRegs(Reserved, AArch64::W27); + markSuperRegs(Reserved, AArch64::W28); + } + assert(checkAllSuperRegsMarked(Reserved)); return Reserved; } diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -14345,6 +14345,7 @@ report_fatal_error("Unsupported calling convention"); case CallingConv::C: case CallingConv::Fast: + case CallingConv::GRAAL: break; case CallingConv::GHC: if (!Subtarget.hasStdExtF() || !Subtarget.hasStdExtD()) diff --git a/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp b/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp --- a/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp +++ b/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp @@ -114,6 +114,11 @@ markSuperRegs(Reserved, RISCV::FRM); markSuperRegs(Reserved, RISCV::FFLAGS); + if (MF.getFunction().getCallingConv() == CallingConv::GRAAL) { + markSuperRegs(Reserved, RISCV::X23); + markSuperRegs(Reserved, RISCV::X27); + } + assert(checkAllSuperRegsMarked(Reserved)); return Reserved; } diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -29477,11 +29477,13 @@ const TargetFrameLowering &TFI = *Subtarget.getFrameLowering(); Register Reg = StringSwitch(RegName) - .Case("esp", X86::ESP) - .Case("rsp", X86::RSP) - .Case("ebp", X86::EBP) - .Case("rbp", X86::RBP) - .Default(0); + .Case("esp", X86::ESP) + .Case("rsp", X86::RSP) + .Case("ebp", X86::EBP) + .Case("rbp", X86::RBP) + .Case("r14", X86::R14) + .Case("r15", X86::R15) + .Default(0); if (Reg == X86::EBP || Reg == X86::RBP) { if (!TFI.hasFP(MF)) diff --git a/llvm/lib/Target/X86/X86RegisterInfo.cpp b/llvm/lib/Target/X86/X86RegisterInfo.cpp --- a/llvm/lib/Target/X86/X86RegisterInfo.cpp +++ b/llvm/lib/Target/X86/X86RegisterInfo.cpp @@ -610,6 +610,13 @@ } } + if (MF.getFunction().getCallingConv() == CallingConv::GRAAL) { + for (MCRegAliasIterator AI(X86::R14, this, true); AI.isValid(); ++AI) + Reserved.set(*AI); + for (MCRegAliasIterator AI(X86::R15, this, true); AI.isValid(); ++AI) + Reserved.set(*AI); + } + assert(checkAllSuperRegsMarked(Reserved, {X86::SIL, X86::DIL, X86::BPL, X86::SPL, X86::SIH, X86::DIH, X86::BPH, X86::SPH}));