-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[nfc][llvm] Clean up isUEFI checks #124845
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
Conversation
The check for `isOSWindows() || isUEFI()` is used in several places across the codebase. Introducing `isOSWindowsOrUEFI()` in Triple.h to simplify these checks.
@llvm/pr-subscribers-llvm-ir @llvm/pr-subscribers-backend-x86 Author: Prabhuk (Prabhuk) ChangesThe check for Full diff: https://github.com/llvm/llvm-project/pull/124845.diff 7 Files Affected:
diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index ed6f48fba788b1..7d67966d172563 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 95a5e5989ad009..0cf0bfc9702d33 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 46222fcaa5b152..335febde3687c5 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 e1879f97aa5675..a9e33c8349bdc2 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 39b0f7c4c4c1e6..fff518e7daf078 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 7bae16c0667168..645a9baeba65c7 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 c399989f115d75..722076ca88c9c1 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(); }
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, as long as CI is happy.
The check for
isOSWindows() || isUEFI()
is used in several placesacross the codebase. Introducing
isOSWindowsOrUEFI()
in Triple.hto simplify these checks.