Really big cleanup.

- New target type "mingw" was introduced
- Same things for both mingw & cygwin are marked as "cygming" (as in
gcc)
- .lcomm is supported here, so allow LLVM to use it
- Correctly use underscored versions of setjmp & _longjmp for both mingw
& cygwin


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32833 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Anton Korobeynikov 2007-01-03 11:43:14 +00:00
parent 7f7fdcca8f
commit 317848f4a1
10 changed files with 33 additions and 24 deletions

View File

@ -42,7 +42,7 @@ std::string X86ATTAsmPrinter::getSectionForFunction(const Function &F) const {
case Function::LinkOnceLinkage: case Function::LinkOnceLinkage:
if (Subtarget->isTargetDarwin()) { if (Subtarget->isTargetDarwin()) {
return ".section __TEXT,__textcoal_nt,coalesced,pure_instructions"; return ".section __TEXT,__textcoal_nt,coalesced,pure_instructions";
} else if (Subtarget->isTargetCygwin()) { } else if (Subtarget->isTargetCygMing()) {
return "\t.section\t.text$linkonce." + CurrentFnName + ",\"ax\"\n"; return "\t.section\t.text$linkonce." + CurrentFnName + ",\"ax\"\n";
} else { } else {
return "\t.section\t.llvm.linkonce.t." + CurrentFnName + return "\t.section\t.llvm.linkonce.t." + CurrentFnName +
@ -57,7 +57,7 @@ std::string X86ATTAsmPrinter::getSectionForFunction(const Function &F) const {
bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) { bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
if (Subtarget->isTargetDarwin() || if (Subtarget->isTargetDarwin() ||
Subtarget->isTargetELF() || Subtarget->isTargetELF() ||
Subtarget->isTargetCygwin()) { Subtarget->isTargetCygMing()) {
// Let PassManager know we need debug information and relay // Let PassManager know we need debug information and relay
// the MachineDebugInfo address on to DwarfWriter. // the MachineDebugInfo address on to DwarfWriter.
DW.SetDebugInfo(&getAnalysis<MachineDebugInfo>()); DW.SetDebugInfo(&getAnalysis<MachineDebugInfo>());
@ -99,7 +99,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
if (Subtarget->isTargetDarwin()) { if (Subtarget->isTargetDarwin()) {
O << "\t.globl\t" << CurrentFnName << "\n"; O << "\t.globl\t" << CurrentFnName << "\n";
O << "\t.weak_definition\t" << CurrentFnName << "\n"; O << "\t.weak_definition\t" << CurrentFnName << "\n";
} else if (Subtarget->isTargetCygwin()) { } else if (Subtarget->isTargetCygMing()) {
EmitAlignment(4, F); // FIXME: This should be parameterized somewhere. EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
O << "\t.linkonce discard\n"; O << "\t.linkonce discard\n";
O << "\t.globl " << CurrentFnName << "\n"; O << "\t.globl " << CurrentFnName << "\n";
@ -111,14 +111,14 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
} }
O << CurrentFnName << ":\n"; O << CurrentFnName << ":\n";
// Add some workaround for linkonce linkage on Cygwin\MinGW // Add some workaround for linkonce linkage on Cygwin\MinGW
if (Subtarget->isTargetCygwin() && if (Subtarget->isTargetCygMing() &&
(F->getLinkage() == Function::LinkOnceLinkage || (F->getLinkage() == Function::LinkOnceLinkage ||
F->getLinkage() == Function::WeakLinkage)) F->getLinkage() == Function::WeakLinkage))
O << "_llvm$workaround$fake$stub_" << CurrentFnName << ":\n"; O << "_llvm$workaround$fake$stub_" << CurrentFnName << ":\n";
if (Subtarget->isTargetDarwin() || if (Subtarget->isTargetDarwin() ||
Subtarget->isTargetELF() || Subtarget->isTargetELF() ||
Subtarget->isTargetCygwin()) { Subtarget->isTargetCygMing()) {
// Emit pre-function debug information. // Emit pre-function debug information.
DW.BeginFunction(&MF); DW.BeginFunction(&MF);
} }
@ -150,7 +150,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
if (Subtarget->isTargetDarwin() || if (Subtarget->isTargetDarwin() ||
Subtarget->isTargetELF() || Subtarget->isTargetELF() ||
Subtarget->isTargetCygwin()) { Subtarget->isTargetCygMing()) {
// Emit post-function debug information. // Emit post-function debug information.
DW.EndFunction(); DW.EndFunction();
} }

View File

@ -111,7 +111,7 @@ bool X86SharedAsmPrinter::doInitialization(Module &M) {
// Emit initial debug information. // Emit initial debug information.
DW.BeginModule(&M); DW.BeginModule(&M);
} else if (Subtarget->isTargetELF() || Subtarget->isTargetCygwin()) { } else if (Subtarget->isTargetELF() || Subtarget->isTargetCygMing()) {
// Emit initial debug information. // Emit initial debug information.
DW.BeginModule(&M); DW.BeginModule(&M);
} }
@ -161,7 +161,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
} else } else
O << TAI->getCOMMDirective() << name << "," << Size; O << TAI->getCOMMDirective() << name << "," << Size;
} else { } else {
if (!Subtarget->isTargetCygwin()) { if (!Subtarget->isTargetCygMing()) {
if (I->hasInternalLinkage()) if (I->hasInternalLinkage())
O << "\t.local\t" << name << "\n"; O << "\t.local\t" << name << "\n";
} }
@ -179,7 +179,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
O << "\t.globl " << name << "\n" O << "\t.globl " << name << "\n"
<< "\t.weak_definition " << name << "\n"; << "\t.weak_definition " << name << "\n";
SwitchToDataSection(".section __DATA,__const_coal,coalesced", I); SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
} else if (Subtarget->isTargetCygwin()) { } else if (Subtarget->isTargetCygMing()) {
std::string SectionName(".section\t.data$linkonce." + std::string SectionName(".section\t.data$linkonce." +
name + name +
",\"aw\""); ",\"aw\"");
@ -218,7 +218,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
I->getSection() == ".dtors")) { I->getSection() == ".dtors")) {
std::string SectionName = ".section " + I->getSection(); std::string SectionName = ".section " + I->getSection();
if (Subtarget->isTargetCygwin()) { if (Subtarget->isTargetCygMing()) {
SectionName += ",\"aw\""; SectionName += ",\"aw\"";
} else { } else {
assert(!Subtarget->isTargetDarwin()); assert(!Subtarget->isTargetDarwin());
@ -310,7 +310,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
// linker can safely perform dead code stripping. Since LLVM never // linker can safely perform dead code stripping. Since LLVM never
// generates code that does this, it is always safe to set. // generates code that does this, it is always safe to set.
O << "\t.subsections_via_symbols\n"; O << "\t.subsections_via_symbols\n";
} else if (Subtarget->isTargetELF() || Subtarget->isTargetCygwin()) { } else if (Subtarget->isTargetELF() || Subtarget->isTargetCygMing()) {
// Emit final debug information. // Emit final debug information.
DW.EndModule(); DW.EndModule();
} }

View File

@ -67,7 +67,7 @@ struct VISIBILITY_HIDDEN X86SharedAsmPrinter : public AsmPrinter {
AU.setPreservesAll(); AU.setPreservesAll();
if (Subtarget->isTargetDarwin() || if (Subtarget->isTargetDarwin() ||
Subtarget->isTargetELF() || Subtarget->isTargetELF() ||
Subtarget->isTargetCygwin()) { Subtarget->isTargetCygMing()) {
AU.addRequired<MachineDebugInfo>(); AU.addRequired<MachineDebugInfo>();
} }
MachineFunctionPass::getAnalysisUsage(AU); MachineFunctionPass::getAnalysisUsage(AU);

View File

@ -534,7 +534,7 @@ void X86DAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
void X86DAGToDAGISel::EmitSpecialCodeForMain(MachineBasicBlock *BB, void X86DAGToDAGISel::EmitSpecialCodeForMain(MachineBasicBlock *BB,
MachineFrameInfo *MFI) { MachineFrameInfo *MFI) {
const TargetInstrInfo *TII = TM.getInstrInfo(); const TargetInstrInfo *TII = TM.getInstrInfo();
if (Subtarget->isTargetCygwin()) if (Subtarget->isTargetCygMing())
BuildMI(BB, TII->get(X86::CALLpcrel32)).addExternalSymbol("__main"); BuildMI(BB, TII->get(X86::CALLpcrel32)).addExternalSymbol("__main");
// Switch the FPU to 64-bit precision mode for better compatibility and speed. // Switch the FPU to 64-bit precision mode for better compatibility and speed.

View File

@ -58,7 +58,7 @@ X86TargetLowering::X86TargetLowering(TargetMachine &TM)
// Darwin should use _setjmp/_longjmp instead of setjmp/longjmp. // Darwin should use _setjmp/_longjmp instead of setjmp/longjmp.
setUseUnderscoreSetJmp(false); setUseUnderscoreSetJmp(false);
setUseUnderscoreLongJmp(false); setUseUnderscoreLongJmp(false);
} else if (Subtarget->isTargetCygwin()) { } else if (Subtarget->isTargetMingw()) {
// MS runtime is weird: it exports _setjmp, but longjmp! // MS runtime is weird: it exports _setjmp, but longjmp!
setUseUnderscoreSetJmp(true); setUseUnderscoreSetJmp(true);
setUseUnderscoreLongJmp(false); setUseUnderscoreLongJmp(false);
@ -234,7 +234,7 @@ X86TargetLowering::X86TargetLowering(TargetMachine &TM)
// FIXME - use subtarget debug flags // FIXME - use subtarget debug flags
if (!Subtarget->isTargetDarwin() && if (!Subtarget->isTargetDarwin() &&
!Subtarget->isTargetELF() && !Subtarget->isTargetELF() &&
!Subtarget->isTargetCygwin()) !Subtarget->isTargetCygMing())
setOperationAction(ISD::DEBUG_LABEL, MVT::Other, Expand); setOperationAction(ISD::DEBUG_LABEL, MVT::Other, Expand);
// VASTART needs to be custom lowered to use the VarArgsFrameIndex // VASTART needs to be custom lowered to use the VarArgsFrameIndex
@ -4405,7 +4405,7 @@ X86TargetLowering::LowerFORMAL_ARGUMENTS(SDOperand Op, SelectionDAG &DAG) {
MachineFunction &MF = DAG.getMachineFunction(); MachineFunction &MF = DAG.getMachineFunction();
const Function* Fn = MF.getFunction(); const Function* Fn = MF.getFunction();
if (Fn->hasExternalLinkage() && if (Fn->hasExternalLinkage() &&
Subtarget->isTargetCygwin() && Subtarget->isTargetCygMing() &&
Fn->getName() == "main") Fn->getName() == "main")
MF.getInfo<X86FunctionInfo>()->setForceFramePointer(true); MF.getInfo<X86FunctionInfo>()->setForceFramePointer(true);

View File

@ -1010,7 +1010,7 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
MFI->setStackSize(NumBytes); MFI->setStackSize(NumBytes);
if (NumBytes) { // adjust stack pointer: ESP -= numbytes if (NumBytes) { // adjust stack pointer: ESP -= numbytes
if (NumBytes >= 4096 && Subtarget->isTargetCygwin()) { if (NumBytes >= 4096 && Subtarget->isTargetCygMing()) {
// Function prologue calls _alloca to probe the stack when allocating // Function prologue calls _alloca to probe the stack when allocating
// more than 4k bytes in one go. Touching the stack at 4K increments is // more than 4k bytes in one go. Touching the stack at 4K increments is
// necessary to ensure that the guard pages used by the OS virtual memory // necessary to ensure that the guard pages used by the OS virtual memory
@ -1054,7 +1054,7 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
// If it's main() on Cygwin\Mingw32 we should align stack as well // If it's main() on Cygwin\Mingw32 we should align stack as well
if (Fn->hasExternalLinkage() && Fn->getName() == "main" && if (Fn->hasExternalLinkage() && Fn->getName() == "main" &&
Subtarget->isTargetCygwin()) { Subtarget->isTargetCygMing()) {
MI= BuildMI(TII.get(X86::AND32ri), X86::ESP).addReg(X86::ESP).addImm(-Align); MI= BuildMI(TII.get(X86::AND32ri), X86::ESP).addReg(X86::ESP).addImm(-Align);
MBB.insert(MBBI, MI); MBB.insert(MBBI, MI);

View File

@ -40,7 +40,7 @@ bool X86Subtarget::GVRequiresExtraLoad(const GlobalValue* GV,
return (!isDirectCall && return (!isDirectCall &&
(GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() || (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
(GV->isExternal() && !GV->hasNotBeenReadFromBytecode()))); (GV->isExternal() && !GV->hasNotBeenReadFromBytecode())));
} else if (isTargetCygwin() || isTargetWindows()) { } else if (isTargetCygMing() || isTargetWindows()) {
return (GV->hasDLLImportLinkage()); return (GV->hasDLLImportLinkage());
} }
@ -248,16 +248,19 @@ X86Subtarget::X86Subtarget(const Module &M, const std::string &FS, bool is64Bit)
// if one cannot be determined, to true. // if one cannot be determined, to true.
const std::string& TT = M.getTargetTriple(); const std::string& TT = M.getTargetTriple();
if (TT.length() > 5) { if (TT.length() > 5) {
if (TT.find("cygwin") != std::string::npos || if (TT.find("cygwin") != std::string::npos)
TT.find("mingw") != std::string::npos)
TargetType = isCygwin; TargetType = isCygwin;
else if (TT.find("mingw") != std::string::npos)
TargetType = isMingw;
else if (TT.find("darwin") != std::string::npos) else if (TT.find("darwin") != std::string::npos)
TargetType = isDarwin; TargetType = isDarwin;
else if (TT.find("win32") != std::string::npos) else if (TT.find("win32") != std::string::npos)
TargetType = isWindows; TargetType = isWindows;
} else if (TT.empty()) { } else if (TT.empty()) {
#if defined(__CYGWIN__) || defined(__MINGW32__) #if defined(__CYGWIN__)
TargetType = isCygwin; TargetType = isCygwin;
#elif defined(__MINGW32__)
TargetType = isMingw;
#elif defined(__APPLE__) #elif defined(__APPLE__)
TargetType = isDarwin; TargetType = isDarwin;
#elif defined(_WIN32) #elif defined(_WIN32)
@ -277,6 +280,7 @@ X86Subtarget::X86Subtarget(const Module &M, const std::string &FS, bool is64Bit)
if (TargetType == isDarwin || if (TargetType == isDarwin ||
TargetType == isCygwin || TargetType == isCygwin ||
TargetType == isMingw ||
(TargetType == isELF && Is64Bit)) (TargetType == isELF && Is64Bit))
stackAlignment = 16; stackAlignment = 16;
} }

View File

@ -64,7 +64,7 @@ private:
public: public:
enum { enum {
isELF, isCygwin, isDarwin, isWindows isELF, isCygwin, isDarwin, isWindows, isMingw
} TargetType; } TargetType;
/// This constructor initializes the data members to match that /// This constructor initializes the data members to match that
@ -106,6 +106,9 @@ public:
bool isTargetDarwin() const { return TargetType == isDarwin; } bool isTargetDarwin() const { return TargetType == isDarwin; }
bool isTargetELF() const { return TargetType == isELF; } bool isTargetELF() const { return TargetType == isELF; }
bool isTargetWindows() const { return TargetType == isWindows; } bool isTargetWindows() const { return TargetType == isWindows; }
bool isTargetMingw() const { return TargetType == isMingw; }
bool isTargetCygMing() const { return (TargetType == isMingw ||
TargetType == isCygwin); }
bool isTargetCygwin() const { return TargetType == isCygwin; } bool isTargetCygwin() const { return TargetType == isCygwin; }
/// True if accessing the GV requires an extra load. For Windows, dllimported /// True if accessing the GV requires an extra load. For Windows, dllimported

View File

@ -103,7 +103,9 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
break; break;
case X86Subtarget::isCygwin: case X86Subtarget::isCygwin:
case X86Subtarget::isMingw:
GlobalPrefix = "_"; GlobalPrefix = "_";
LCOMMDirective = "\t.lcomm\t";
COMMDirectiveTakesAlignment = false; COMMDirectiveTakesAlignment = false;
HasDotTypeDotSizeDirective = false; HasDotTypeDotSizeDirective = false;
StaticCtorsSection = "\t.section .ctors,\"aw\""; StaticCtorsSection = "\t.section .ctors,\"aw\"";

View File

@ -115,7 +115,7 @@ X86TargetMachine::X86TargetMachine(const Module &M, const std::string &FS, bool
Subtarget.getStackAlignment(), Subtarget.is64Bit() ? -8 : -4), Subtarget.getStackAlignment(), Subtarget.is64Bit() ? -8 : -4),
InstrInfo(*this), JITInfo(*this), TLInfo(*this) { InstrInfo(*this), JITInfo(*this), TLInfo(*this) {
if (getRelocationModel() == Reloc::Default) if (getRelocationModel() == Reloc::Default)
if (Subtarget.isTargetDarwin() || Subtarget.isTargetCygwin()) if (Subtarget.isTargetDarwin() || Subtarget.isTargetCygMing())
setRelocationModel(Reloc::DynamicNoPIC); setRelocationModel(Reloc::DynamicNoPIC);
else else
setRelocationModel(Reloc::Static); setRelocationModel(Reloc::Static);