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

via libc-commits libc-commits at lists.llvm.org
Fri Dec 6 11:49:04 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Joseph Huber (jhuber6)

<details>
<summary>Changes</summary>

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


---
Full diff: https://github.com/llvm/llvm-project/pull/119018.diff


1 Files Affected:

- (modified) libc/src/__support/CPP/atomic.h (+7-6) 


``````````diff
diff --git a/libc/src/__support/CPP/atomic.h b/libc/src/__support/CPP/atomic.h
index c67e4e9b6f1cbc..b4b86fd511e248 100644
--- a/libc/src/__support/CPP/atomic.h
+++ b/libc/src/__support/CPP/atomic.h
@@ -214,13 +214,14 @@ 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)
+  return __scoped_atomic_thread_fence(static_cast<int>(mem_ord),
+                                      static_cast<int>(mem_scope));
 #else
-  __atomic_thread_fence(static_cast<int>(mem_ord));
+  return __atomic_thread_fence(static_cast<int>(mem_ord));
 #endif
 }
 

``````````

</details>


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


More information about the libc-commits mailing list