Add support for implicit TLS model used with MS VC runtime.
authorAnton Korobeynikov <asl@math.spbu.ru>
Sat, 11 Feb 2012 17:26:53 +0000 (17:26 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Sat, 11 Feb 2012 17:26:53 +0000 (17:26 +0000)
Patch by Kai Nacke!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150307 91177308-0d34-0410-b5e6-96231b3b80d8

21 files changed:
include/llvm/MC/MCExpr.h
include/llvm/MC/MCObjectFileInfo.h
lib/CodeGen/TargetLoweringObjectFileImpl.cpp
lib/MC/MCExpr.cpp
lib/MC/MCObjectFileInfo.cpp
lib/Target/X86/MCTargetDesc/X86BaseInfo.h
lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp
lib/Target/X86/X86AsmPrinter.cpp
lib/Target/X86/X86ISelLowering.cpp
lib/Target/X86/X86MCInstLower.cpp
test/CodeGen/X86/tls1.ll
test/CodeGen/X86/tls11.ll
test/CodeGen/X86/tls12.ll
test/CodeGen/X86/tls13.ll
test/CodeGen/X86/tls14.ll
test/CodeGen/X86/tls2.ll
test/CodeGen/X86/tls3.ll
test/CodeGen/X86/tls4.ll
test/CodeGen/X86/tls5.ll
test/CodeGen/X86/tls6.ll

index 093278395f64f39704261e8f739d74d38d8b61ff..2ae1e848382637aa72400b80d5b5c349749b2363 100644 (file)
@@ -162,6 +162,7 @@ public:
     VK_TPOFF,
     VK_DTPOFF,
     VK_TLVP,      // Mach-O thread local variable relocation
     VK_TPOFF,
     VK_DTPOFF,
     VK_TLVP,      // Mach-O thread local variable relocation
+    VK_SECREL,
     // FIXME: We'd really like to use the generic Kinds listed above for these.
     VK_ARM_PLT,   // ARM-style PLT references. i.e., (PLT) instead of @PLT
     VK_ARM_TLSGD, //   ditto for TLSGD, GOT, GOTOFF, TPOFF and GOTTPOFF
     // FIXME: We'd really like to use the generic Kinds listed above for these.
     VK_ARM_PLT,   // ARM-style PLT references. i.e., (PLT) instead of @PLT
     VK_ARM_TLSGD, //   ditto for TLSGD, GOT, GOTOFF, TPOFF and GOTTPOFF
index c3d2019f37cb79a3e0cbae6ca1e531ad310676f3..e58e7d68f7fd55709e5c27dd880ff435a0ac55b8 100644 (file)
@@ -109,7 +109,7 @@ protected:
   const MCSection *TLSExtraDataSection;
   
   /// TLSDataSection - Section directive for Thread Local data.
   const MCSection *TLSExtraDataSection;
   
   /// TLSDataSection - Section directive for Thread Local data.
-  /// ELF and MachO only.
+  /// ELF, MachO and COFF.
   const MCSection *TLSDataSection;        // Defaults to ".tdata".
 
   /// TLSBSSSection - Section directive for Thread Local uninitialized data.
   const MCSection *TLSDataSection;        // Defaults to ".tdata".
 
   /// TLSBSSSection - Section directive for Thread Local uninitialized data.
index fd67d628b657a7e3aec3f1552b454d61262606d6..3a71f4f126712392b7d1d710c8666e0ed067b0c7 100644 (file)
@@ -588,6 +588,11 @@ getCOFFSectionFlags(SectionKind K) {
       COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
       COFF::IMAGE_SCN_MEM_READ |
       COFF::IMAGE_SCN_MEM_WRITE;
       COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
       COFF::IMAGE_SCN_MEM_READ |
       COFF::IMAGE_SCN_MEM_WRITE;
+  else if (K.isThreadLocal())
+    Flags |=
+      COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+      COFF::IMAGE_SCN_MEM_READ |
+      COFF::IMAGE_SCN_MEM_WRITE;
   else if (K.isReadOnly())
     Flags |=
       COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
   else if (K.isReadOnly())
     Flags |=
       COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
@@ -614,6 +619,8 @@ static const char *getCOFFSectionPrefixForUniqueGlobal(SectionKind Kind) {
     return ".text$";
   if (Kind.isBSS ())
     return ".bss$";
     return ".text$";
   if (Kind.isBSS ())
     return ".bss$";
+  if (Kind.isThreadLocal())
+    return ".tls$";
   if (Kind.isWriteable())
     return ".data$";
   return ".rdata$";
   if (Kind.isWriteable())
     return ".data$";
   return ".rdata$";
@@ -623,7 +630,6 @@ static const char *getCOFFSectionPrefixForUniqueGlobal(SectionKind Kind) {
 const MCSection *TargetLoweringObjectFileCOFF::
 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
                        Mangler *Mang, const TargetMachine &TM) const {
 const MCSection *TargetLoweringObjectFileCOFF::
 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
                        Mangler *Mang, const TargetMachine &TM) const {
-  assert(!Kind.isThreadLocal() && "Doesn't support TLS");
 
   // If this global is linkonce/weak and the target handles this by emitting it
   // into a 'uniqued' section name, create and return the section now.
 
   // If this global is linkonce/weak and the target handles this by emitting it
   // into a 'uniqued' section name, create and return the section now.
@@ -644,6 +650,9 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
   if (Kind.isText())
     return getTextSection();
 
   if (Kind.isText())
     return getTextSection();
 
+  if (Kind.isThreadLocal())
+    return getTLSDataSection();
+
   return getDataSection();
 }
 
   return getDataSection();
 }
 
index ccdccdf514646c81dd3e164e20d57b7136212717..f3a91cbd5ef7d408b581621c1a486b0f99e022af 100644 (file)
@@ -188,6 +188,7 @@ StringRef MCSymbolRefExpr::getVariantKindName(VariantKind Kind) {
   case VK_TPOFF: return "TPOFF";
   case VK_DTPOFF: return "DTPOFF";
   case VK_TLVP: return "TLVP";
   case VK_TPOFF: return "TPOFF";
   case VK_DTPOFF: return "DTPOFF";
   case VK_TLVP: return "TLVP";
+  case VK_SECREL: return "SECREL";
   case VK_ARM_PLT: return "(PLT)";
   case VK_ARM_GOT: return "(GOT)";
   case VK_ARM_GOTOFF: return "(GOTOFF)";
   case VK_ARM_PLT: return "(PLT)";
   case VK_ARM_GOT: return "(GOT)";
   case VK_ARM_GOTOFF: return "(GOTOFF)";
index 4c03aaa87329379fac9f95f5c5d3a9cdea4bf122..1b8653531e8293ed819ef96815a5073804e06395 100644 (file)
@@ -495,6 +495,12 @@ void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
                         COFF::IMAGE_SCN_MEM_READ |
                         COFF::IMAGE_SCN_MEM_WRITE,
                         SectionKind::getDataRel());
                         COFF::IMAGE_SCN_MEM_READ |
                         COFF::IMAGE_SCN_MEM_WRITE,
                         SectionKind::getDataRel());
+  TLSDataSection =
+    Ctx->getCOFFSection(".tls$",
+                        COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                        COFF::IMAGE_SCN_MEM_READ |
+                        COFF::IMAGE_SCN_MEM_WRITE,
+                        SectionKind::getDataRel());
 }
 
 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
 }
 
 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
