[PATCH] D125291: Introduce @llvm.threadlocal.address intrinsic to access TLS variable

Nikita Popov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 15 06:08:40 PST 2022


nikic added a comment.

In D125291#3548671 <https://reviews.llvm.org/D125291#3548671>, @jyknight wrote:

> So, I've been spending some significant time looking into this. I found that I couldn't really review this change for correctness, because I find it basically impossible to figure out whether the intrinsic calls have actually been added to all the right places in Clang or not. (And my intuition said "not", but then couldn't tell me where it's wrong.)
>
> So, I started hacking up a prototype of a change to make the type of a TLS global variable be `token` instead of `ptr`. This allows missing calls to manifest as IR construction errors.
>
> So far the biggest missing piece that identified in this review is function-local thread_locals (although I haven't actually gotten something fully working). Sadly, the handling of function-local statics in Clang is really rather hairy, what with objc blocks and openmp support both doing things that seem rather ill-advised to me. I'm toying with some cleanups there, to see if it can be simplified a bit. I don't have a full idea, yet, what changes need to be made to this review.
>
> Anyhow -- I think the prototype I'm fiddling with is also along the path to the ideal long-term state, but pushing it beyond a prototype seems like it'll be a pain in the ass due to the bitcode compatibility requirement. (The bitcode upgrader would need to know how to transform all constant expressions using a TLS global into non-constant IR instructions, starting with a call to llvm.threadlocal.address -- in every function where the "constant" is referenced. For uses outside a function body, it transforms to an arbitrary address (e.g. null), instead.)

Do you plan to pursue this? We now have the necessary infrastructure to make the bitcode upgrade simple, and I think it would be great to include this change in LLVM 16, so we directly introduce llvm.threadlocal.address in its final form.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125291/new/

https://reviews.llvm.org/D125291



More information about the cfe-commits mailing list