[libc-commits] [libc] 9c8bdbc - [libc] Implement memory fences on NVPTX
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Thu Mar 23 09:26:43 PDT 2023
Author: Joseph Huber
Date: 2023-03-23T11:26:35-05:00
New Revision: 9c8bdbcbc502fac7d7d8da5c848cec448daf26ae
URL: https://github.com/llvm/llvm-project/commit/9c8bdbcbc502fac7d7d8da5c848cec448daf26ae
DIFF: https://github.com/llvm/llvm-project/commit/9c8bdbcbc502fac7d7d8da5c848cec448daf26ae.diff
LOG: [libc] Implement memory fences on NVPTX
Memory fences are not handled by the NVPTX backend. We need to replace
them with a memory barrier intrinsic function. This doesn't include the
ordering, but should perform the necessary functionality, albeit slower.
Reviewed By: tianshilei1992
Differential Revision: https://reviews.llvm.org/D146725
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 b0e90e32dadd..5514062525cc 100644
--- a/libc/src/__support/CPP/atomic.h
+++ b/libc/src/__support/CPP/atomic.h
@@ -10,6 +10,7 @@
#define LLVM_LIBC_SRC_SUPPORT_CPP_ATOMIC_H
#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/properties/architectures.h"
#include "type_traits.h"
@@ -96,7 +97,14 @@ template <typename T> struct Atomic {
// Issue a thread fence with the given memory ordering.
LIBC_INLINE void atomic_thread_fence(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
+ (void)mem_ord;
+ __nvvm_membar_sys();
+#else
__atomic_thread_fence(int(mem_ord));
+#endif
}
} // namespace cpp
More information about the libc-commits
mailing list