index 820b248909bb303d51953383587c5873a8392d85..c41e9e7aef605b0750a33875263a05e591366d88 100644 (file)
@@ -164,7 +164,13 @@ namespace X86II {
     /// is some TLS offset from the picbase.
     ///
     /// This is the 32-bit TLS offset for Darwin TLS in PIC mode.
     /// is some TLS offset from the picbase.
     ///
     /// This is the 32-bit TLS offset for Darwin TLS in PIC mode.
-    MO_TLVP_PIC_BASE
+    MO_TLVP_PIC_BASE,
+
+    /// MO_SECREL - On a symbol operand this indicates that the immediate is
+    /// the offset from beginning of section.
+    ///
+    /// This is the TLS offset for the COFF/Windows TLS mechanism.
+    MO_SECREL
   };
 
   enum {
   };
 
   enum {
index 7f24766f678348a3bff8764925092e33a85376c0..b0305b44cffa9cdc965a71eb7736925f117bc631 100644 (file)
@@ -222,6 +222,7 @@ EmitImmediate(const MCOperand &DispOp, SMLoc Loc, unsigned Size,
 
   // If we have an immoffset, add it to the expression.
   if ((FixupKind == FK_Data_4 ||
 
   // If we have an immoffset, add it to the expression.
   if ((FixupKind == FK_Data_4 ||
+       FixupKind == FK_Data_8 ||
        FixupKind == MCFixupKind(X86::reloc_signed_4byte))) {
     GlobalOffsetTableExprKind Kind = StartsWithGlobalOffsetTable(Expr);
     if (Kind != GOT_None) {
        FixupKind == MCFixupKind(X86::reloc_signed_4byte))) {
     GlobalOffsetTableExprKind Kind = StartsWithGlobalOffsetTable(Expr);
     if (Kind != GOT_None) {
@@ -230,6 +231,11 @@ EmitImmediate(const MCOperand &DispOp, SMLoc Loc, unsigned Size,
       FixupKind = MCFixupKind(X86::reloc_global_offset_table);
       if (Kind == GOT_Normal)
         ImmOffset = CurByte;
       FixupKind = MCFixupKind(X86::reloc_global_offset_table);
       if (Kind == GOT_Normal)
         ImmOffset = CurByte;
+    } else if (Expr->getKind() == MCExpr::SymbolRef) {
+      const MCSymbolRefExpr *Ref = static_cast<const MCSymbolRefExpr*>(Expr);
+      if (Ref->getKind() == MCSymbolRefExpr::VK_SECREL) {
+        FixupKind = MCFixupKind(FK_SecRel_4);
+      }
     }
   }
 
     }
   }
 
index a337aaa6a522f8b26f3f7e428e62e537f3142dd4..bc272efcc9ceea1cd8f841ea6546df903622adc2 100644 (file)
@@ -52,7 +52,7 @@ unsigned X86WinCOFFObjectWriter::getRelocType(unsigned FixupKind) const {
       return COFF::IMAGE_REL_AMD64_ADDR64;
     llvm_unreachable("unsupported relocation type");
   case FK_SecRel_4:
       return COFF::IMAGE_REL_AMD64_ADDR64;
     llvm_unreachable("unsupported relocation type");
   case FK_SecRel_4:
-    return Is64Bit ? COFF::IMAGE_REL_AMD64_SREL32 : COFF::IMAGE_REL_I386_SECREL;
+    return Is64Bit ? COFF::IMAGE_REL_AMD64_SECREL : COFF::IMAGE_REL_I386_SECREL;
   default:
     llvm_unreachable("unsupported relocation type");
   }
   default:
     llvm_unreachable("unsupported relocation type");
   }
index 5949064ee387c9a042c9a218f1ef618dab090e35..c61ad729d9863784d8dce074a88264774444a616 100644 (file)
@@ -199,6 +199,7 @@ void X86AsmPrinter::printSymbolOperand(const MachineOperand &MO,
   case X86II::MO_TLVP_PIC_BASE:
     O << "@TLVP" << '-' << *MF->getPICBaseSymbol();
     break;
   case X86II::MO_TLVP_PIC_BASE:
     O << "@TLVP" << '-' << *MF->getPICBaseSymbol();
     break;
+  case X86II::MO_SECREL:      O << "@SECREL";      break;
   }
 }
 
   }
 }
 
