[libc-commits] [libc] [libc] Update fence to use scoped fence now that it's supported (PR #119018)
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Fri Dec 6 13:12:13 PST 2024
https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/119018
>From 9897b2210dad3652957280e3dc36b4d7e64cb9ec Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Fri, 6 Dec 2024 13:46:43 -0600
Subject: [PATCH] [libc] Update fence to use scoped fence now that it's
supported
Summary:
Adds support for scoped fences now that the NVPTX backend doesn't break
on them.
---
libc/src/__support/CPP/atomic.h | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
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