diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 2e63cd9b4481c..e164a196ba72d 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -4096,7 +4096,8 @@ const MCExpr *AsmPrinter::lowerBlockAddressConstant(const BlockAddress &BA) { /// GetCPISymbol - Return the symbol for the specified constant pool entry. MCSymbol *AsmPrinter::GetCPISymbol(unsigned CPID) const { - if (getSubtargetInfo().getTargetTriple().isWindowsMSVCEnvironment()) { + if (getSubtargetInfo().getTargetTriple().isWindowsMSVCEnvironment() || + getSubtargetInfo().getTargetTriple().isUEFI()) { const MachineConstantPoolEntry &CPE = MF->getConstantPool()->getConstants()[CPID]; if (!CPE.isMachineConstantPoolEntry()) { diff --git a/llvm/lib/IR/Mangler.cpp b/llvm/lib/IR/Mangler.cpp index 3b9c00cf993f3..cba8ee8c707df 100644 --- a/llvm/lib/IR/Mangler.cpp +++ b/llvm/lib/IR/Mangler.cpp @@ -223,7 +223,8 @@ void llvm::emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV, bool NeedQuotes = GV->hasName() && !canBeUnquotedInDirective(GV->getName()); if (NeedQuotes) OS << "\""; - if (TT.isWindowsGNUEnvironment() || TT.isWindowsCygwinEnvironment()) { + if (TT.isWindowsGNUEnvironment() || TT.isWindowsCygwinEnvironment() || + TT.isUEFI()) { std::string Flag; raw_string_ostream FlagOS(Flag); Mangler.getNameWithPrefix(FlagOS, GV, false); @@ -249,7 +250,7 @@ void llvm::emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV, OS << "\""; if (!GV->getValueType()->isFunctionTy()) { - if (TT.isWindowsMSVCEnvironment()) + if (TT.isWindowsMSVCEnvironment() || TT.isUEFI()) OS << ",DATA"; else OS << ",data"; diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp index 1c4d68d5448d6..f552ca329a4af 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp @@ -444,7 +444,7 @@ static MCAsmInfo *createX86MCAsmInfo(const MCRegisterInfo &MRI, // Force the use of an ELF container. MAI = new X86ELFMCAsmInfo(TheTriple); } else if (TheTriple.isWindowsMSVCEnvironment() || - TheTriple.isWindowsCoreCLREnvironment()) { + TheTriple.isWindowsCoreCLREnvironment() || TheTriple.isUEFI()) { if (Options.getAssemblyLanguage().equals_insensitive("masm")) MAI = new X86MCAsmInfoMicrosoftMASM(TheTriple); else @@ -452,8 +452,6 @@ static MCAsmInfo *createX86MCAsmInfo(const MCRegisterInfo &MRI, } else if (TheTriple.isOSCygMing() || TheTriple.isWindowsItaniumEnvironment()) { MAI = new X86MCAsmInfoGNUCOFF(TheTriple); - } else if (TheTriple.isUEFI()) { - MAI = new X86MCAsmInfoGNUCOFF(TheTriple); } else { // The default is ELF. MAI = new X86ELFMCAsmInfo(TheTriple); diff --git a/llvm/lib/Target/X86/X86CallingConv.td b/llvm/lib/Target/X86/X86CallingConv.td index 0d087e057a2bd..82f6dfd5a3b07 100644 --- a/llvm/lib/Target/X86/X86CallingConv.td +++ b/llvm/lib/Target/X86/X86CallingConv.td @@ -284,7 +284,7 @@ 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<"isTargetWindowsOrUEFI64()", CCIfType<[f80], CCAssignToReg<[FP0, FP1]>>> ]>; // X86-32 C return-value convention. @@ -495,6 +495,9 @@ def RetCC_X86_64 : CallingConv<[ // Mingw64 and native Win64 use Win64 CC CCIfSubtarget<"isTargetWin64()", CCDelegateTo>, + // UEFI64 uses Win64 CC + CCIfSubtarget<"isTargetUEFI64()", CCDelegateTo>, + // Otherwise, drop to normal X86-64 CC CCDelegateTo ]>; @@ -1084,6 +1087,8 @@ def CC_X86_64 : CallingConv<[ // Mingw64 and native Win64 use Win64 CC CCIfSubtarget<"isTargetWin64()", CCDelegateTo>, + // UEFI uses Win64 CC + CCIfSubtarget<"isTargetUEFI64()", CCDelegateTo>, // Otherwise, drop to normal X86-64 CC CCDelegateTo diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index ee2c72bc9cced..e51ad7f48645b 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -585,6 +585,7 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM, // FIXME - use subtarget debug flags if (!Subtarget.isTargetDarwin() && !Subtarget.isTargetELF() && !Subtarget.isTargetCygMing() && !Subtarget.isTargetWin64() && + !Subtarget.isTargetUEFI64() && TM.Options.ExceptionModel != ExceptionHandling::SjLj) { setOperationAction(ISD::EH_LABEL, MVT::Other, Expand); } @@ -28087,7 +28088,6 @@ Register X86TargetLowering::getRegisterByName(const char* RegName, LLT VT, .Case("r14", X86::R14) .Case("r15", X86::R15) .Default(0); - if (Reg == X86::EBP || Reg == X86::RBP) { if (!TFI.hasFP(MF)) report_fatal_error("register " + StringRef(RegName) + @@ -28131,7 +28131,7 @@ Register X86TargetLowering::getExceptionSelectorRegister( } bool X86TargetLowering::needsFixedCatchObjects() const { - return Subtarget.isTargetWin64(); + return Subtarget.isTargetWin64() || Subtarget.isTargetUEFI64(); } SDValue X86TargetLowering::LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const { @@ -61613,8 +61613,8 @@ bool X86TargetLowering::hasStackProbeSymbol(const MachineFunction &MF) const { /// Returns true if stack probing through inline assembly is requested. bool X86TargetLowering::hasInlineStackProbe(const MachineFunction &MF) const { - // No inline stack probe for Windows, they have their own mechanism. - if (Subtarget.isOSWindows() || + // No inline stack probe for Windows and UEFI, they have their own mechanism. + if (Subtarget.isOSWindowsOrUEFI() || MF.getFunction().hasFnAttribute("no-stack-arg-probe")) return false; @@ -61638,9 +61638,9 @@ X86TargetLowering::getStackProbeSymbolName(const MachineFunction &MF) const { if (MF.getFunction().hasFnAttribute("probe-stack")) return MF.getFunction().getFnAttribute("probe-stack").getValueAsString(); - // Generally, if we aren't on Windows, the platform ABI does not include - // support for stack probes, so don't emit them. - if (!Subtarget.isOSWindows() || Subtarget.isTargetMachO() || + // Generally, if we aren't on Windows or UEFI, the platform ABI does not + // include support for stack probes, so don't emit them. + if (!(Subtarget.isOSWindowsOrUEFI()) || Subtarget.isTargetMachO() || MF.getFunction().hasFnAttribute("no-stack-arg-probe")) return ""; diff --git a/llvm/lib/Target/X86/X86RegisterInfo.cpp b/llvm/lib/Target/X86/X86RegisterInfo.cpp index b59d980172458..9a2fcde7f766c 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; @@ -456,7 +457,7 @@ X86RegisterInfo::getCallPreservedMask(const MachineFunction &MF, } case CallingConv::X86_RegCall: if (Is64Bit) { - if (IsWin64) { + if (IsWin64 || IsUEFI64) { return (HasSSE ? CSR_Win64_RegCall_RegMask : CSR_Win64_RegCall_NoSSE_RegMask); } else { @@ -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 5b6ac3c5da019..0f3ec2f6a6a7e 100644 --- a/llvm/lib/Target/X86/X86RegisterInfo.h +++ b/llvm/lib/Target/X86/X86RegisterInfo.h @@ -27,10 +27,14 @@ class X86RegisterInfo final : public X86GenRegisterInfo { /// bool Is64Bit; - /// IsWin64 - Is the target on of win64 flavours + /// IsWin64 - Is the target one of win64 flavours /// bool IsWin64; + /// IsUEFI64 - Is this 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 8f2d326a69398..e68420e4a3cb3 100644 --- a/llvm/lib/Target/X86/X86Subtarget.h +++ b/llvm/lib/Target/X86/X86Subtarget.h @@ -327,11 +327,17 @@ class X86Subtarget final : public X86GenSubtargetInfo { bool isTargetCygMing() const { return TargetTriple.isOSCygMing(); } + bool isOSWindows() const { return TargetTriple.isOSWindows(); } + bool isUEFI() const { return TargetTriple.isUEFI(); } - bool isOSWindows() const { return TargetTriple.isOSWindows(); } + bool isOSWindowsOrUEFI() const { return TargetTriple.isOSWindowsOrUEFI(); } + + bool isTargetWindowsOrUEFI64() const { + return isTargetWin64() || isTargetUEFI64(); + } - bool isOSWindowsOrUEFI() const { return isOSWindows() || isUEFI(); } + bool isTargetUEFI64() const { return Is64Bit && isUEFI(); } bool isTargetWin64() const { return Is64Bit && isOSWindows(); } @@ -348,8 +354,10 @@ class X86Subtarget final : public X86GenSubtargetInfo { bool isCallingConvWin64(CallingConv::ID CC) const { switch (CC) { - // On Win64, all these conventions just use the default convention. + // On Win64 and UEFI64, all these conventions just use the default + // convention. case CallingConv::C: + return isTargetWin64() || isTargetUEFI64(); case CallingConv::Fast: case CallingConv::Tail: case CallingConv::Swift: diff --git a/llvm/test/CodeGen/X86/mangle-question-mark.ll b/llvm/test/CodeGen/X86/mangle-question-mark.ll index fea62ecad97c9..15fdae34bc4c3 100644 --- a/llvm/test/CodeGen/X86/mangle-question-mark.ll +++ b/llvm/test/CodeGen/X86/mangle-question-mark.ll @@ -2,6 +2,7 @@ ; RUN: llc -mtriple i686-pc-win32 < %s | FileCheck %s --check-prefix=COFF ; RUN: llc -mtriple x86_64-pc-win32 < %s | FileCheck %s --check-prefix=COFF64 +; RUN: llc -mtriple x86_64-unknown-uefi < %s | FileCheck %s --check-prefix=COFF64 ; RUN: llc -mtriple i686-linux-gnu < %s | FileCheck %s --check-prefix=ELF ; RUN: llc -mtriple i686-apple-darwin < %s | FileCheck %s --check-prefix=MACHO diff --git a/llvm/test/CodeGen/X86/win32-preemption.ll b/llvm/test/CodeGen/X86/win32-preemption.ll index 77dcfa7280daf..139a1e514556e 100644 --- a/llvm/test/CodeGen/X86/win32-preemption.ll +++ b/llvm/test/CodeGen/X86/win32-preemption.ll @@ -4,6 +4,8 @@ ; RUN: -relocation-model=pic < %s | FileCheck --check-prefix=COFF %s ; RUN: llc -mtriple x86_64-pc-win32 \ ; RUN: -relocation-model=dynamic-no-pic < %s | FileCheck --check-prefix=COFF %s +; RUN: llc -mtriple x86_64-unknown-uefi \ +; RUN: -relocation-model=dynamic-no-pic < %s | FileCheck --check-prefix=COFF %s ; 32 bits