[libclc] 8e9e922 - libclc: Fix missing overloads for atomic_fetch_add/sub (#188478)

via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 27 00:27:40 PDT 2026


Author: Matt Arsenault
Date: 2026-03-27T08:27:36+01:00
New Revision: 8e9e9228d45463ae52a9dde006b26fb921cd23ea

URL: https://github.com/llvm/llvm-project/commit/8e9e9228d45463ae52a9dde006b26fb921cd23ea
DIFF: https://github.com/llvm/llvm-project/commit/8e9e9228d45463ae52a9dde006b26fb921cd23ea.diff

LOG: libclc: Fix missing overloads for atomic_fetch_add/sub (#188478)

Added: 
    

Modified: 
    libclc/opencl/lib/generic/atomic/atomic_fetch_add.cl
    libclc/opencl/lib/generic/atomic/atomic_fetch_sub.cl

Removed: 
    


################################################################################
diff  --git a/libclc/opencl/lib/generic/atomic/atomic_fetch_add.cl b/libclc/opencl/lib/generic/atomic/atomic_fetch_add.cl
index ff2115f4c4b41..12b6f37b3fdf5 100644
--- a/libclc/opencl/lib/generic/atomic/atomic_fetch_add.cl
+++ b/libclc/opencl/lib/generic/atomic/atomic_fetch_add.cl
@@ -18,30 +18,87 @@
 #define __CLC_BODY "atomic_def.inc"
 #include "clc/math/gentype.inc"
 
-#if defined(__opencl_c_atomic_order_seq_cst) &&                                \
-    defined(__opencl_c_atomic_scope_device)
+// If the device address space is 64-bits, the data types atomic_intptr_t,
+// atomic_uintptr_t, atomic_size_t and atomic_ptr
diff _t are supported if the
+// cl_khr_int64_base_atomics and cl_khr_int64_extended_atomics extensions are
+// supported and have been enabled.
+#if __SIZEOF_POINTER__ < 8 || (defined(cl_khr_int64_base_atomics) &&           \
+                               defined(cl_khr_int64_extended_atomics))
 
-_CLC_OVERLOAD _CLC_DEF uintptr_t
+#if defined(__opencl_c_atomic_scope_device) &&                                 \
+    defined(__opencl_c_atomic_order_seq_cst)
+
+_CLC_DEF _CLC_OVERLOAD uintptr_t
 atomic_fetch_add(volatile __local atomic_uintptr_t *p, ptr
diff _t v) {
   return __scoped_atomic_fetch_add((volatile __local uintptr_t *)p, v,
                                    __ATOMIC_SEQ_CST, __MEMORY_SCOPE_DEVICE);
 }
 
-_CLC_OVERLOAD _CLC_DEF uintptr_t
+_CLC_DEF _CLC_OVERLOAD uintptr_t
 atomic_fetch_add(volatile __global atomic_uintptr_t *p, ptr
diff _t v) {
   return __scoped_atomic_fetch_add((volatile __global uintptr_t *)p, v,
                                    __ATOMIC_SEQ_CST, __MEMORY_SCOPE_DEVICE);
 }
 
 #if _CLC_GENERIC_AS_SUPPORTED
-
-_CLC_OVERLOAD _CLC_DEF uintptr_t atomic_fetch_add(volatile atomic_uintptr_t *p,
+_CLC_DEF _CLC_OVERLOAD uintptr_t atomic_fetch_add(volatile atomic_uintptr_t *p,
                                                   ptr
diff _t v) {
   return __scoped_atomic_fetch_add((volatile uintptr_t *)p, v, __ATOMIC_SEQ_CST,
                                    __MEMORY_SCOPE_DEVICE);
 }
+#endif // _CLC_GENERIC_AS_SUPPORTED
+#endif // defined(__opencl_c_atomic_scope_device) &&
+       // defined(__opencl_c_atomic_order_seq_cst)
+
+#ifdef __opencl_c_atomic_scope_device
+
+_CLC_DEF _CLC_OVERLOAD uintptr_t atomic_fetch_add(
+    volatile __local atomic_uintptr_t *p, ptr
diff _t v, memory_order order) {
+  return __scoped_atomic_fetch_add((volatile __local uintptr_t *)p, v, order,
+                                   __MEMORY_SCOPE_DEVICE);
+}
+
+_CLC_DEF _CLC_OVERLOAD uintptr_t atomic_fetch_add(
+    volatile __global atomic_uintptr_t *p, ptr
diff _t v, memory_order order) {
+  return __scoped_atomic_fetch_add((volatile __global uintptr_t *)p, v, order,
+                                   __MEMORY_SCOPE_DEVICE);
+}
+
+#if _CLC_GENERIC_AS_SUPPORTED
+_CLC_DEF _CLC_OVERLOAD uintptr_t atomic_fetch_add(volatile atomic_uintptr_t *p,
+                                                  ptr
diff _t v,
+                                                  memory_order order) {
+  return __scoped_atomic_fetch_add((volatile uintptr_t *)p, v, order,
+                                   __MEMORY_SCOPE_DEVICE);
+}
+#endif // _CLC_GENERIC_AS_SUPPORTED
+#endif // __opencl_c_atomic_scope_device
+
+_CLC_DEF _CLC_OVERLOAD uintptr_t
+atomic_fetch_add(volatile __local atomic_uintptr_t *p, ptr
diff _t v,
+                 memory_order order, memory_scope scope) {
+  return __scoped_atomic_fetch_add((volatile __local uintptr_t *)p, v, order,
+                                   __opencl_get_clang_memory_scope(scope));
+}
+
+_CLC_DEF _CLC_OVERLOAD uintptr_t
+atomic_fetch_add(volatile __global atomic_uintptr_t *p, ptr
diff _t v,
+                 memory_order order, memory_scope scope) {
+  return __scoped_atomic_fetch_add((volatile __global uintptr_t *)p, v, order,
+                                   __opencl_get_clang_memory_scope(scope));
+}
+
+#if _CLC_GENERIC_AS_SUPPORTED
+
+_CLC_DEF _CLC_OVERLOAD uintptr_t atomic_fetch_add(volatile atomic_uintptr_t *p,
+                                                  ptr
diff _t v,
+                                                  memory_order order,
+                                                  memory_scope scope) {
+  return __scoped_atomic_fetch_add((volatile uintptr_t *)p, v, order,
+                                   __opencl_get_clang_memory_scope(scope));
+}
 
 #endif // _CLC_GENERIC_AS_SUPPORTED
 
-#endif // defined(__opencl_c_atomic_order_seq_cst) &&
-       // defined(__opencl_c_atomic_scope_device)
+#endif // __SIZEOF_POINTER__ < 8 || (defined(cl_khr_int64_base_atomics) &&
+       // defined(cl_khr_int64_extended_atomics))

diff  --git a/libclc/opencl/lib/generic/atomic/atomic_fetch_sub.cl b/libclc/opencl/lib/generic/atomic/atomic_fetch_sub.cl
index 9740ff7c036db..6dfcdde207efc 100644
--- a/libclc/opencl/lib/generic/atomic/atomic_fetch_sub.cl
+++ b/libclc/opencl/lib/generic/atomic/atomic_fetch_sub.cl
@@ -18,30 +18,87 @@
 #define __CLC_BODY "atomic_def.inc"
 #include "clc/math/gentype.inc"
 
-#if defined(__opencl_c_atomic_order_seq_cst) &&                                \
-    defined(__opencl_c_atomic_scope_device)
+// If the device subress space is 64-bits, the data types atomic_intptr_t,
+// atomic_uintptr_t, atomic_size_t and atomic_ptr
diff _t are supported if the
+// cl_khr_int64_base_atomics and cl_khr_int64_extended_atomics extensions are
+// supported and have been enabled.
+#if __SIZEOF_POINTER__ < 8 || (defined(cl_khr_int64_base_atomics) &&           \
+                               defined(cl_khr_int64_extended_atomics))
 
-_CLC_OVERLOAD _CLC_DEF uintptr_t
+#if defined(__opencl_c_atomic_scope_device) &&                                 \
+    defined(__opencl_c_atomic_order_seq_cst)
+
+_CLC_DEF _CLC_OVERLOAD uintptr_t
 atomic_fetch_sub(volatile __local atomic_uintptr_t *p, ptr
diff _t v) {
   return __scoped_atomic_fetch_sub((volatile __local uintptr_t *)p, v,
                                    __ATOMIC_SEQ_CST, __MEMORY_SCOPE_DEVICE);
 }
 
-_CLC_OVERLOAD _CLC_DEF uintptr_t
+_CLC_DEF _CLC_OVERLOAD uintptr_t
 atomic_fetch_sub(volatile __global atomic_uintptr_t *p, ptr
diff _t v) {
   return __scoped_atomic_fetch_sub((volatile __global uintptr_t *)p, v,
                                    __ATOMIC_SEQ_CST, __MEMORY_SCOPE_DEVICE);
 }
 
 #if _CLC_GENERIC_AS_SUPPORTED
-
-_CLC_OVERLOAD _CLC_DEF uintptr_t atomic_fetch_sub(volatile atomic_uintptr_t *p,
+_CLC_DEF _CLC_OVERLOAD uintptr_t atomic_fetch_sub(volatile atomic_uintptr_t *p,
                                                   ptr
diff _t v) {
   return __scoped_atomic_fetch_sub((volatile uintptr_t *)p, v, __ATOMIC_SEQ_CST,
                                    __MEMORY_SCOPE_DEVICE);
 }
+#endif // _CLC_GENERIC_AS_SUPPORTED
+#endif // defined(__opencl_c_atomic_scope_device) &&
+       // defined(__opencl_c_atomic_order_seq_cst)
+
+#ifdef __opencl_c_atomic_scope_device
+
+_CLC_DEF _CLC_OVERLOAD uintptr_t atomic_fetch_sub(
+    volatile __local atomic_uintptr_t *p, ptr
diff _t v, memory_order order) {
+  return __scoped_atomic_fetch_sub((volatile __local uintptr_t *)p, v, order,
+                                   __MEMORY_SCOPE_DEVICE);
+}
+
+_CLC_DEF _CLC_OVERLOAD uintptr_t atomic_fetch_sub(
+    volatile __global atomic_uintptr_t *p, ptr
diff _t v, memory_order order) {
+  return __scoped_atomic_fetch_sub((volatile __global uintptr_t *)p, v, order,
+                                   __MEMORY_SCOPE_DEVICE);
+}
+
+#if _CLC_GENERIC_AS_SUPPORTED
+_CLC_DEF _CLC_OVERLOAD uintptr_t atomic_fetch_sub(volatile atomic_uintptr_t *p,
+                                                  ptr
diff _t v,
+                                                  memory_order order) {
+  return __scoped_atomic_fetch_sub((volatile uintptr_t *)p, v, order,
+                                   __MEMORY_SCOPE_DEVICE);
+}
+#endif // _CLC_GENERIC_AS_SUPPORTED
+#endif // __opencl_c_atomic_scope_device
+
+_CLC_DEF _CLC_OVERLOAD uintptr_t
+atomic_fetch_sub(volatile __local atomic_uintptr_t *p, ptr
diff _t v,
+                 memory_order order, memory_scope scope) {
+  return __scoped_atomic_fetch_sub((volatile __local uintptr_t *)p, v, order,
+                                   __opencl_get_clang_memory_scope(scope));
+}
+
+_CLC_DEF _CLC_OVERLOAD uintptr_t
+atomic_fetch_sub(volatile __global atomic_uintptr_t *p, ptr
diff _t v,
+                 memory_order order, memory_scope scope) {
+  return __scoped_atomic_fetch_sub((volatile __global uintptr_t *)p, v, order,
+                                   __opencl_get_clang_memory_scope(scope));
+}
+
+#if _CLC_GENERIC_AS_SUPPORTED
+
+_CLC_DEF _CLC_OVERLOAD uintptr_t atomic_fetch_sub(volatile atomic_uintptr_t *p,
+                                                  ptr
diff _t v,
+                                                  memory_order order,
+                                                  memory_scope scope) {
+  return __scoped_atomic_fetch_sub((volatile uintptr_t *)p, v, order,
+                                   __opencl_get_clang_memory_scope(scope));
+}
 
 #endif // _CLC_GENERIC_AS_SUPPORTED
 
-#endif // defined(__opencl_c_atomic_order_seq_cst) &&
-       // defined(__opencl_c_atomic_scope_device)
+#endif // __SIZEOF_POINTER__ < 8 || (defined(cl_khr_int64_base_atomics) &&
+       // defined(cl_khr_int64_extended_atomics))


        


More information about the cfe-commits mailing list