diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/SelectionDAG/TargetLowering.cpp | 22 | ||||
-rw-r--r-- | lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp | 29 | ||||
-rw-r--r-- | lib/Target/X86/X86ISelLowering.cpp | 32 |
3 files changed, 69 insertions, 14 deletions
diff --git a/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 3f56febafa..e92932b186 100644 --- a/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -26,6 +26,28 @@ #include "llvm/Support/MathExtras.h" using namespace llvm; +namespace llvm { +TLSModel::Model getTLSModel(const GlobalValue *GV, Reloc::Model reloc) { + bool isLocal = GV->hasLocalLinkage(); + bool isDeclaration = GV->isDeclaration(); + // FIXME: what should we do for protected and internal visibility? + // For variables, is internal different from hidden? + bool isHidden = GV->hasHiddenVisibility(); + + if (reloc == Reloc::PIC_) { + if (isLocal || isHidden) + return TLSModel::LocalDynamic; + else + return TLSModel::GeneralDynamic; + } else { + if (!isDeclaration || isHidden) + return TLSModel::LocalExec; + else + return TLSModel::InitialExec; + } +} +} + /// InitLibcallNames - Set default libcall names. /// static void InitLibcallNames(const char **Names) { diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp index ca1d7385ad..e0bd6a3e34 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp @@ -439,13 +439,30 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, printOffset(MO.getOffset()); if (isThreadLocal) { - if (TM.getRelocationModel() == Reloc::PIC_ || Subtarget->is64Bit()) - O << "@TLSGD"; // general dynamic TLS model - else - if (GV->isDeclaration()) - O << "@INDNTPOFF"; // initial exec TLS model + TLSModel::Model model = getTLSModel(GVar, TM.getRelocationModel()); + switch (model) { + case TLSModel::GeneralDynamic: + O << "@TLSGD"; + break; + case TLSModel::LocalDynamic: + // O << "@TLSLD"; // local dynamic not implemented + O << "@TLSGD"; + break; + case TLSModel::InitialExec: + if (Subtarget->is64Bit()) + O << "@TLSGD"; // 64 bit intial exec not implemented else - O << "@NTPOFF"; // local exec TLS model + O << "@INDNTPOFF"; + break; + case TLSModel::LocalExec: + if (Subtarget->is64Bit()) + O << "@TLSGD"; // 64 bit local exec not implemented + else + O << "@NTPOFF"; + break; + default: + assert (0 && "Unknown TLS model"); + } } else if (isMemOp) { if (shouldPrintGOT(TM, Subtarget)) { if (Subtarget->GVRequiresExtraLoad(GV, TM, false)) diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index d18c283c4f..c3a29b2a43 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -4795,7 +4795,7 @@ LowerToTLSGeneralDynamicModel64(GlobalAddressSDNode *GA, SelectionDAG &DAG, // Lower ISD::GlobalTLSAddress using the "initial exec" (for no-pic) or // "local exec" model. static SDValue LowerToTLSExecModel(GlobalAddressSDNode *GA, SelectionDAG &DAG, - const MVT PtrVT) { + const MVT PtrVT, TLSModel::Model model) { DebugLoc dl = GA->getDebugLoc(); // Get the Thread Pointer SDValue ThreadPointer = DAG.getNode(X86ISD::THREAD_POINTER, @@ -4807,7 +4807,7 @@ static SDValue LowerToTLSExecModel(GlobalAddressSDNode *GA, SelectionDAG &DAG, GA->getOffset()); SDValue Offset = DAG.getNode(X86ISD::Wrapper, dl, PtrVT, TGA); - if (GA->getGlobal()->isDeclaration()) // initial exec TLS model + if (model == TLSModel::InitialExec) Offset = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Offset, PseudoSourceValue::getGOT(), 0); @@ -4823,15 +4823,31 @@ X86TargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) { assert(Subtarget->isTargetELF() && "TLS not implemented for non-ELF targets"); GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); - // If the relocation model is PIC, use the "General Dynamic" TLS Model, - // otherwise use the "Local Exec"TLS Model + GlobalValue *GV = GA->getGlobal(); + TLSModel::Model model = + getTLSModel (GV, getTargetMachine().getRelocationModel()); if (Subtarget->is64Bit()) { - return LowerToTLSGeneralDynamicModel64(GA, DAG, getPointerTy()); + 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()); + default: + assert (0 && "Unknown TLS model"); + } } else { - if (getTargetMachine().getRelocationModel() == Reloc::PIC_) + switch (model) { + case TLSModel::GeneralDynamic: + case TLSModel::LocalDynamic: // not implemented return LowerToTLSGeneralDynamicModel32(GA, DAG, getPointerTy()); - else - return LowerToTLSExecModel(GA, DAG, getPointerTy()); + + case TLSModel::InitialExec: + case TLSModel::LocalExec: + return LowerToTLSExecModel(GA, DAG, getPointerTy(), model); + default: + assert (0 && "Unknown TLS model"); + } } } |