X86-64 TLS support for local exec and initial exec.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68947 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
index e9b62a8..65ce5ac 100644
--- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
+++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
@@ -454,14 +454,16 @@
O << "@TLSGD";
break;
case TLSModel::InitialExec:
- if (Subtarget->is64Bit())
- O << "@TLSGD"; // 64 bit intial exec not implemented
- else
+ if (Subtarget->is64Bit()) {
+ assert (!NotRIPRel);
+ O << "@GOTTPOFF(%rip)";
+ } else {
O << "@INDNTPOFF";
+ }
break;
case TLSModel::LocalExec:
if (Subtarget->is64Bit())
- O << "@TLSGD"; // 64 bit local exec not implemented
+ O << "@TPOFF";
else
O << "@NTPOFF";
break;
diff --git a/lib/Target/X86/X86ISelDAGToDAG.cpp b/lib/Target/X86/X86ISelDAGToDAG.cpp
index bb8061f..339261f 100644
--- a/lib/Target/X86/X86ISelDAGToDAG.cpp
+++ b/lib/Target/X86/X86ISelDAGToDAG.cpp
@@ -808,9 +808,16 @@
uint64_t Offset = G->getOffset();
if (!is64Bit || isInt32(AM.Disp + Offset)) {
GlobalValue *GV = G->getGlobal();
+ bool isRIPRel = TM.symbolicAddressesAreRIPRel();
+ if (N0.getOpcode() == llvm::ISD::TargetGlobalTLSAddress) {
+ TLSModel::Model model =
+ getTLSModel (GV, TM.getRelocationModel());
+ if (is64Bit && model == TLSModel::InitialExec)
+ isRIPRel = true;
+ }
AM.GV = GV;
AM.Disp += Offset;
- AM.isRIPRel = TM.symbolicAddressesAreRIPRel();
+ AM.isRIPRel = isRIPRel;
return false;
}
} else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(N0)) {
diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp
index ff8382a..825e31d 100644
--- a/lib/Target/X86/X86ISelLowering.cpp
+++ b/lib/Target/X86/X86ISelLowering.cpp
@@ -4831,12 +4831,14 @@
// Lower ISD::GlobalTLSAddress using the "initial exec" (for no-pic) or
// "local exec" model.
static SDValue LowerToTLSExecModel(GlobalAddressSDNode *GA, SelectionDAG &DAG,
- const MVT PtrVT, TLSModel::Model model) {
+ const MVT PtrVT, TLSModel::Model model,
+ bool is64Bit) {
DebugLoc dl = GA->getDebugLoc();
// Get the Thread Pointer
SDValue Base = DAG.getNode(X86ISD::SegmentBaseAddress,
DebugLoc::getUnknownLoc(), PtrVT,
- DAG.getRegister(X86::GS, MVT::i32));
+ DAG.getRegister(is64Bit? X86::FS : X86::GS,
+ MVT::i32));
SDValue ThreadPointer = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Base,
NULL, 0);
@@ -4871,9 +4873,11 @@
switch (model) {
case TLSModel::GeneralDynamic:
case TLSModel::LocalDynamic: // not implemented
- case TLSModel::InitialExec: // not implemented
- case TLSModel::LocalExec: // not implemented
return LowerToTLSGeneralDynamicModel64(GA, DAG, getPointerTy());
+
+ case TLSModel::InitialExec:
+ case TLSModel::LocalExec:
+ return LowerToTLSExecModel(GA, DAG, getPointerTy(), model, true);
}
} else {
switch (model) {
@@ -4883,7 +4887,7 @@
case TLSModel::InitialExec:
case TLSModel::LocalExec:
- return LowerToTLSExecModel(GA, DAG, getPointerTy(), model);
+ return LowerToTLSExecModel(GA, DAG, getPointerTy(), model, false);
}
}
assert(0 && "Unreachable");