[libc-commits] [libc] 7ff8929 - [libc] Update fence to use scoped fence now that it's supported (#119018)

via libc-commits libc-commits at lists.llvm.org
Fri Dec 6 13:20:12 PST 2024


Author: Joseph Huber
Date: 2024-12-06T15:20:07-06:00
New Revision: 7ff89294b63f8f15c650fe314cff5c576978c489

URL: https://github.com/llvm/llvm-project/commit/7ff89294b63f8f15c650fe314cff5c576978c489
DIFF: https://github.com/llvm/llvm-project/commit/7ff89294b63f8f15c650fe314cff5c576978c489.diff

LOG: [libc] Update fence to use scoped fence now that it's supported (#119018)

Summary:
Adds support for scoped fences now that the NVPTX backend doesn't break
on them.

Added: 
    

Modified: 
    libc/src/__support/CPP/atomic.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/CPP/atomic.h b/libc/src/__support/CPP/atomic.h
index c67e4e9b6f1cbc..a9fc7e61610ccc 100644
--- a/libc/src/__support/CPP/atomic.h
+++ b/libc/src/__support/CPP/atomic.h
@@ -214,11 +214,12 @@ template <typename T> struct Atomic {
 };
 
 // Issue a thread fence with the given memory ordering.
-LIBC_INLINE void atomic_thread_fence([[maybe_unused]] MemoryOrder mem_ord) {
-// The NVPTX backend currently does not support atomic thread fences so we use a
-// full system fence instead.
-#ifdef LIBC_TARGET_ARCH_IS_NVPTX
-  __nvvm_membar_sys();
+LIBC_INLINE void atomic_thread_fence(
+    MemoryOrder mem_ord,
+    [[maybe_unused]] MemoryScope mem_scope = MemoryScope::DEVICE) {
+#if __has_builtin(__scoped_atomic_thread_fence)
+  __scoped_atomic_thread_fence(static_cast<int>(mem_ord),
+                               static_cast<int>(mem_scope));
 #else
   __atomic_thread_fence(static_cast<int>(mem_ord));
 #endif


        


More information about the libc-commits mailing list