diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h index ed6f48fba788b..7d67966d17256 100644 --- a/llvm/include/llvm/TargetParser/Triple.h +++ b/llvm/include/llvm/TargetParser/Triple.h @@ -656,6 +656,9 @@ class Triple { return getOS() == Triple::Win32; } + /// Tests whether the OS is Windows or UEFI. + bool isOSWindowsOrUEFI() const { return isOSWindows() || isUEFI(); } + /// Checks if the environment is MSVC. bool isKnownWindowsMSVCEnvironment() const { return isOSWindows() && getEnvironment() == Triple::MSVC; diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp index 95a5e5989ad00..0cf0bfc9702d3 100644 --- a/llvm/lib/IR/DataLayout.cpp +++ b/llvm/lib/IR/DataLayout.cpp @@ -178,7 +178,7 @@ const char *DataLayout::getManglingComponent(const Triple &T) { return "-m:l"; if (T.isOSBinFormatMachO()) return "-m:o"; - if ((T.isOSWindows() || T.isUEFI()) && T.isOSBinFormatCOFF()) + if (T.isOSWindowsOrUEFI() && T.isOSBinFormatCOFF()) return T.getArch() == Triple::x86 ? "-m:x" : "-m:w"; if (T.isOSBinFormatXCOFF()) return "-m:a"; diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index 46222fcaa5b15..335febde3687c 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -85,7 +85,7 @@ MCContext::MCContext(const Triple &TheTriple, const MCAsmInfo *mai, Env = IsMachO; break; case Triple::COFF: - if (!TheTriple.isOSWindows() && !TheTriple.isUEFI()) + if (!TheTriple.isOSWindowsOrUEFI()) report_fatal_error( "Cannot initialize MC for non-Windows COFF object files."); diff --git a/llvm/lib/MC/TargetRegistry.cpp b/llvm/lib/MC/TargetRegistry.cpp index e1879f97aa567..a9e33c8349bdc 100644 --- a/llvm/lib/MC/TargetRegistry.cpp +++ b/llvm/lib/MC/TargetRegistry.cpp @@ -31,8 +31,7 @@ MCStreamer *Target::createMCObjectStreamer( case Triple::UnknownObjectFormat: llvm_unreachable("Unknown object format"); case Triple::COFF: - assert((T.isOSWindows() || T.isUEFI()) && - "only Windows and UEFI COFF are supported"); + assert(T.isOSWindowsOrUEFI() && "only Windows and UEFI COFF are supported"); S = COFFStreamerCtorFn(Ctx, std::move(TAB), std::move(OW), std::move(Emitter)); break; diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp index 39b0f7c4c4c1e..fff518e7daf07 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp @@ -147,7 +147,7 @@ X86MCAsmInfoMicrosoftMASM::X86MCAsmInfoMicrosoftMASM(const Triple &Triple) void X86MCAsmInfoGNUCOFF::anchor() { } X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) { - assert((Triple.isOSWindows() || Triple.isUEFI()) && + assert(Triple.isOSWindowsOrUEFI() && "Windows and UEFI are the only supported COFF targets"); if (Triple.getArch() == Triple::x86_64) { PrivateGlobalPrefix = ".L"; diff --git a/llvm/lib/Target/X86/X86MCInstLower.cpp b/llvm/lib/Target/X86/X86MCInstLower.cpp index 7bae16c066716..645a9baeba65c 100644 --- a/llvm/lib/Target/X86/X86MCInstLower.cpp +++ b/llvm/lib/Target/X86/X86MCInstLower.cpp @@ -1710,7 +1710,7 @@ static void printZeroExtend(const MachineInstr *MI, MCStreamer &OutStreamer, void X86AsmPrinter::EmitSEHInstruction(const MachineInstr *MI) { assert(MF->hasWinCFI() && "SEH_ instruction in function without WinCFI?"); - assert((getSubtarget().isOSWindows() || TM.getTargetTriple().isUEFI()) && + assert(getSubtarget().isOSWindowsOrUEFI() && "SEH_ instruction Windows and UEFI only"); // Use the .cv_fpo directives if we're emitting CodeView on 32-bit x86. diff --git a/llvm/lib/Target/X86/X86Subtarget.h b/llvm/lib/Target/X86/X86Subtarget.h index c399989f115d7..722076ca88c9c 100644 --- a/llvm/lib/Target/X86/X86Subtarget.h +++ b/llvm/lib/Target/X86/X86Subtarget.h @@ -324,8 +324,12 @@ class X86Subtarget final : public X86GenSubtargetInfo { bool isTargetCygMing() const { return TargetTriple.isOSCygMing(); } + bool isUEFI() const { return TargetTriple.isUEFI(); } + bool isOSWindows() const { return TargetTriple.isOSWindows(); } + bool isOSWindowsOrUEFI() const { return isOSWindows() || isUEFI(); } + bool isTargetWin64() const { return Is64Bit && isOSWindows(); } bool isTargetWin32() const { return !Is64Bit && isOSWindows(); }