[PATCH] D143708: [RISCV] Add emulated TLS supported
Vitaly Cheptsov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 10 01:10:54 PST 2023
vit9696 created this revision.
vit9696 added reviewers: MaskRay, jrtc27, brad, paulkirth, phosek, hiraditya.
vit9696 added projects: All, LLVM.
Herald added subscribers: luke, VincentWu, vkmr, frasercrmck, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, krytarowski, arichardson.
vit9696 requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, eopXD.
As discussed earlier in the GitHub issue <https://github.com/llvm/llvm-project/issues/59500>, currently LLVM generates invalid code when emulated TLS is used. There were attempts to resolve this previously (D102527 <https://reviews.llvm.org/D102527>), but they were not merged because the component owners raised concerns about emulated TLS efficiency.
The current state of the art is that:
- OpenBSD team, which raised the initial issue, simply has patches downstream <https://github.com/openbsd/src/blob/a0747c9/gnu/llvm/llvm/lib/Target/RISCV/RISCVISelLowering.cpp#L2850-L2852>.
- Our team, which raised the GH issue, has patches downstream as well. We also do not use `malloc` or any dynamic allocations <https://github.com/llvm/llvm-project/issues/59500#issuecomment-1349046835> with emulated TLS, so the concerns raised in the original issue does not apply to us.
- GCC compatibility is broken, because GCC supports emulated TLS.
- RISC-V is the only architecture in LLVM that does not support emulated TLS, and work is being done to at least warn the users about it (D143619 <https://reviews.llvm.org/D143619>).
With all these in mind I believe it is important to address the consumers' needs especially given that there is little to no maintenance downsides.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D143708
Files:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -4569,6 +4569,9 @@
SDValue RISCVTargetLowering::lowerGlobalTLSAddress(SDValue Op,
SelectionDAG &DAG) const {
+ GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op);
+ if (DAG.getTarget().useEmulatedTLS())
+ return LowerToTLSEmulatedModel(GA, DAG);
GlobalAddressSDNode *N = cast<GlobalAddressSDNode>(Op);
assert(N->getOffset() == 0 && "unexpected offset in global node");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143708.496364.patch
Type: text/x-patch
Size: 660 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230210/e83954b7/attachment.bin>
More information about the llvm-commits
mailing list