diff --git a/include/llvm/ADT/Triple.h b/include/llvm/ADT/Triple.h index 8c2d18d5b8e..20191900dbb 100644 --- a/include/llvm/ADT/Triple.h +++ b/include/llvm/ADT/Triple.h @@ -101,7 +101,8 @@ public: GNU, GNUEABI, - EABI + EABI, + MachO }; private: diff --git a/lib/Support/Triple.cpp b/lib/Support/Triple.cpp index c9da964ce13..eadfa56ff31 100644 --- a/lib/Support/Triple.cpp +++ b/lib/Support/Triple.cpp @@ -122,6 +122,7 @@ const char *Triple::getEnvironmentTypeName(EnvironmentType Kind) { case GNU: return "gnu"; case GNUEABI: return "gnueabi"; case EABI: return "eabi"; + case MachO: return "macho"; } return ""; @@ -350,6 +351,8 @@ Triple::EnvironmentType Triple::ParseEnvironment(StringRef EnvironmentName) { return GNUEABI; else if (EnvironmentName.startswith("gnu")) return GNU; + else if (EnvironmentName.startswith("macho")) + return MachO; else return UnknownEnvironment; } diff --git a/lib/Target/X86/X86AsmBackend.cpp b/lib/Target/X86/X86AsmBackend.cpp index 21befd91d43..3c426bed829 100644 --- a/lib/Target/X86/X86AsmBackend.cpp +++ b/lib/Target/X86/X86AsmBackend.cpp @@ -414,7 +414,10 @@ TargetAsmBackend *llvm::createX86_32AsmBackend(const Target &T, case Triple::MinGW32: case Triple::Cygwin: case Triple::Win32: - return new WindowsX86AsmBackend(T, false); + if (Triple(TT).getEnvironment() == Triple::MachO) + return new DarwinX86_32AsmBackend(T); + else + return new WindowsX86AsmBackend(T, false); default: return new ELFX86_32AsmBackend(T, Triple(TT).getOS()); } @@ -428,7 +431,10 @@ TargetAsmBackend *llvm::createX86_64AsmBackend(const Target &T, case Triple::MinGW64: case Triple::Cygwin: case Triple::Win32: - return new WindowsX86AsmBackend(T, true); + if (Triple(TT).getEnvironment() == Triple::MachO) + return new DarwinX86_64AsmBackend(T); + else + return new WindowsX86AsmBackend(T, true); default: return new ELFX86_64AsmBackend(T, Triple(TT).getOS()); } diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp index 5c5f99903fe..99b4479a9fc 100644 --- a/lib/Target/X86/X86AsmPrinter.cpp +++ b/lib/Target/X86/X86AsmPrinter.cpp @@ -53,7 +53,7 @@ using namespace llvm; bool X86AsmPrinter::runOnMachineFunction(MachineFunction &MF) { SetupMachineFunction(MF); - if (Subtarget->isTargetCOFF()) { + if (Subtarget->isTargetCOFF() && !Subtarget->isTargetEnvMacho()) { bool Intrn = MF.getFunction()->hasInternalLinkage(); OutStreamer.BeginCOFFSymbolDef(CurrentFnSym); OutStreamer.EmitCOFFSymbolStorageClass(Intrn ? COFF::IMAGE_SYM_CLASS_STATIC @@ -474,13 +474,13 @@ bool X86AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, } void X86AsmPrinter::EmitStartOfAsmFile(Module &M) { - if (Subtarget->isTargetDarwin()) + if (Subtarget->isTargetEnvMacho()) OutStreamer.SwitchSection(getObjFileLowering().getTextSection()); } void X86AsmPrinter::EmitEndOfAsmFile(Module &M) { - if (Subtarget->isTargetDarwin()) { + if (Subtarget->isTargetEnvMacho()) { // All darwin targets use mach-o. MachineModuleInfoMachO &MMIMacho = MMI->getObjFileInfo(); @@ -581,7 +581,7 @@ void X86AsmPrinter::EmitEndOfAsmFile(Module &M) { OutStreamer.EmitSymbolAttribute(S, MCSA_Global); } - if (Subtarget->isTargetCOFF()) { + if (Subtarget->isTargetCOFF() && !Subtarget->isTargetEnvMacho()) { X86COFFMachineModuleInfo &COFFMMI = MMI->getObjFileInfo(); diff --git a/lib/Target/X86/X86FrameLowering.cpp b/lib/Target/X86/X86FrameLowering.cpp index 1abd170edfc..2db47f4c54a 100644 --- a/lib/Target/X86/X86FrameLowering.cpp +++ b/lib/Target/X86/X86FrameLowering.cpp @@ -556,7 +556,9 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF) const { // responsible for adjusting the stack pointer. Touching the stack at 4K // increments is necessary to ensure that the guard pages used by the OS // virtual memory manager are allocated in correct sequence. - if (NumBytes >= 4096 && (STI.isTargetCygMing() || STI.isTargetWin32())) { + if (NumBytes >= 4096 && + (STI.isTargetCygMing() || STI.isTargetWin32()) && + !STI.isTargetEnvMacho()) { // Check whether EAX is livein for this function. bool isEAXAlive = isEAXLiveIn(MF); @@ -592,7 +594,9 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF) const { StackPtr, false, NumBytes - 4); MBB.insert(MBBI, MI); } - } else if (NumBytes >= 4096 && STI.isTargetWin64()) { + } else if (NumBytes >= 4096 && + STI.isTargetWin64() && + !STI.isTargetEnvMacho()) { // Sanity check that EAX is not livein for this function. It should // should not be, so throw an assert. assert(!isEAXLiveIn(MF) && "EAX is livein in the Win64 case!"); diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index b1b7f47b790..ab75db28eae 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -61,21 +61,21 @@ static SDValue getMOVL(SelectionDAG &DAG, DebugLoc dl, EVT VT, SDValue V1, SDValue V2); static TargetLoweringObjectFile *createTLOF(X86TargetMachine &TM) { - - bool is64Bit = TM.getSubtarget().is64Bit(); - - if (TM.getSubtarget().isTargetDarwin()) { + const X86Subtarget *Subtarget = &TM.getSubtarget(); + bool is64Bit = Subtarget->is64Bit(); + + if (Subtarget->isTargetEnvMacho()) { if (is64Bit) return new X8664_MachoTargetObjectFile(); return new TargetLoweringObjectFileMachO(); } - if (TM.getSubtarget().isTargetELF() ){ + if (Subtarget->isTargetELF()) { if (is64Bit) return new X8664_ELFTargetObjectFile(TM); return new X8632_ELFTargetObjectFile(TM); } - if (TM.getSubtarget().isTargetCOFF()) + if (Subtarget->isTargetCOFF() && !Subtarget->isTargetEnvMacho()) return new TargetLoweringObjectFileCOFF(); llvm_unreachable("unknown subtarget type"); } diff --git a/lib/Target/X86/X86Subtarget.h b/lib/Target/X86/X86Subtarget.h index 95c438d678a..48ceb21946a 100644 --- a/lib/Target/X86/X86Subtarget.h +++ b/lib/Target/X86/X86Subtarget.h @@ -192,6 +192,10 @@ public: return Is64Bit && (isTargetMingw() || isTargetWindows()); } + bool isTargetEnvMacho() const { + return isTargetDarwin() || (TargetTriple.getEnvironment() == Triple::MachO); + } + bool isTargetWin32() const { return !Is64Bit && (isTargetMingw() || isTargetWindows()); } diff --git a/lib/Target/X86/X86TargetMachine.cpp b/lib/Target/X86/X86TargetMachine.cpp index 8de20a366cb..f2162798cee 100644 --- a/lib/Target/X86/X86TargetMachine.cpp +++ b/lib/Target/X86/X86TargetMachine.cpp @@ -33,7 +33,10 @@ static MCAsmInfo *createMCAsmInfo(const Target &T, StringRef TT) { case Triple::MinGW64: case Triple::Cygwin: case Triple::Win32: - return new X86MCAsmInfoCOFF(TheTriple); + if (TheTriple.getEnvironment() == Triple::MachO) + return new X86MCAsmInfoDarwin(TheTriple); + else + return new X86MCAsmInfoCOFF(TheTriple); default: return new X86ELFMCAsmInfo(TheTriple); } @@ -53,7 +56,10 @@ static MCStreamer *createMCStreamer(const Target &T, const std::string &TT, case Triple::MinGW64: case Triple::Cygwin: case Triple::Win32: - return createWinCOFFStreamer(Ctx, TAB, *_Emitter, _OS, RelaxAll); + if (TheTriple.getEnvironment() == Triple::MachO) + return createMachOStreamer(Ctx, TAB, _OS, _Emitter, RelaxAll); + else + return createWinCOFFStreamer(Ctx, TAB, *_Emitter, _OS, RelaxAll); default: return createELFStreamer(Ctx, TAB, _OS, _Emitter, RelaxAll, NoExecStack); }