[clang] [Clang] Introduce scoped variants of GNU atomic functions (PR #72280)

Joseph Huber via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 30 12:31:45 PST 2023


jhuber6 wrote:

> My primary concerns here are:
> 
>     * It being likely these builtins will be superseded by something else once someone else tries to standardize this.  Maybe this isn't a big deal... but maybe we want to choose names that are less likely to overlap with stuff anyone else is doing.
>
Technically these are "standardized" in the case of OpenCL. The problem is that the underlying concept is much broader so we'd need something that covers all use-cases in a familiar manner. IMHO this is probably as close as we'll get since all we're doing is expanding the already existing GCC intrinsics, which are well defined and understood. The thing which may change is simply the names we call them, or whatever mapping of integer to behavior we expect. I think that's fairly easy enough to change even in the future.
>     * We should try to avoid new preprocessor macros if possible; these are going to get unconditionally injected into every translation unit anyone ever builds with clang in any language mode, so we want to try to avoid extending the number of macros we define where possible.

My first thought was to make these an overloaded version of the GCC intrinsics, but there was apparently some resistance to that, as it made a bit more of an implied divergence between source codes or something. We'd still need the memory scopes however. That being said, we already do this for HIP and OpenCL, so if we can rewrite those in terms of this it would be a net reduction in preprocessor macros.
> 
> That said, I don't want to block progress here; this is clearly important functionality to have.

Yeah, my main use-case is for use inside my `gpu` libc project as well as the OpenMP device runtime. We have several places we'd like to use more efficient atomic scopes, and encourage them to be fully implemented in NVPTX, but right now there's no good cross-target way to do it.

https://github.com/llvm/llvm-project/pull/72280


More information about the cfe-commits mailing list