darwin doesn't support .bss, but it does have .zerofill
[oota-llvm.git] / lib / Target / X86 / X86TargetAsmInfo.cpp
index ed9f1ac313278fefdb6c3a0f2da9b96541f687e6..1735220ae2c206dc078077edaa397916229291d2 100644 (file)
@@ -14,6 +14,7 @@
 #include "X86TargetAsmInfo.h"
 #include "X86TargetMachine.h"
 #include "X86Subtarget.h"
+#include "llvm/DerivedTypes.h"
 #include "llvm/InlineAsm.h"
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
@@ -46,6 +47,8 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
       Data64bitsDirective = 0;       // we can't emit a 64-bit unit
     ZeroDirective = "\t.space\t";  // ".space N" emits N zeros.
     PrivateGlobalPrefix = "L";     // Marker for constant pool idxs
+    BSSSection = 0;                       // no BSS section.
+    ZeroFillDirective = "\t.zerofill\t";  // Uses .zerofill
     ConstantPoolSection = "\t.const\n";
     JumpTableDataSection = "\t.const\n";
     CStringSection = "\t.cstring";
@@ -63,6 +66,7 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
     SetDirective = "\t.set";
     UsedDirective = "\t.no_dead_strip\t";
     WeakRefDirective = "\t.weak_reference\t";
+    HiddenDirective = "\t.private_extern\t";
     
     NeedsSet = true;
     DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug";
@@ -86,7 +90,7 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
     // bool HasDotLoc; // Defaults to false.
     // HasDotFile - True if target asm supports .file directives.
     // bool HasDotFile; // Defaults to false.
-    PrivateGlobalPrefix = ".";  // Prefix for private global symbols
+    PrivateGlobalPrefix = ".L";
     WeakRefDirective = "\t.weak\t";
     DwarfRequiresFrameSection = false;
     DwarfAbbrevSection =  "\t.section\t.debug_abbrev,\"\",@progbits";
@@ -103,11 +107,14 @@ 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\"";
     StaticDtorsSection = "\t.section .dtors,\"aw\"";
+    HiddenDirective = NULL;
 
     // Set up DWARF directives
     HasLEB128 = true;  // Target asm supports leb128 directives (little-endian)
@@ -125,12 +132,12 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
     DwarfRangesSection =  "\t.section\t.debug_ranges,\"dr\"";
     DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"dr\"";
     break;
-    
-    break;
+
   case X86Subtarget::isWindows:
     GlobalPrefix = "_";
     HasDotTypeDotSizeDirective = false;
     break;
+
   default: break;
   }
   
@@ -152,11 +159,14 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
     
     TextSection = "_text";
     DataSection = "_data";
+    JumpTableDataSection = NULL;
     SwitchToSectionDirective = "";
     TextSectionStartSuffix = "\tsegment 'CODE'";
     DataSectionStartSuffix = "\tsegment 'DATA'";
     SectionEndDirectiveSuffix = "\tends\n";
   }
+
+  AssemblerDialect = Subtarget->getAsmFlavor();
 }
 
 bool X86TargetAsmInfo::LowerToBSwap(CallInst *CI) const {
@@ -171,28 +181,28 @@ bool X86TargetAsmInfo::LowerToBSwap(CallInst *CI) const {
       !CI->getType()->isInteger())
     return false;
   
-  const Type *Ty = CI->getType()->getUnsignedVersion();
+  const Type *Ty = CI->getType();
   const char *IntName;
-  switch (Ty->getTypeID()) {
-  default: return false;
-  case Type::UShortTyID: IntName = "llvm.bswap.i16"; break;
-  case Type::UIntTyID:   IntName = "llvm.bswap.i32"; break;
-  case Type::ULongTyID:  IntName = "llvm.bswap.i64"; break;
-  }
+  if (const IntegerType *ITy = dyn_cast<IntegerType>(Ty)) {
+    unsigned BitWidth = ITy->getBitWidth();
+    if (BitWidth == 16)
+      IntName = "llvm.bswap.i16";
+    else if (BitWidth == 32)
+      IntName = "llvm.bswap.i32";
+    else if (BitWidth == 64)
+      IntName = "llvm.bswap.i64";
+    else
+      return false;
+  } else
+    return false;
 
   // Okay, we can do this xform, do so now.
   Module *M = CI->getParent()->getParent()->getParent();
-  Function *Int = M->getOrInsertFunction(IntName, Ty, Ty, (Type*)0);
+  Constant *Int = M->getOrInsertFunction(IntName, Ty, Ty, (Type*)0);
   
   Value *Op = CI->getOperand(1);
-  if (CI->getOperand(1)->getType() != Ty)
-    Op = new BitCastInst(Op, Ty, Op->getName(), CI);
-  
   Op = new CallInst(Int, Op, CI->getName(), CI);
   
-  if (Op->getType() != CI->getType())
-    Op = new BitCastInst(Op, CI->getType(), Op->getName(), CI);
-  
   CI->replaceAllUsesWith(Op);
   CI->eraseFromParent();
   return true;
@@ -225,7 +235,7 @@ bool X86TargetAsmInfo::ExpandInlineAsm(CallInst *CI) const {
     }
     break;
   case 3:
-    if (CI->getType() == Type::ULongTy && Constraints.size() >= 2 &&
+    if (CI->getType() == Type::Int64Ty && Constraints.size() >= 2 &&
         Constraints[0].Codes.size() == 1 && Constraints[0].Codes[0] == "A" &&
         Constraints[1].Codes.size() == 1 && Constraints[1].Codes[0] == "0") {
       // bswap %eax / bswap %edx / xchgl %eax, %edx  -> llvm.bswap.i64