[llvm] [Xtensa] Implement THREADPTR and DFPAccel Xtensa Options. (PR #145543)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 27 06:11:57 PDT 2025
================
@@ -919,6 +920,58 @@ SDValue XtensaTargetLowering::LowerGlobalAddress(SDValue Op,
return Res;
}
+SDValue XtensaTargetLowering::LowerGlobalTLSAddress(SDValue Op,
+ SelectionDAG &DAG) const {
+ const GlobalAddressSDNode *G = cast<GlobalAddressSDNode>(Op);
+ SDLoc DL(Op);
+ auto PtrVT = Op.getValueType();
+ const GlobalValue *GV = G->getGlobal();
+
+ if (DAG.getTarget().useEmulatedTLS())
+ return LowerToTLSEmulatedModel(G, DAG);
+
+ TLSModel::Model model = getTargetMachine().getTLSModel(GV);
+
+ if (!Subtarget.hasTHREADPTR()) {
+ DAG.getContext()->diagnose(DiagnosticInfoUnsupported(
+ DAG.getMachineFunction().getFunction(), "only emulated TLS supported",
+ DL.getDebugLoc()));
+ }
+
+ if (model == TLSModel::LocalExec || model == TLSModel::InitialExec) {
+ bool Priv = GV->isPrivateLinkage(GV->getLinkage());
+ MachineFunction &MF = DAG.getMachineFunction();
+ XtensaMachineFunctionInfo *XtensaFI =
+ MF.getInfo<XtensaMachineFunctionInfo>();
+ unsigned LabelId = XtensaFI->createCPLabelId();
+
+ // Create a constant pool entry for the callee address
+ XtensaConstantPoolValue *CPV = XtensaConstantPoolSymbol::Create(
+ *DAG.getContext(), GV->getName().str().c_str(), LabelId, Priv,
+ XtensaCP::TPOFF);
+
+ // Get the address of the callee into a register
+ SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, Align(4));
+ SDValue CPWrap = getAddrPCRel(CPAddr, DAG);
+ SDValue Addr = DAG.getLoad(
+ PtrVT, DL, DAG.getEntryNode(), CPWrap,
+ MachinePointerInfo::getConstantPool(DAG.getMachineFunction()));
+
+ SDValue TPRegister = DAG.getRegister(Xtensa::THREADPTR, MVT::i32);
+ SDValue ThreadPointer =
+ DAG.getNode(XtensaISD::RUR, DL, MVT::i32, TPRegister);
+
+ return DAG.getNode(ISD::ADD, DL, PtrVT, ThreadPointer, Addr);
+ } else {
----------------
arsenm wrote:
No else after return
https://github.com/llvm/llvm-project/pull/145543
More information about the llvm-commits
mailing list