Skip to content

Commit e7f0224

Browse files
authored
[nfc][llvm] Clean up isUEFI checks (llvm#124845)
The check for `isOSWindows() || isUEFI()` is used in several places across the codebase. Introducing `isOSWindowsOrUEFI()` in Triple.h to simplify these checks.
1 parent 437040f commit e7f0224

File tree

7 files changed

+12
-6
lines changed

7 files changed

+12
-6
lines changed

llvm/include/llvm/TargetParser/Triple.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,9 @@ class Triple {
656656
return getOS() == Triple::Win32;
657657
}
658658

659+
/// Tests whether the OS is Windows or UEFI.
660+
bool isOSWindowsOrUEFI() const { return isOSWindows() || isUEFI(); }
661+
659662
/// Checks if the environment is MSVC.
660663
bool isKnownWindowsMSVCEnvironment() const {
661664
return isOSWindows() && getEnvironment() == Triple::MSVC;

llvm/lib/IR/DataLayout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ const char *DataLayout::getManglingComponent(const Triple &T) {
178178
return "-m:l";
179179
if (T.isOSBinFormatMachO())
180180
return "-m:o";
181-
if ((T.isOSWindows() || T.isUEFI()) && T.isOSBinFormatCOFF())
181+
if (T.isOSWindowsOrUEFI() && T.isOSBinFormatCOFF())
182182
return T.getArch() == Triple::x86 ? "-m:x" : "-m:w";
183183
if (T.isOSBinFormatXCOFF())
184184
return "-m:a";

llvm/lib/MC/MCContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ MCContext::MCContext(const Triple &TheTriple, const MCAsmInfo *mai,
8585
Env = IsMachO;
8686
break;
8787
case Triple::COFF:
88-
if (!TheTriple.isOSWindows() && !TheTriple.isUEFI())
88+
if (!TheTriple.isOSWindowsOrUEFI())
8989
report_fatal_error(
9090
"Cannot initialize MC for non-Windows COFF object files.");
9191

llvm/lib/MC/TargetRegistry.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ MCStreamer *Target::createMCObjectStreamer(
3131
case Triple::UnknownObjectFormat:
3232
llvm_unreachable("Unknown object format");
3333
case Triple::COFF:
34-
assert((T.isOSWindows() || T.isUEFI()) &&
35-
"only Windows and UEFI COFF are supported");
34+
assert(T.isOSWindowsOrUEFI() && "only Windows and UEFI COFF are supported");
3635
S = COFFStreamerCtorFn(Ctx, std::move(TAB), std::move(OW),
3736
std::move(Emitter));
3837
break;

llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ X86MCAsmInfoMicrosoftMASM::X86MCAsmInfoMicrosoftMASM(const Triple &Triple)
147147
void X86MCAsmInfoGNUCOFF::anchor() { }
148148

149149
X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) {
150-
assert((Triple.isOSWindows() || Triple.isUEFI()) &&
150+
assert(Triple.isOSWindowsOrUEFI() &&
151151
"Windows and UEFI are the only supported COFF targets");
152152
if (Triple.getArch() == Triple::x86_64) {
153153
PrivateGlobalPrefix = ".L";

llvm/lib/Target/X86/X86MCInstLower.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,7 @@ static void printZeroExtend(const MachineInstr *MI, MCStreamer &OutStreamer,
17101710

17111711
void X86AsmPrinter::EmitSEHInstruction(const MachineInstr *MI) {
17121712
assert(MF->hasWinCFI() && "SEH_ instruction in function without WinCFI?");
1713-
assert((getSubtarget().isOSWindows() || TM.getTargetTriple().isUEFI()) &&
1713+
assert(getSubtarget().isOSWindowsOrUEFI() &&
17141714
"SEH_ instruction Windows and UEFI only");
17151715

17161716
// Use the .cv_fpo directives if we're emitting CodeView on 32-bit x86.

llvm/lib/Target/X86/X86Subtarget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,12 @@ class X86Subtarget final : public X86GenSubtargetInfo {
324324

325325
bool isTargetCygMing() const { return TargetTriple.isOSCygMing(); }
326326

327+
bool isUEFI() const { return TargetTriple.isUEFI(); }
328+
327329
bool isOSWindows() const { return TargetTriple.isOSWindows(); }
328330

331+
bool isOSWindowsOrUEFI() const { return isOSWindows() || isUEFI(); }
332+
329333
bool isTargetWin64() const { return Is64Bit && isOSWindows(); }
330334

331335
bool isTargetWin32() const { return !Is64Bit && isOSWindows(); }

0 commit comments

Comments
 (0)