@@ -101,6 +101,7 @@ XtensaTargetLowering::XtensaTargetLowering(const TargetMachine &TM,
101101
102102 setOperationAction (ISD::ConstantPool, PtrVT, Custom);
103103 setOperationAction (ISD::GlobalAddress, PtrVT, Custom);
104+ setOperationAction (ISD::GlobalTLSAddress, PtrVT, Custom);
104105 setOperationAction (ISD::BlockAddress, PtrVT, Custom);
105106 setOperationAction (ISD::JumpTable, PtrVT, Custom);
106107
@@ -972,6 +973,58 @@ SDValue XtensaTargetLowering::LowerGlobalAddress(SDValue Op,
972973 return Res;
973974}
974975
976+ SDValue XtensaTargetLowering::LowerGlobalTLSAddress (SDValue Op,
977+ SelectionDAG &DAG) const {
978+ const GlobalAddressSDNode *G = cast<GlobalAddressSDNode>(Op);
979+ SDLoc DL (Op);
980+ EVT PtrVT = Op.getValueType ();
981+ const GlobalValue *GV = G->getGlobal ();
982+
983+ if (DAG.getTarget ().useEmulatedTLS ())
984+ return LowerToTLSEmulatedModel (G, DAG);
985+
986+ TLSModel::Model model = getTargetMachine ().getTLSModel (GV);
987+
988+ if (!Subtarget.hasTHREADPTR ()) {
989+ DAG.getContext ()->diagnose (DiagnosticInfoUnsupported (
990+ DAG.getMachineFunction ().getFunction (), " only emulated TLS supported" ,
991+ DL.getDebugLoc ()));
992+ return DAG.getPOISON (Op->getValueType (0 ));
993+ }
994+
995+ if (model == TLSModel::LocalExec || model == TLSModel::InitialExec) {
996+ bool Priv = GV->isPrivateLinkage (GV->getLinkage ());
997+ MachineFunction &MF = DAG.getMachineFunction ();
998+ XtensaMachineFunctionInfo *XtensaFI =
999+ MF.getInfo <XtensaMachineFunctionInfo>();
1000+ unsigned LabelId = XtensaFI->createCPLabelId ();
1001+
1002+ // Create a constant pool entry for the callee address
1003+ XtensaConstantPoolValue *CPV = XtensaConstantPoolSymbol::Create (
1004+ *DAG.getContext (), GV->getName ().str ().c_str (), LabelId, Priv,
1005+ XtensaCP::TPOFF);
1006+
1007+ // Get the address of the callee into a register
1008+ SDValue CPAddr = DAG.getTargetConstantPool (CPV, PtrVT, Align (4 ));
1009+ SDValue CPWrap = getAddrPCRel (CPAddr, DAG);
1010+ SDValue Addr = DAG.getLoad (
1011+ PtrVT, DL, DAG.getEntryNode (), CPWrap,
1012+ MachinePointerInfo::getConstantPool (DAG.getMachineFunction ()));
1013+
1014+ SDValue TPRegister = DAG.getRegister (Xtensa::THREADPTR, MVT::i32 );
1015+ SDValue ThreadPointer =
1016+ DAG.getNode (XtensaISD::RUR, DL, MVT::i32 , TPRegister);
1017+
1018+ return DAG.getNode (ISD::ADD, DL, PtrVT, ThreadPointer, Addr);
1019+ }
1020+
1021+ DAG.getContext ()->diagnose (DiagnosticInfoUnsupported (
1022+ DAG.getMachineFunction ().getFunction (),
1023+ " only local-exec and initial-exec TLS mode supported" , DL.getDebugLoc ()));
1024+
1025+ return DAG.getPOISON (Op->getValueType (0 ));
1026+ }
1027+
9751028SDValue XtensaTargetLowering::LowerBlockAddress (SDValue Op,
9761029 SelectionDAG &DAG) const {
9771030 BlockAddressSDNode *Node = cast<BlockAddressSDNode>(Op);
@@ -1406,6 +1459,8 @@ SDValue XtensaTargetLowering::LowerOperation(SDValue Op,
14061459 return LowerRETURNADDR (Op, DAG);
14071460 case ISD::GlobalAddress:
14081461 return LowerGlobalAddress (Op, DAG);
1462+ case ISD::GlobalTLSAddress:
1463+ return LowerGlobalTLSAddress (Op, DAG);
14091464 case ISD::BlockAddress:
14101465 return LowerBlockAddress (Op, DAG);
14111466 case ISD::JumpTable:
@@ -1459,6 +1514,8 @@ const char *XtensaTargetLowering::getTargetNodeName(unsigned Opcode) const {
14591514 return " XtensaISD::RET" ;
14601515 case XtensaISD::RETW:
14611516 return " XtensaISD::RETW" ;
1517+ case XtensaISD::RUR:
1518+ return " XtensaISD::RUR" ;
14621519 case XtensaISD::SELECT_CC:
14631520 return " XtensaISD::SELECT_CC" ;
14641521 case XtensaISD::SELECT_CC_FP:
0 commit comments