index 1343b571ece4934b0bf7185be30418dc6d1b9286..6d292068bd2f963147379dc635d12cdc442df034 100644 (file)
@@ -7355,6 +7355,68 @@ X86TargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const {
     unsigned Reg = Subtarget->is64Bit() ? X86::RAX : X86::EAX;
     return DAG.getCopyFromReg(Chain, DL, Reg, getPointerTy(),
                               Chain.getValue(1));
     unsigned Reg = Subtarget->is64Bit() ? X86::RAX : X86::EAX;
     return DAG.getCopyFromReg(Chain, DL, Reg, getPointerTy(),
                               Chain.getValue(1));
+  } else if (Subtarget->isTargetWindows()) {
+    // Just use the implicit TLS architecture
+    // Need to generate someting similar to:
+    //   mov     rdx, qword [gs:abs 58H]; Load pointer to ThreadLocalStorage
+    //                                  ; from TEB
+    //   mov     ecx, dword [rel _tls_index]: Load index (from C runtime)
+    //   mov     rcx, qword [rdx+rcx*8]
+    //   mov     eax, .tls$:tlsvar
+    //   [rax+rcx] contains the address
+    // Windows 64bit: gs:0x58
+    // Windows 32bit: fs:__tls_array
+
+    // If GV is an alias then use the aliasee for determining
+    // thread-localness.
+    if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV))
+      GV = GA->resolveAliasedGlobal(false);
+    DebugLoc dl = GA->getDebugLoc();
+    SDValue Chain = DAG.getEntryNode();
+
+    // Get the Thread Pointer, which is %fs:__tls_array (32-bit) or
+    // %gs:0x58 (64-bit).
+    Value *Ptr = Constant::getNullValue(Subtarget->is64Bit()
+                                        ? Type::getInt8PtrTy(*DAG.getContext(),
+                                                             256)
+                                        : Type::getInt32PtrTy(*DAG.getContext(),
+                                                              257));
+
+    SDValue ThreadPointer = DAG.getLoad(getPointerTy(), dl, Chain,
+                                        Subtarget->is64Bit()
+                                        ? DAG.getIntPtrConstant(0x58)
+                                        : DAG.getExternalSymbol("_tls_array",
+                                                                getPointerTy()),
+                                        MachinePointerInfo(Ptr),
+                                        false, false, false, 0);
+
+    // Load the _tls_index variable
+    SDValue IDX = DAG.getExternalSymbol("_tls_index", getPointerTy());
+    if (Subtarget->is64Bit())
+      IDX = DAG.getExtLoad(ISD::ZEXTLOAD, dl, getPointerTy(), Chain,
+                           IDX, MachinePointerInfo(), MVT::i32,
+                           false, false, 0);
+    else
+      IDX = DAG.getLoad(getPointerTy(), dl, Chain, IDX, MachinePointerInfo(),
+                        false, false, false, 0);
+
+    SDValue Scale = DAG.getConstant(Log2_64_Ceil(TD->getPointerSize()),
+                                           getPointerTy());
+    IDX = DAG.getNode(ISD::SHL, dl, getPointerTy(), IDX, Scale);
+
+    SDValue res = DAG.getNode(ISD::ADD, dl, getPointerTy(), ThreadPointer, IDX);
+    res = DAG.getLoad(getPointerTy(), dl, Chain, res, MachinePointerInfo(),
+                      false, false, false, 0);
+
+    // Get the offset of start of .tls section
+    SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl,
+                                             GA->getValueType(0),
+                                             GA->getOffset(), X86II::MO_SECREL);
+    SDValue Offset = DAG.getNode(X86ISD::Wrapper, dl, getPointerTy(), TGA);
+
+    // The address of the thread local variable is the add of the thread
+    // pointer with the offset of the variable.
+    return DAG.getNode(ISD::ADD, dl, getPointerTy(), res, Offset);
   }
 
   llvm_unreachable("TLS not implemented for this target.");
   }
 
   llvm_unreachable("TLS not implemented for this target.");
