This is an archive of the discontinued LLVM Phabricator instance.

[libc] Add intrinsic for thread fence to the atomic support
ClosedPublic

Authored by jhuber6 on Mar 8 2023, 1:22 PM.

Details

Summary

This function mimics the std::atomic_thread_fence function from
<atomic>. This has no uses in source currently, but this will be used by
the proposed RPC client for the GPU mode support. There is varying
support for direct memory ordering for the GPU atomics on shared memory
resources. So the implementation will use relaxed atomics and explicit
memory fences.

Some additional work may need to be done to map this to NVPTX system
level fences.

Diff Detail

Event Timeline

jhuber6 created this revision.Mar 8 2023, 1:22 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 8 2023, 1:22 PM
jhuber6 requested review of this revision.Mar 8 2023, 1:22 PM
lntue added inline comments.Mar 8 2023, 7:26 PM
libc/src/__support/CPP/atomic.h
97

Do we need a guard to check if the builtin __atomic_thread_fence is available?

jhuber6 added inline comments.Mar 8 2023, 8:27 PM
libc/src/__support/CPP/atomic.h
97

We use all the other intrinsics above, so as long as it supports the same built-ins that GNU does it should be provided.
Also, should this function be noexcept or always_inline?

sivachandra added inline comments.Mar 8 2023, 8:36 PM
libc/src/__support/CPP/atomic.h
97

I am not really worried about the guard check because there is no alternative being proposed. But, this function should at the least use LIBC_INLINE. noexcept is optional as we build the libc with -fno-exceptions anyway.

jhuber6 updated this revision to Diff 503606.Mar 8 2023, 8:38 PM

inline -> LIBC_INLINE

I think libstdc++ uses always_inline

sivachandra accepted this revision.Mar 8 2023, 11:37 PM
This revision is now accepted and ready to land.Mar 8 2023, 11:37 PM
This revision was landed with ongoing or failed builds.Mar 9 2023, 4:37 AM
This revision was automatically updated to reflect the committed changes.