Really big cleanup.
authorAnton Korobeynikov <asl@math.spbu.ru>
Wed, 3 Jan 2007 11:43:14 +0000 (11:43 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Wed, 3 Jan 2007 11:43:14 +0000 (11:43 +0000)
- 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

lib/Target/X86/X86ATTAsmPrinter.cpp
lib/Target/X86/X86AsmPrinter.cpp
lib/Target/X86/X86AsmPrinter.h
lib/Target/X86/X86ISelDAGToDAG.cpp
lib/Target/X86/X86ISelLowering.cpp
lib/Target/X86/X86RegisterInfo.cpp
lib/Target/X86/X86Subtarget.cpp
lib/Target/X86/X86Subtarget.h
lib/Target/X86/X86TargetAsmInfo.cpp
lib/Target/X86/X86TargetMachine.cpp

index f9b03b2455f9b85545aec480d5b3ce24e271b112..e3448928416e5b38d3a1e6d87f82f83de21e7541 100755 (executable)
@@ -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();
   }
index 65d2e7d36a6f6b8609d6cfb58da96d00ceb417b7..4f55f42a5a41f479193503593104221099dfcb23 100644 (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();
   }
index c5f521bf786ebbe6e568d913c4412dd4715d45d8..ab885fdf7e921e9ec335de53262668f93307f766 100755 (executable)
@@ -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);
index 411bcbeb561c92ea1a5036130c089fc5a560228c..5c80f2375339dd261356579d0ebc7dcecdd62932 100644 (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.
index ac1b708e885b2201063c50b9665573f78fc03b2a..ca9cfcdea76966fb23a10d09654d5c7370a77777 100644 (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);
 
index 2e899a5fae72472e6bb63b1e06eed1ca050d24d4..eff79721ba65d57d1f31016b7a2eeeb0b6170ec5 100644 (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);
 
index 05965c24cddc100610770494034f916fcb894e67..6feb0af49160e0465fd70c5455cccb67978130ac 100644 (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;
 }
index ba43e385dae9ab9c2653d411a9dc20fd00767a29..863e1af93141bfadd56c4b6ac322ce1f890ad7cd 100644 (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
index e25e2690af438f1f32a3fa314da12cd7a0944ddf..6e95e89e8e01c91c33fa228e2daa3a67bd8344b6 100644 (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\"";
index 9dee7c897d0948833488e6ccdd0c4daff5be5ba6..d92ae498cf0cde540cf6c5163d618b2dc0b174db 100644 (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);