index 89e19674486ff113de2b52ab46c128b14377e974..c2c46986d2f7b27f8383bf9ed2711c1fa5e72e49 100644 (file)
@@ -154,6 +154,7 @@ MCOperand X86MCInstLower::LowerSymbolOperand(const MachineOperand &MO,
                                                            Ctx),
                                    Ctx);
     break;
                                                            Ctx),
                                    Ctx);
     break;
+  case X86II::MO_SECREL:    RefKind = MCSymbolRefExpr::VK_SECREL; break;
   case X86II::MO_TLSGD:     RefKind = MCSymbolRefExpr::VK_TLSGD; break;
   case X86II::MO_GOTTPOFF:  RefKind = MCSymbolRefExpr::VK_GOTTPOFF; break;
   case X86II::MO_INDNTPOFF: RefKind = MCSymbolRefExpr::VK_INDNTPOFF; break;
   case X86II::MO_TLSGD:     RefKind = MCSymbolRefExpr::VK_TLSGD; break;
   case X86II::MO_GOTTPOFF:  RefKind = MCSymbolRefExpr::VK_GOTTPOFF; break;
   case X86II::MO_INDNTPOFF: RefKind = MCSymbolRefExpr::VK_INDNTPOFF; break;
@@ -230,7 +231,8 @@ static void LowerUnaryToTwoAddr(MCInst &OutMI, unsigned NewOpc) {
 /// a short fixed-register form.
 static void SimplifyShortImmForm(MCInst &Inst, unsigned Opcode) {
   unsigned ImmOp = Inst.getNumOperands() - 1;
 /// a short fixed-register form.
 static void SimplifyShortImmForm(MCInst &Inst, unsigned Opcode) {
   unsigned ImmOp = Inst.getNumOperands() - 1;
-  assert(Inst.getOperand(0).isReg() && Inst.getOperand(ImmOp).isImm() &&
+  assert(Inst.getOperand(0).isReg() &&
+         (Inst.getOperand(ImmOp).isImm() || Inst.getOperand(ImmOp).isExpr()) &&
          ((Inst.getNumOperands() == 3 && Inst.getOperand(1).isReg() &&
            Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) ||
           Inst.getNumOperands() == 2) && "Unexpected instruction!");
          ((Inst.getNumOperands() == 3 && Inst.getOperand(1).isReg() &&
            Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) ||
           Inst.getNumOperands() == 2) && "Unexpected instruction!");
index 0cae5c4f2888ffa23df4eb2ef0bac2e0ceb331a8..f39658e01b2dbb75f25325095b5dd7fb74145178 100644 (file)
@@ -1,7 +1,7 @@
-; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu > %t
-; RUN: grep {movl      %gs:i@NTPOFF, %eax} %t
-; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu > %t2
-; RUN: grep {movl      %fs:i@TPOFF, %eax} %t2
+; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu | FileCheck -check-prefix=X32_LINUX %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu | FileCheck -check-prefix=X64_LINUX %s
+; RUN: llc < %s -march=x86 -mtriple=x86-pc-win32 | FileCheck -check-prefix=X32_WIN %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-pc-win32 | FileCheck -check-prefix=X64_WIN %s
 
 @i = thread_local global i32 15
 
 
 @i = thread_local global i32 15
 
@@ -10,3 +10,11 @@ entry:
        %tmp1 = load i32* @i
        ret i32 %tmp1
 }
        %tmp1 = load i32* @i
        ret i32 %tmp1
 }
+; X32_LINUX: movl %gs:i@NTPOFF, %eax
+; X64_LINUX: movl %fs:i@TPOFF, %eax
+; X32_WIN: movl __tls_index, %eax
+; X32_WIN: movl %fs:__tls_array, %ecx
+; X32_WIN: movl _i@SECREL(%eax), %eax
+; X64_WIN: movl _tls_index(%rip), %eax
+; X64_WIN: movabsq $i@SECREL, %rcx
+
index 514a168c5387824bb18aaf3a92951b624f29c99f..cc1482603706a3885951e307d41a8cf29c9fd1e1 100644 (file)
@@ -1,7 +1,7 @@
-; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu > %t
-; RUN: grep {movzwl    %gs:i@NTPOFF, %eax} %t
-; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu > %t2
-; RUN: grep {movzwl    %fs:i@TPOFF, %eax} %t2
+; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu | FileCheck -check-prefix=X32_LINUX %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu | FileCheck -check-prefix=X64_LINUX %s
+; RUN: llc < %s -march=x86 -mtriple=x86-pc-win32 | FileCheck -check-prefix=X32_WIN %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-pc-win32 | FileCheck -check-prefix=X64_WIN %s
 
 @i = thread_local global i16 15
 
 
 @i = thread_local global i16 15
 
@@ -10,3 +10,12 @@ entry:
        %tmp1 = load i16* @i
        ret i16 %tmp1
 }
        %tmp1 = load i16* @i
        ret i16 %tmp1
 }
