[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 11:48:29 PST 2024
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/119018
Summary:
Adds support for scoped fences now that the NVPTX backend doesn't break
on them.
>From 7d7cf74a8f7c46ec98ca6b9bc0e938b25ddb8ec5 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 | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
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
}
More information about the libc-commits
mailing list