[PATCH] D135628: [clang][codegen] Don't emit atomic loads for threadsafe init if they aren't inline

Eli Friedman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 10 15:49:50 PDT 2022


efriedma created this revision.
efriedma added reviewers: rjmccall, nikic.
Herald added a project: All.
efriedma requested review of this revision.
Herald added a project: clang.

Performing a load before calling __cxa_guard_acquire is supposed to be an optimization, but it isn't much of one if we're just going to emit a call to __atomic_load_1 instead.  Instead, just skip the load, and let __cxa_guard_acquire do whatever it wants.

(In practice, on such targets, the C++ library is just built with threading turned off, so the result isn't actually threadsafe, but there's not really anything clang can do about that.)

The alternative here is that we try to define some ABI for threadsafe init that allows the speculative load without full atomics.  Almost any target without full atomics has a load that's s "atomic enough" for this purpose. But it's not clear how we emit an "atomic enough" load in LLVM IR, and there isn't any ABI document we can refer to.

Or I guess we could turn off -fthreadsafe-statics by default on Cortex-M0, but that seems like it would be surprising.

Fixes https://github.com/llvm/llvm-project/issues/58184


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135628

Files:
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/threadsafe-statics-no-atomic.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135628.466652.patch
Type: text/x-patch
Size: 6225 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221010/46e501c0/attachment.bin>


More information about the cfe-commits mailing list