+; X32_LINUX: movzwl %gs:i@NTPOFF, %eax
+; X64_LINUX: movzwl %fs:i@TPOFF, %eax
+; X32_WIN: movl __tls_index, %eax
+; X32_WIN: movl %fs:__tls_array, %ecx
+; X32_WIN: movzwl _i@SECREL(%eax), %eax
+; X64_WIN: movl _tls_index(%rip), %eax
+; X64_WIN: movq %gs:88, %rcx
+; X64_WIN: movabsq $i@SECREL, %rcx
+; X64_WIN: movzwl (%rax,%rcx), %eax
index c29f6adacd2026478e8e16e4fde935bb219863e8..3da789e8f19abf559c9be30433a5757275f04f15 100644 (file)
@@ -1,7 +1,7 @@
-; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu > %t
-; RUN: grep {movb      %gs:i@NTPOFF, %al} %t
-; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu > %t2
-; RUN: grep {movb      %fs:i@TPOFF, %al} %t2
+; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu | FileCheck -check-prefix=X32_LINUX %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu | FileCheck -check-prefix=X64_LINUX %s
+; RUN: llc < %s -march=x86 -mtriple=x86-pc-win32 | FileCheck -check-prefix=X32_WIN %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-pc-win32 | FileCheck -check-prefix=X64_WIN %s
 
 @i = thread_local global i8 15
 
 
 @i = thread_local global i8 15
 
