@@ -67,7 +67,7 @@ XtensaTargetLowering::XtensaTargetLowering(const TargetMachine &tm,
67
67
setStackPointerRegisterToSaveRestore (Xtensa::SP);
68
68
69
69
setSchedulingPreference (Sched::RegPressure);
70
-
70
+
71
71
setBooleanContents (ZeroOrOneBooleanContent);
72
72
setBooleanVectorContents (ZeroOrOneBooleanContent);
73
73
@@ -88,6 +88,7 @@ XtensaTargetLowering::XtensaTargetLowering(const TargetMachine &tm,
88
88
// Handle the various types of symbolic address.
89
89
setOperationAction (ISD::ConstantPool, PtrVT, Custom);
90
90
setOperationAction (ISD::GlobalAddress, PtrVT, Custom);
91
+ setOperationAction (ISD::GlobalTLSAddress, PtrVT, Custom);
91
92
setOperationAction (ISD::BlockAddress, PtrVT, Custom);
92
93
setOperationAction (ISD::JumpTable, PtrVT, Custom);
93
94
@@ -1298,6 +1299,44 @@ SDValue XtensaTargetLowering::LowerGlobalAddress(SDValue Op,
1298
1299
llvm_unreachable (" invalid global addresses to lower" );
1299
1300
}
1300
1301
1302
+ SDValue XtensaTargetLowering::LowerGlobalTLSAddress (GlobalAddressSDNode *GA,
1303
+ SelectionDAG &DAG) const {
1304
+ SDLoc DL (GA);
1305
+ const GlobalValue *GV = GA->getGlobal ();
1306
+ EVT PtrVT = getPointerTy (DAG.getDataLayout ());
1307
+
1308
+ if (DAG.getTarget ().useEmulatedTLS ())
1309
+ return LowerToTLSEmulatedModel (GA, DAG);
1310
+
1311
+ TLSModel::Model model = getTargetMachine ().getTLSModel (GV);
1312
+
1313
+ if (!Subtarget.hasTHREADPTR ()) {
1314
+ llvm_unreachable (" only emulated TLS supported" );
1315
+ }
1316
+
1317
+ if ((model == TLSModel::LocalExec) || (model == TLSModel::InitialExec)) {
1318
+ auto PtrVt = getPointerTy (DAG.getDataLayout ());
1319
+
1320
+ bool Priv = GV->isPrivateLinkage (GV->getLinkage ());
1321
+ // Create a constant pool entry for the callee address
1322
+ XtensaConstantPoolValue *CPV = XtensaConstantPoolSymbol::Create (
1323
+ *DAG.getContext (), GV->getName ().str ().c_str () /* Sym */ ,
1324
+ 0 /* XtensaCLabelIndex */ , Priv, XtensaCP::TPOFF);
1325
+
1326
+ // Get the address of the callee into a register
1327
+ SDValue CPAddr = DAG.getTargetConstantPool (CPV, PtrVt, 4 );
1328
+ SDValue CPWrap = getAddrPCRel (CPAddr, DAG);
1329
+
1330
+ SDValue TPRegister = DAG.getRegister (Xtensa::THREADPTR, MVT::i32 );
1331
+ SDValue ThreadPointer =
1332
+ DAG.getNode (XtensaISD::RUR, DL, MVT::i32 , TPRegister);
1333
+ return DAG.getNode (ISD::ADD, DL, PtrVT, ThreadPointer, CPWrap);
1334
+ } else
1335
+ llvm_unreachable (" only local-exec and initial-exec TLS mode supported" );
1336
+
1337
+ return SDValue ();
1338
+ }
1339
+
1301
1340
SDValue XtensaTargetLowering::LowerBlockAddress (BlockAddressSDNode *Node,
1302
1341
SelectionDAG &DAG) const {
1303
1342
const BlockAddress *BA = Node->getBlockAddress ();
@@ -1629,6 +1668,8 @@ SDValue XtensaTargetLowering::LowerOperation(SDValue Op,
1629
1668
return LowerSELECT_CC (Op, DAG);
1630
1669
case ISD::GlobalAddress:
1631
1670
return LowerGlobalAddress (Op, DAG);
1671
+ case ISD::GlobalTLSAddress:
1672
+ return LowerGlobalTLSAddress (cast<GlobalAddressSDNode>(Op), DAG);
1632
1673
case ISD::BlockAddress:
1633
1674
return LowerBlockAddress (cast<BlockAddressSDNode>(Op), DAG);
1634
1675
case ISD::JumpTable:
@@ -1685,6 +1726,7 @@ const char *XtensaTargetLowering::getTargetNodeName(unsigned Opcode) const {
1685
1726
OPCODE (MSUB);
1686
1727
OPCODE (MOVS);
1687
1728
OPCODE (MOVSP);
1729
+ OPCODE (RUR);
1688
1730
OPCODE (SHL);
1689
1731
OPCODE (SRA);
1690
1732
OPCODE (SRL);
0 commit comments