-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[llvm] X86_64 CC for UEFI #137905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[llvm] X86_64 CC for UEFI #137905
+19
−5
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Select appropriate registers for X86_64 UEFI.
@llvm/pr-subscribers-backend-x86 Author: Prabhu Rajasekaran (Prabhuk) ChangesSelect appropriate registers for X86_64 UEFI. Full diff: https://github.com/llvm/llvm-project/pull/137905.diff 4 Files Affected:
diff --git a/llvm/lib/Target/X86/X86CallingConv.td b/llvm/lib/Target/X86/X86CallingConv.td
index 0d087e057a2bd..8103e8c6df51b 100644
--- a/llvm/lib/Target/X86/X86CallingConv.td
+++ b/llvm/lib/Target/X86/X86CallingConv.td
@@ -284,7 +284,8 @@ def RetCC_X86Common : CallingConv<[
// Long double types are always returned in FP0 (even with SSE),
// except on Win64.
- CCIfNotSubtarget<"isTargetWin64()", CCIfType<[f80], CCAssignToReg<[FP0, FP1]>>>
+ CCIfNotSubtarget<"isTargetWinOrUEFI64()",
+ CCIfType<[f80], CCAssignToReg<[FP0, FP1]>>>
]>;
// X86-32 C return-value convention.
@@ -495,6 +496,9 @@ def RetCC_X86_64 : CallingConv<[
// Mingw64 and native Win64 use Win64 CC
CCIfSubtarget<"isTargetWin64()", CCDelegateTo<RetCC_X86_Win64_C>>,
+ // UEFI64 uses Win64 CC
+ CCIfSubtarget<"isTargetUEFI64()", CCDelegateTo<RetCC_X86_Win64_C>>,
+
// Otherwise, drop to normal X86-64 CC
CCDelegateTo<RetCC_X86_64_C>
]>;
@@ -1085,6 +1089,9 @@ def CC_X86_64 : CallingConv<[
// Mingw64 and native Win64 use Win64 CC
CCIfSubtarget<"isTargetWin64()", CCDelegateTo<CC_X86_Win64_C>>,
+ // UEFI uses Win64 CC
+ CCIfSubtarget<"isTargetUEFI64()", CCDelegateTo<CC_X86_Win64_C>>,
+
// Otherwise, drop to normal X86-64 CC
CCDelegateTo<CC_X86_64_C>
]>;
diff --git a/llvm/lib/Target/X86/X86RegisterInfo.cpp b/llvm/lib/Target/X86/X86RegisterInfo.cpp
index 29242c7059d5f..ef58c7619b243 100644
--- a/llvm/lib/Target/X86/X86RegisterInfo.cpp
+++ b/llvm/lib/Target/X86/X86RegisterInfo.cpp
@@ -60,6 +60,7 @@ X86RegisterInfo::X86RegisterInfo(const Triple &TT)
// Cache some information.
Is64Bit = TT.isArch64Bit();
IsWin64 = Is64Bit && TT.isOSWindows();
+ IsUEFI64 = Is64Bit && TT.isUEFI();
// Use a callee-saved register as the base pointer. These registers must
// not conflict with any ABI requirements. For example, in 32-bit mode PIC
@@ -227,7 +228,7 @@ X86RegisterInfo::getPointerRegClass(const MachineFunction &MF,
const TargetRegisterClass *
X86RegisterInfo::getGPRsForTailCall(const MachineFunction &MF) const {
const Function &F = MF.getFunction();
- if (IsWin64 || (F.getCallingConv() == CallingConv::Win64))
+ if (IsWin64 || IsUEFI64 || (F.getCallingConv() == CallingConv::Win64))
return &X86::GR64_TCW64RegClass;
else if (Is64Bit)
return &X86::GR64_TCRegClass;
@@ -389,7 +390,7 @@ X86RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
return IsWin64 ? CSR_Win64_SwiftError_SaveList
: CSR_64_SwiftError_SaveList;
- if (IsWin64)
+ if (IsWin64 || IsUEFI64)
return HasSSE ? CSR_Win64_SaveList : CSR_Win64_NoSSE_SaveList;
if (CallsEHReturn)
return CSR_64EHRet_SaveList;
@@ -514,7 +515,7 @@ X86RegisterInfo::getCallPreservedMask(const MachineFunction &MF,
if (IsSwiftCC)
return IsWin64 ? CSR_Win64_SwiftError_RegMask : CSR_64_SwiftError_RegMask;
- return IsWin64 ? CSR_Win64_RegMask : CSR_64_RegMask;
+ return (IsWin64 || IsUEFI64) ? CSR_Win64_RegMask : CSR_64_RegMask;
}
return CSR_32_RegMask;
diff --git a/llvm/lib/Target/X86/X86RegisterInfo.h b/llvm/lib/Target/X86/X86RegisterInfo.h
index b3c03e8f2bc22..13a5fbf16e981 100644
--- a/llvm/lib/Target/X86/X86RegisterInfo.h
+++ b/llvm/lib/Target/X86/X86RegisterInfo.h
@@ -31,6 +31,10 @@ class X86RegisterInfo final : public X86GenRegisterInfo {
///
bool IsWin64;
+ /// IsUEFI64 - Is UEFI 64 bit target.
+ ///
+ bool IsUEFI64;
+
/// SlotSize - Stack slot size in bytes.
///
unsigned SlotSize;
diff --git a/llvm/lib/Target/X86/X86Subtarget.h b/llvm/lib/Target/X86/X86Subtarget.h
index e0dd3565605b9..a793595532fb7 100644
--- a/llvm/lib/Target/X86/X86Subtarget.h
+++ b/llvm/lib/Target/X86/X86Subtarget.h
@@ -337,6 +337,10 @@ class X86Subtarget final : public X86GenSubtargetInfo {
bool isTargetWin64() const { return Is64Bit && isOSWindows(); }
+ bool isTargetWinOrUEFI64() const {
+ return isTargetWin64() || isTargetUEFI64();
+ }
+
bool isTargetWin32() const { return !Is64Bit && isOSWindows(); }
bool isPICStyleGOT() const { return PICStyle == PICStyles::Style::GOT; }
@@ -352,6 +356,7 @@ class X86Subtarget final : public X86GenSubtargetInfo {
switch (CC) {
// On Win64, all these conventions just use the default convention.
case CallingConv::C:
+ return isTargetWin64() || isTargetUEFI64();
case CallingConv::Fast:
case CallingConv::Tail:
case CallingConv::Swift:
|
petrhosek
reviewed
Apr 30, 2025
petrhosek
approved these changes
May 2, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Select appropriate registers for X86_64 UEFI.