@@ -10,3 +10,12 @@ entry:
        %tmp1 = load i8* @i
        ret i8 %tmp1
 }
        %tmp1 = load i8* @i
        ret i8 %tmp1
 }
+; X32_LINUX: movb %gs:i@NTPOFF, %al
+; X64_LINUX: movb %fs:i@TPOFF, %al
+; X32_WIN: movl __tls_index, %eax
+; X32_WIN: movl %fs:__tls_array, %ecx
+; X32_WIN: movb _i@SECREL(%eax), %al
+; X64_WIN: movl _tls_index(%rip), %eax
+; X64_WIN: movq %gs:88, %rcx
+; X64_WIN: movabsq $i@SECREL, %rcx
+; X64_WIN: movb (%rax,%rcx), %al
index 08778ec2ce8b1aea2b2093d26c45e91321ae4add..0f6a98a06653f51382bbe314ea5cec3588427af4 100644 (file)
@@ -1,9 +1,7 @@
-; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu > %t
-; RUN: grep {movswl    %gs:i@NTPOFF, %eax} %t
-; RUN: grep {movzwl    %gs:j@NTPOFF, %eax} %t
-; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu > %t2
-; RUN: grep {movswl    %fs:i@TPOFF, %edi} %t2
-; RUN: grep {movzwl    %fs:j@TPOFF, %edi} %t2
+; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu | FileCheck -check-prefix=X32_LINUX %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu | FileCheck -check-prefix=X64_LINUX %s
+; RUN: llc < %s -march=x86 -mtriple=x86-pc-win32 | FileCheck -check-prefix=X32_WIN %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-pc-win32 | FileCheck -check-prefix=X64_WIN %s
 
 @i = thread_local global i16 0
 @j = thread_local global i16 0
 
 @i = thread_local global i16 0
 @j = thread_local global i16 0
@@ -22,3 +20,14 @@ entry:
 declare void @g(i32)
 
 declare void @h(i32)
 declare void @g(i32)
 
 declare void @h(i32)
+
+; X32_LINUX: movswl %gs:i@NTPOFF, %eax
+; X32_LINUX: movzwl %gs:j@NTPOFF, %eax
+; X64_LINUX: movswl %fs:i@TPOFF, %edi
+; X64_LINUX: movzwl %fs:j@TPOFF, %edi
+; X32_WIN: movswl _i@SECREL(%esi), %eax
+; X32_WIN: movzwl _j@SECREL(%esi), %eax
+; X64_WIN: movabsq $i@SECREL, %rax
+; X64_WIN: movswl (%rsi,%rax), %ecx
+; X64_WIN: movabsq $j@SECREL, %rax
+; X64_WIN: movzwl (%rsi,%rax), %ecx
index 88426dd43d50e166c9e3bd6f2691aa26cde5f046..646257184101e4123771425c699344652561d7b8 100644 (file)
@@ -1,9 +1,7 @@
-; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu > %t
-; RUN: grep {movsbl    %gs:i@NTPOFF, %eax} %t
-; RUN: grep {movzbl    %gs:j@NTPOFF, %eax} %t
-; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu > %t2
-; RUN: grep {movsbl    %fs:i@TPOFF, %edi} %t2
-; RUN: grep {movzbl    %fs:j@TPOFF, %edi} %t2
+; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu | FileCheck -check-prefix=X32_LINUX %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu | FileCheck -check-prefix=X64_LINUX %s
+; RUN: llc < %s -march=x86 -mtriple=x86-pc-win32 | FileCheck -check-prefix=X32_WIN %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-pc-win32 | FileCheck -check-prefix=X64_WIN %s
 
 @i = thread_local global i8 0
 @j = thread_local global i8 0
 
 @i = thread_local global i8 0
 @j = thread_local global i8 0
@@ -22,3 +20,14 @@ entry:
 declare void @g(i32)
 
 declare void @h(i32)
 declare void @g(i32)
 
 declare void @h(i32)
