Skip to content

Commit 9653eb5

Browse files
committed
Make Triple's isOSBinFormatXXX functions partition triple-space.
Most users would be surprised if "isCOFF" and "isMachO" were simultaneously true, unless they'd put the compiler in a box with a gun attached to a photon detector. This makes sure precisely one of the three formats is true for any triple and simplifies some target logic based on that. llvm-svn: 196934
1 parent a7830a4 commit 9653eb5

File tree

8 files changed

+22
-26
lines changed

8 files changed

+22
-26
lines changed

llvm/include/llvm/ADT/Triple.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,17 +341,17 @@ class Triple {
341341

342342
/// \brief Tests whether the OS uses the ELF binary format.
343343
bool isOSBinFormatELF() const {
344-
return !isOSDarwin() && !isOSWindows();
344+
return !isOSBinFormatMachO() && !isOSBinFormatCOFF();
345345
}
346346

347347
/// \brief Tests whether the OS uses the COFF binary format.
348348
bool isOSBinFormatCOFF() const {
349-
return isOSWindows();
349+
return getEnvironment() != Triple::ELF &&
350+
getEnvironment() != Triple::MachO && isOSWindows();
350351
}
351352

352353
/// \brief Tests whether the environment is MachO.
353-
// FIXME: Should this be an OSBinFormat predicate?
354-
bool isEnvironmentMachO() const {
354+
bool isOSBinFormatMachO() const {
355355
return getEnvironment() == Triple::MachO || isOSDarwin();
356356
}
357357

llvm/lib/Target/ARM/ARMSubtarget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class ARMSubtarget : public ARMGenSubtargetInfo {
310310
bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
311311
bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); }
312312
bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
313-
bool isTargetELF() const { return !isTargetDarwin(); }
313+
bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
314314
// ARM EABI is the bare-metal EABI described in ARM ABI documents and
315315
// can be accessed via -target arm-none-eabi. This is NOT GNUEABI.
316316
// FIXME: Add a flag for bare-metal for that target and set Triple::EABI

llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static MCInstPrinter *createARMMCInstPrinter(const Target &T,
268268
static MCRelocationInfo *createARMMCRelocationInfo(StringRef TT,
269269
MCContext &Ctx) {
270270
Triple TheTriple(TT);
271-
if (TheTriple.isEnvironmentMachO())
271+
if (TheTriple.isOSBinFormatMachO())
272272
return createARMMachORelocationInfo(Ctx);
273273
// Default to the stock relocation info.
274274
return llvm::createMCRelocationInfo(TT, Ctx);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ static MCInstPrinter *createX86MCInstPrinter(const Target &T,
387387
static MCRelocationInfo *createX86MCRelocationInfo(StringRef TT,
388388
MCContext &Ctx) {
389389
Triple TheTriple(TT);
390-
if (TheTriple.isEnvironmentMachO() && TheTriple.getArch() == Triple::x86_64)
390+
if (TheTriple.isOSBinFormatMachO() && TheTriple.getArch() == Triple::x86_64)
391391
return createX86_64MachORelocationInfo(Ctx);
392392
else if (TheTriple.isOSBinFormatELF())
393393
return createX86_64ELFRelocationInfo(Ctx);

llvm/lib/Target/X86/X86AsmPrinter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ using namespace llvm;
5151
bool X86AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
5252
SetupMachineFunction(MF);
5353

54-
if (Subtarget->isTargetCOFF() && !Subtarget->isTargetEnvMacho()) {
54+
if (Subtarget->isTargetCOFF()) {
5555
bool Intrn = MF.getFunction()->hasInternalLinkage();
5656
OutStreamer.BeginCOFFSymbolDef(CurrentFnSym);
5757
OutStreamer.EmitCOFFSymbolStorageClass(Intrn ? COFF::IMAGE_SYM_CLASS_STATIC
@@ -503,7 +503,7 @@ bool X86AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
503503
}
504504

505505
void X86AsmPrinter::EmitStartOfAsmFile(Module &M) {
506-
if (Subtarget->isTargetEnvMacho())
506+
if (Subtarget->isTargetMacho())
507507
OutStreamer.SwitchSection(getObjFileLowering().getTextSection());
508508

509509
if (Subtarget->isTargetCOFF()) {
@@ -530,7 +530,7 @@ void X86AsmPrinter::EmitStartOfAsmFile(Module &M) {
530530

531531

532532
void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
533-
if (Subtarget->isTargetEnvMacho()) {
533+
if (Subtarget->isTargetMacho()) {
534534
// All darwin targets use mach-o.
535535
MachineModuleInfoMachO &MMIMacho =
536536
MMI->getObjFileInfo<MachineModuleInfoMachO>();
@@ -631,7 +631,7 @@ void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
631631
OutStreamer.EmitSymbolAttribute(S, MCSA_Global);
632632
}
633633

634-
if (Subtarget->isTargetCOFF() && !Subtarget->isTargetEnvMacho()) {
634+
if (Subtarget->isTargetCOFF()) {
635635
X86COFFMachineModuleInfo &COFFMMI =
636636
MMI->getObjFileInfo<X86COFFMachineModuleInfo>();
637637

llvm/lib/Target/X86/X86FrameLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF) const {
606606
// responsible for adjusting the stack pointer. Touching the stack at 4K
607607
// increments is necessary to ensure that the guard pages used by the OS
608608
// virtual memory manager are allocated in correct sequence.
609-
if (NumBytes >= 4096 && STI.isOSWindows() && !STI.isTargetEnvMacho()) {
609+
if (NumBytes >= 4096 && STI.isOSWindows() && !STI.isTargetMacho()) {
610610
const char *StackProbeSymbol;
611611
bool isSPUpdateNeeded = false;
612612

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static TargetLoweringObjectFile *createTLOF(X86TargetMachine &TM) {
180180
const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
181181
bool is64Bit = Subtarget->is64Bit();
182182

183-
if (Subtarget->isTargetEnvMacho()) {
183+
if (Subtarget->isTargetMacho()) {
184184
if (is64Bit)
185185
return new X86_64MachoTargetObjectFile();
186186
return new TargetLoweringObjectFileMachO();
@@ -190,7 +190,7 @@ static TargetLoweringObjectFile *createTLOF(X86TargetMachine &TM) {
190190
return new X86LinuxTargetObjectFile();
191191
if (Subtarget->isTargetELF())
192192
return new TargetLoweringObjectFileELF();
193-
if (Subtarget->isTargetCOFF() && !Subtarget->isTargetEnvMacho())
193+
if (Subtarget->isTargetCOFF())
194194
return new TargetLoweringObjectFileCOFF();
195195
llvm_unreachable("unknown subtarget type");
196196
}
@@ -632,7 +632,7 @@ void X86TargetLowering::resetOperationActions() {
632632
setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
633633
setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
634634

635-
if (Subtarget->isOSWindows() && !Subtarget->isTargetEnvMacho())
635+
if (Subtarget->isOSWindows() && !Subtarget->isTargetMacho())
636636
setOperationAction(ISD::DYNAMIC_STACKALLOC, Subtarget->is64Bit() ?
637637
MVT::i64 : MVT::i32, Custom);
638638
else if (TM.Options.EnableSegmentedStacks)
@@ -10799,7 +10799,7 @@ X86TargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op,
1079910799
getTargetMachine().Options.EnableSegmentedStacks) &&
1080010800
"This should be used only on Windows targets or when segmented stacks "
1080110801
"are being used");
10802-
assert(!Subtarget->isTargetEnvMacho() && "Not implemented");
10802+
assert(!Subtarget->isTargetMacho() && "Not implemented");
1080310803
SDLoc dl(Op);
1080410804

1080510805
// Get the inputs.
@@ -15512,7 +15512,7 @@ X86TargetLowering::EmitLoweredWinAlloca(MachineInstr *MI,
1551215512
const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
1551315513
DebugLoc DL = MI->getDebugLoc();
1551415514

15515-
assert(!Subtarget->isTargetEnvMacho());
15515+
assert(!Subtarget->isTargetMacho());
1551615516

1551715517
// The lowering is pretty easy: we're just emitting the call to _alloca. The
1551815518
// non-trivial part is impdef of ESP.

llvm/lib/Target/X86/X86Subtarget.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,11 @@ class X86Subtarget : public X86GenSubtargetInfo {
319319
bool isTargetSolaris() const {
320320
return TargetTriple.getOS() == Triple::Solaris;
321321
}
322-
bool isTargetELF() const {
323-
return (TargetTriple.getEnvironment() == Triple::ELF ||
324-
TargetTriple.isOSBinFormatELF());
325-
}
322+
323+
bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
324+
bool isTargetCOFF() const { return TargetTriple.isOSBinFormatCOFF(); }
325+
bool isTargetMacho() const { return TargetTriple.isOSBinFormatMachO(); }
326+
326327
bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
327328
bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); }
328329
bool isTargetNaCl32() const { return isTargetNaCl() && !is64Bit(); }
@@ -331,11 +332,6 @@ class X86Subtarget : public X86GenSubtargetInfo {
331332
bool isTargetMingw() const { return TargetTriple.getOS() == Triple::MinGW32; }
332333
bool isTargetCygwin() const { return TargetTriple.getOS() == Triple::Cygwin; }
333334
bool isTargetCygMing() const { return TargetTriple.isOSCygMing(); }
334-
bool isTargetCOFF() const {
335-
return (TargetTriple.getEnvironment() != Triple::ELF &&
336-
TargetTriple.isOSBinFormatCOFF());
337-
}
338-
bool isTargetEnvMacho() const { return TargetTriple.isEnvironmentMachO(); }
339335

340336
bool isOSWindows() const { return TargetTriple.isOSWindows(); }
341337

0 commit comments

Comments
 (0)