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:
if (Subtarget->isTargetDarwin()) {
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";
} else {
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) {
if (Subtarget->isTargetDarwin() ||
Subtarget->isTargetELF() ||
Subtarget->isTargetCygwin()) {
Subtarget->isTargetCygMing()) {
// Let PassManager know we need debug information and relay
// the MachineDebugInfo address on to DwarfWriter.
DW.SetDebugInfo(&getAnalysis<MachineDebugInfo>());
@ -99,7 +99,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
if (Subtarget->isTargetDarwin()) {
O << "\t.globl\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.
O << "\t.linkonce discard\n";
O << "\t.globl " << CurrentFnName << "\n";
@ -111,14 +111,14 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
}
O << CurrentFnName << ":\n";
// Add some workaround for linkonce linkage on Cygwin\MinGW
if (Subtarget->isTargetCygwin() &&
if (Subtarget->isTargetCygMing() &&
(F->getLinkage() == Function::LinkOnceLinkage ||
F->getLinkage() == Function::WeakLinkage))
O << "_llvm$workaround$fake$stub_" << CurrentFnName << ":\n";
if (Subtarget->isTargetDarwin() ||
Subtarget->isTargetELF() ||
Subtarget->isTargetCygwin()) {
Subtarget->isTargetCygMing()) {
// Emit pre-function debug information.
DW.BeginFunction(&MF);
}
@ -150,7 +150,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
if (Subtarget->isTargetDarwin() ||
Subtarget->isTargetELF() ||
Subtarget->isTargetCygwin()) {
Subtarget->isTargetCygMing()) {
// Emit post-function debug information.
DW.EndFunction();
}

View File

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

View File

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

View File

@ -534,7 +534,7 @@ void X86DAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
void X86DAGToDAGISel::EmitSpecialCodeForMain(MachineBasicBlock *BB,
MachineFrameInfo *MFI) {
const TargetInstrInfo *TII = TM.getInstrInfo();
if (Subtarget->isTargetCygwin())
if (Subtarget->isTargetCygMing())
BuildMI(BB, TII->get(X86::CALLpcrel32)).addExternalSymbol("__main");
// 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.
setUseUnderscoreSetJmp(false);
setUseUnderscoreLongJmp(false);
} else if (Subtarget->isTargetCygwin()) {
} else if (Subtarget->isTargetMingw()) {
// MS runtime is weird: it exports _setjmp, but longjmp!
setUseUnderscoreSetJmp(true);
setUseUnderscoreLongJmp(false);
@ -234,7 +234,7 @@ X86TargetLowering::X86TargetLowering(TargetMachine &TM)
// FIXME - use subtarget debug flags
if (!Subtarget->isTargetDarwin() &&
!Subtarget->isTargetELF() &&
!Subtarget->isTargetCygwin())
!Subtarget->isTargetCygMing())
setOperationAction(ISD::DEBUG_LABEL, MVT::Other, Expand);
// 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();
const Function* Fn = MF.getFunction();
if (Fn->hasExternalLinkage() &&
Subtarget->isTargetCygwin() &&
Subtarget->isTargetCygMing() &&
Fn->getName() == "main")
MF.getInfo<X86FunctionInfo>()->setForceFramePointer(true);

View File

@ -1010,7 +1010,7 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
MFI->setStackSize(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
// 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
@ -1054,7 +1054,7 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
// If it's main() on Cygwin\Mingw32 we should align stack as well
if (Fn->hasExternalLinkage() && Fn->getName() == "main" &&
Subtarget->isTargetCygwin()) {
Subtarget->isTargetCygMing()) {
MI= BuildMI(TII.get(X86::AND32ri), X86::ESP).addReg(X86::ESP).addImm(-Align);
MBB.insert(MBBI, MI);

View File

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

View File

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

View File

@ -103,7 +103,9 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
break;
case X86Subtarget::isCygwin:
case X86Subtarget::isMingw:
GlobalPrefix = "_";
LCOMMDirective = "\t.lcomm\t";
COMMDirectiveTakesAlignment = false;
HasDotTypeDotSizeDirective = false;
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),
InstrInfo(*this), JITInfo(*this), TLInfo(*this) {
if (getRelocationModel() == Reloc::Default)
if (Subtarget.isTargetDarwin() || Subtarget.isTargetCygwin())
if (Subtarget.isTargetDarwin() || Subtarget.isTargetCygMing())
setRelocationModel(Reloc::DynamicNoPIC);
else
setRelocationModel(Reloc::Static);