+
+; X32_LINUX: movsbl %gs:i@NTPOFF, %eax
+; X32_LINUX: movzbl %gs:j@NTPOFF, %eax
+; X64_LINUX: movsbl %fs:i@TPOFF, %edi
+; X64_LINUX: movzbl %fs:j@TPOFF, %edi
+; X32_WIN: movsbl _i@SECREL(%esi), %eax
+; X32_WIN: movzbl _j@SECREL(%esi), %eax
+; X64_WIN: movabsq $i@SECREL, %rax
+; X64_WIN: movsbl (%rsi,%rax), %ecx
+; X64_WIN: movabsq $j@SECREL, %rax
+; X64_WIN: movzbl (%rsi,%rax), %ecx
index 5a94296afefc184153541cf122d14c2e90b0cd44..e882f535ffb4dfa527fa3291c097789a7e39e6e2 100644 (file)
@@ -1,9 +1,7 @@
-; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu > %t
-; RUN: grep {movl      %gs:0, %eax} %t
-; RUN: grep {leal      i@NTPOFF(%eax), %eax} %t
-; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu > %t2
-; RUN: grep {movq      %fs:0, %rax} %t2
-; RUN: grep {leaq      i@TPOFF(%rax), %rax} %t2
+; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu | FileCheck -check-prefix=X32_LINUX %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu | FileCheck -check-prefix=X64_LINUX %s
+; RUN: llc < %s -march=x86 -mtriple=x86-pc-win32 | FileCheck -check-prefix=X32_WIN %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-pc-win32 | FileCheck -check-prefix=X64_WIN %s
 
 @i = thread_local global i32 15
 
 
 @i = thread_local global i32 15
 
@@ -11,3 +9,13 @@ define i32* @f() {
 entry:
        ret i32* @i
 }
 entry:
        ret i32* @i
 }
