[llvm] [llvm] Add Triple::isOSWindowsOrUEFI and use it, NFC (PR #206608)
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 29 15:46:54 PDT 2026
https://github.com/rnk created https://github.com/llvm/llvm-project/pull/206608
I think this predicate has earned it's place in Triple.h.
Unfortunately, there isn't a really clear line between what Windows behavior has to carry over to UEFI, so I went with the mechanical `isOSWindowsOrUEFI` name.
I have a follow-up PR for Clang.
>From 26bc45c943aa05e29eddbb185c4921ece35db03e Mon Sep 17 00:00:00 2001
From: Reid Kleckner <rkleckner at nvidia.com>
Date: Mon, 29 Jun 2026 10:19:46 -0700
Subject: [PATCH] [llvm] Add a Windows-or-UEFI triple predicate
---
llvm/include/llvm/IR/RuntimeLibcalls.td | 4 ++--
llvm/include/llvm/TargetParser/Triple.h | 6 ++++++
llvm/lib/MC/MCContext.cpp | 2 +-
llvm/lib/MC/TargetRegistry.cpp | 2 +-
llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp | 2 +-
llvm/lib/Target/X86/X86ISelLowering.cpp | 4 ++--
llvm/lib/Target/X86/X86MCInstLower.cpp | 2 +-
llvm/lib/Target/X86/X86Subtarget.h | 4 ++++
llvm/lib/TargetParser/TargetDataLayout.cpp | 2 +-
llvm/lib/TargetParser/Triple.cpp | 2 +-
llvm/unittests/TargetParser/TripleTest.cpp | 7 +++++++
11 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index fc4388a4d15ad..a7e45570c1b24 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -3370,10 +3370,10 @@ def isCygwinMinGW32 : RuntimeLibcallPredicate<
def isWin32NotCygMing : RuntimeLibcallPredicate<
[{TT.getArch() == Triple::x86 &&
- (TT.isOSWindows() || TT.isUEFI()) && !TT.isOSCygMing()}]>;
+ TT.isOSWindowsOrUEFI() && !TT.isOSCygMing()}]>;
def isWin64NotCygMing : RuntimeLibcallPredicate<
[{TT.getArch() == Triple::x86_64 &&
- (TT.isOSWindows() || TT.isUEFI()) && !TT.isOSCygMing()}]>;
+ TT.isOSWindowsOrUEFI() && !TT.isOSCygMing()}]>;
// Some darwins have an optimized __bzero/bzero function.
diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index 852a410be03c0..4cf54022c5c32 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -687,6 +687,12 @@ class Triple {
/// Tests whether the OS is Windows.
bool isOSWindows() const { return getOS() == Triple::Win32; }
+ /// Tests whether the OS is Windows or UEFI. These targets generally share
+ /// Windows low-level platform ABI conventions, but this does not imply
+ /// support for a hosted Windows environment or its runtime libraries. Use
+ /// object format or environment predicates when those properties matter.
+ 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/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 6c86de020aa41..cea521debe71a 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -87,7 +87,7 @@ MCContext::MCContext(const Triple &TheTriple, const MCAsmInfo &mai,
Env = IsMachO;
break;
case Triple::COFF:
- if (!TheTriple.isOSWindows() && !TheTriple.isUEFI()) {
+ if (!TheTriple.isOSWindowsOrUEFI()) {
reportFatalUsageError(
"cannot initialize MC for non-Windows COFF object files");
}
diff --git a/llvm/lib/MC/TargetRegistry.cpp b/llvm/lib/MC/TargetRegistry.cpp
index 948fb5034f726..4a211ffca776d 100644
--- a/llvm/lib/MC/TargetRegistry.cpp
+++ b/llvm/lib/MC/TargetRegistry.cpp
@@ -42,7 +42,7 @@ MCStreamer *Target::createMCObjectStreamer(
case Triple::UnknownObjectFormat:
llvm_unreachable("Unknown object format");
case Triple::COFF:
- assert((T.isOSWindows() || T.isUEFI()) &&
+ assert(T.isOSWindowsOrUEFI() &&
"only Windows and UEFI COFF are supported");
S = COFFStreamerCtorFn(Ctx, std::move(TAB), std::move(OW),
std::move(Emitter));
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp
index fa17a0040dab7..adb7bd2e58f96 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp
@@ -219,7 +219,7 @@ void X86MCAsmInfoGNUCOFF::anchor() { }
X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple,
const MCTargetOptions &Options)
: MCAsmInfoGNUCOFF(Options) {
- assert((Triple.isOSWindows() || Triple.isUEFI()) &&
+ assert(Triple.isOSWindowsOrUEFI() &&
"Windows and UEFI are the only supported COFF targets");
if (Triple.isX86_64()) {
InternalSymbolPrefix = ".L";
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 7a382490c5027..0fe0dd0dfd98b 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -64828,7 +64828,7 @@ bool X86TargetLowering::hasStackProbeSymbol(const MachineFunction &MF) const {
bool X86TargetLowering::hasInlineStackProbe(const MachineFunction &MF) const {
// No inline stack probe for Windows, they have their own mechanism.
- if (Subtarget.isOSWindows() || Subtarget.isUEFI() ||
+ if (Subtarget.isOSWindowsOrUEFI() ||
MF.getFunction().hasFnAttribute("no-stack-arg-probe"))
return false;
@@ -64854,7 +64854,7 @@ X86TargetLowering::getStackProbeSymbolName(const MachineFunction &MF) const {
// 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.isUEFI()) ||
+ if (!Subtarget.isOSWindowsOrUEFI() ||
Subtarget.isTargetMachO() ||
MF.getFunction().hasFnAttribute("no-stack-arg-probe"))
return "";
diff --git a/llvm/lib/Target/X86/X86MCInstLower.cpp b/llvm/lib/Target/X86/X86MCInstLower.cpp
index 2219d0a222cfc..ad0946b4c3310 100644
--- a/llvm/lib/Target/X86/X86MCInstLower.cpp
+++ b/llvm/lib/Target/X86/X86MCInstLower.cpp
@@ -1732,7 +1732,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() || getSubtarget().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 692c7938ddc00..31ca2bdc73cea 100644
--- a/llvm/lib/Target/X86/X86Subtarget.h
+++ b/llvm/lib/Target/X86/X86Subtarget.h
@@ -335,6 +335,10 @@ class X86Subtarget final : public X86GenSubtargetInfo {
bool isOSWindows() const { return TargetTriple.isOSWindows(); }
+ bool isOSWindowsOrUEFI() const {
+ return TargetTriple.isOSWindowsOrUEFI();
+ }
+
bool isTargetUEFI64() const { return Is64Bit && isUEFI(); }
bool isTargetWin64() const { return Is64Bit && isOSWindows(); }
diff --git a/llvm/lib/TargetParser/TargetDataLayout.cpp b/llvm/lib/TargetParser/TargetDataLayout.cpp
index a2125eeb82932..cab9d7792c787 100644
--- a/llvm/lib/TargetParser/TargetDataLayout.cpp
+++ b/llvm/lib/TargetParser/TargetDataLayout.cpp
@@ -18,7 +18,7 @@ static StringRef 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/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 501cf81c1b031..603227e891d4b 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -2510,7 +2510,7 @@ bool Triple::isLittleEndian() const {
unsigned Triple::getDefaultWCharSize() const {
if (getArch() == Triple::xcore)
return 1;
- if (isOSWindows() || isWindowsCygwinEnvironment() || isPS() || isUEFI())
+ if (isOSWindowsOrUEFI() || isPS())
return 2;
if (isOSAIX() && isArch32Bit())
return 2;
diff --git a/llvm/unittests/TargetParser/TripleTest.cpp b/llvm/unittests/TargetParser/TripleTest.cpp
index ff090429d74ca..0486b113e9354 100644
--- a/llvm/unittests/TargetParser/TripleTest.cpp
+++ b/llvm/unittests/TargetParser/TripleTest.cpp
@@ -3530,6 +3530,13 @@ TEST(DataLayoutTest, UEFI) {
EXPECT_THAT(TT.computeDataLayout(), testing::HasSubstr("-m:w-"));
}
+TEST(TripleTest, WindowsOrUEFI) {
+ EXPECT_TRUE(Triple("x86_64-pc-windows-msvc").isOSWindowsOrUEFI());
+ EXPECT_TRUE(Triple("x86_64-w64-windows-gnu").isOSWindowsOrUEFI());
+ EXPECT_TRUE(Triple("x86_64-unknown-uefi").isOSWindowsOrUEFI());
+ EXPECT_FALSE(Triple("x86_64-unknown-linux-gnu").isOSWindowsOrUEFI());
+}
+
TEST(TripleTest, DefaultWCharSize) {
EXPECT_EQ(4u, Triple("x86_64-unknown-linux-gnu").getDefaultWCharSize());
EXPECT_EQ(4u, Triple("aarch64-unknown-linux-gnu").getDefaultWCharSize());
More information about the llvm-commits
mailing list