+; X32_LINUX: movl %gs:0, %eax
+; X32_LINUX: leal i@NTPOFF(%eax), %eax
+; X64_LINUX: movq %fs:0, %rax
+; X64_LINUX: leaq i@TPOFF(%rax), %rax
+; X32_WIN: movl __tls_index, %eax
+; X32_WIN: movl %fs:__tls_array, %ecx
+; X32_WIN: leal _i@SECREL(%eax), %eax
+; X64_WIN: movl _tls_index(%rip), %eax
+; X64_WIN: movq %gs:88, %rcx
+; X64_WIN: addq $i@SECREL, %rax
index 7327cc41777e9c675d82277e5d329b0a07d63c69..ee3f28f4daf7b70340a4d38e44bff340debcbd0b 100644 (file)
@@ -1,9 +1,7 @@
-; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu > %t
-; RUN: grep {movl      i@INDNTPOFF, %eax} %t
-; RUN: grep {movl      %gs:(%eax), %eax} %t
-; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu > %t2
-; RUN: grep {movq      i@GOTTPOFF(%rip), %rax} %t2
-; RUN: grep {movl      %fs:(%rax), %eax} %t2
+; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu | FileCheck -check-prefix=X32_LINUX %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu | FileCheck -check-prefix=X64_LINUX %s
+; RUN: llc < %s -march=x86 -mtriple=x86-pc-win32 | FileCheck -check-prefix=X32_WIN %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-pc-win32 | FileCheck -check-prefix=X64_WIN %s
 
 @i = external thread_local global i32          ; <i32*> [#uses=2]
 
 
 @i = external thread_local global i32          ; <i32*> [#uses=2]
 
@@ -12,3 +10,12 @@ entry:
        %tmp1 = load i32* @i            ; <i32> [#uses=1]
        ret i32 %tmp1
 }
        %tmp1 = load i32* @i            ; <i32> [#uses=1]
        ret i32 %tmp1
 }
+; X32_LINUX: movl i@INDNTPOFF, %eax
+; X32_LINUX: movl %gs:(%eax), %eax
+; X64_LINUX: movq i@GOTTPOFF(%rip), %rax
+; X64_LINUX: movl %fs:(%rax), %eax
+; X32_WIN: movl __tls_index, %eax
+; X32_WIN: movl %fs:__tls_array, %ecx
+; X32_WIN: movl _i@SECREL(%eax), %eax
+; X64_WIN: movl _tls_index(%rip), %eax
+; X64_WIN: movabsq $i@SECREL, %rcx
index d2e40e389bd5703e8b220493e28e02a0ed16d7d0..2b53ec57fea0bb7a2e244e075494ad0c42ed35c3 100644 (file)
@@ -1,9 +1,7 @@
-; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu > %t
-; RUN: grep {movl      %gs:0, %eax} %t
-; RUN: grep {addl      i@INDNTPOFF, %eax} %t
-; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu > %t2
-; RUN: grep {movq      %fs:0, %rax} %t2
-; RUN: grep {addq      i@GOTTPOFF(%rip), %rax} %t2
+; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu | FileCheck -check-prefix=X32_LINUX %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu | FileCheck -check-prefix=X64_LINUX %s
+; RUN: llc < %s -march=x86 -mtriple=x86-pc-win32 | FileCheck -check-prefix=X32_WIN %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-pc-win32 | FileCheck -check-prefix=X64_WIN %s
 
 @i = external thread_local global i32          ; <i32*> [#uses=2]
 
 
 @i = external thread_local global i32          ; <i32*> [#uses=2]
 
@@ -11,3 +9,13 @@ define i32* @f() {
 entry:
        ret i32* @i
 }
 entry:
        ret i32* @i
 }
+; X32_LINUX: movl %gs:0, %eax
+; X32_LINUX: addl i@INDNTPOFF, %eax
+; X64_LINUX: movq %fs:0, %rax
+; X64_LINUX: addq i@GOTTPOFF(%rip), %rax
+; X32_WIN: movl __tls_index, %eax
+; X32_WIN: movl %fs:__tls_array, %ecx
+; X32_WIN: leal _i@SECREL(%eax), %eax
+; X64_WIN: movl _tls_index(%rip), %eax
+; X64_WIN: movq %gs:88, %rcx
+; X64_WIN: addq $i@SECREL, %rax
index 4d2cc02b50286b102b499db061ca2e914981a0ab..3cc6dab59041242c278a7f2cc86e671c363ef91d 100644 (file)
@@ -1,7 +1,7 @@
-; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu > %t
-; RUN: grep {movl      %gs:i@NTPOFF, %eax} %t
-; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu > %t2
-; RUN: grep {movl      %fs:i@TPOFF, %eax} %t2
+; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu | FileCheck -check-prefix=X32_LINUX %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu | FileCheck -check-prefix=X64_LINUX %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-pc-win32 | FileCheck -check-prefix=X64_WIN %s
+; RUN: llc < %s -march=x86 -mtriple=x86-pc-win32 | FileCheck -check-prefix=X32_WIN %s
 
 @i = internal thread_local global i32 15
 
 
 @i = internal thread_local global i32 15
 
@@ -10,3 +10,10 @@ entry:
        %tmp1 = load i32* @i
        ret i32 %tmp1
 }
        %tmp1 = load i32* @i
        ret i32 %tmp1
 }
+; X32_LINUX: movl %gs:i@NTPOFF, %eax
+; X64_LINUX: movl %fs:i@TPOFF, %eax
+; X32_WIN: movl __tls_index, %eax
+; X32_WIN: movl %fs:__tls_array, %ecx
+; X32_WIN: movl _i@SECREL(%eax), %eax
+; X64_WIN: movl _tls_index(%rip), %eax
+; X64_WIN: movabsq $i@SECREL, %rcx
index 505106ee14ed40c910b78e1e798a57f6c92a8ce0..c98ad7c360e7c15271bd4e7f4a5800b9afef360e 100644 (file)
@@ -1,9 +1,7 @@
-; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu > %t
-; RUN: grep {movl      %gs:0, %eax} %t
-; RUN: grep {leal      i@NTPOFF(%eax), %eax} %t
-; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu > %t2
-; RUN: grep {movq      %fs:0, %rax} %t2
-; RUN: grep {leaq      i@TPOFF(%rax), %rax} %t2
+; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu | FileCheck -check-prefix=X32_LINUX %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu | FileCheck -check-prefix=X64_LINUX %s
+; RUN: llc < %s -march=x86 -mtriple=x86-pc-win32 | FileCheck -check-prefix=X32_WIN %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-pc-win32 | FileCheck -check-prefix=X64_WIN %s
 
 @i = internal thread_local global i32 15
 
 
 @i = internal thread_local global i32 15
 
@@ -11,3 +9,13 @@ define i32* @f() {
 entry:
        ret i32* @i
 }
 entry:
        ret i32* @i
 }
+; X32_LINUX: movl %gs:0, %eax
+; X32_LINUX: leal i@NTPOFF(%eax), %eax
+; X64_LINUX: movq %fs:0, %rax
+; X64_LINUX: leaq i@TPOFF(%rax), %rax
+; X32_WIN: movl __tls_index, %eax
+; X32_WIN: movl %fs:__tls_array, %ecx
+; X32_WIN: leal _i@SECREL(%eax), %eax
+; X64_WIN: movl _tls_index(%rip), %eax
+; X64_WIN: movq %gs:88, %rcx
+; X64_WIN: addq $i@SECREL, %rax