https://github.com/wenju-he created 
https://github.com/llvm/llvm-project/pull/168318

Implement atomic_*_explicit (e.g. atomic_store_explicit) with memory_order plus 
optional memory_scope.

OpenCL memory_order maps 1:1 to Clang (e.g. OpenCL memory_order_relaxed == 
Clang __ATOMIC_RELAXED), so we pass it unchanged to clc_atomic_* function which 
forwards to Clang _scoped_atomic* builtins.

Other changes:
* Add __opencl_get_clang_memory_scope helper in opencl/utils.h (OpenCL scope -> 
Clang scope).
* Correct atomic_compare_exchange return type to bool.
* Fix atomic_compare_exchange to return true when value stored in the pointer 
equals expected value.

>From 5965c4bd306c1a227188ea6eeb9c3d247e9ab2f3 Mon Sep 17 00:00:00 2001
From: Wenju He <[email protected]>
Date: Mon, 17 Nov 2025 06:52:38 +0100
Subject: [PATCH] [libclc] Add OpenCL atomic_*_explicit builtins

Implement atomic_*_explicit (e.g. atomic_store_explicit) with
memory_order plus optional memory_scope.

OpenCL memory_order maps 1:1 to Clang (e.g. OpenCL memory_order_relaxed
== Clang __ATOMIC_RELAXED), so we pass it unchanged to clc_atomic_*
function which forwards to Clang _scoped_atomic* builtins.

Other changes:
* Add __opencl_get_clang_memory_scope helper in opencl/utils.h
  (OpenCL scope -> Clang scope).
* Correct atomic_compare_exchange return type to bool.
* Fix atomic_compare_exchange to return true when value stored in the
  pointer equals expected value.
---
 .../atomic/atomic_compare_exchange_strong.h   |   3 +
 .../atomic/atomic_compare_exchange_weak.h     |   3 +
 .../include/clc/opencl/atomic/atomic_decl.inc |  91 ++++++++++--
 .../clc/opencl/atomic/atomic_exchange.h       |   3 +
 .../clc/opencl/atomic/atomic_fetch_add.h      |   3 +
 .../clc/opencl/atomic/atomic_fetch_and.h      |   3 +
 .../clc/opencl/atomic/atomic_fetch_max.h      |   3 +
 .../clc/opencl/atomic/atomic_fetch_min.h      |   3 +
 .../clc/opencl/atomic/atomic_fetch_or.h       |   3 +
 .../clc/opencl/atomic/atomic_fetch_sub.h      |   3 +
 .../clc/opencl/atomic/atomic_fetch_xor.h      |   3 +
 .../include/clc/opencl/atomic/atomic_load.h   |   3 +
 .../include/clc/opencl/atomic/atomic_store.h  |   3 +
 libclc/opencl/include/clc/opencl/types.h      |  48 +++++++
 libclc/opencl/include/clc/opencl/utils.h      |  33 +++++
 .../atomic/atomic_compare_exchange_strong.cl  |   7 +-
 .../atomic/atomic_compare_exchange_weak.cl    |   7 +-
 .../opencl/lib/generic/atomic/atomic_def.inc  | 131 +++++++++++++++---
 .../lib/generic/atomic/atomic_exchange.cl     |   7 +-
 .../lib/generic/atomic/atomic_fetch_add.cl    |   7 +-
 .../lib/generic/atomic/atomic_fetch_and.cl    |   7 +-
 .../lib/generic/atomic/atomic_fetch_max.cl    |   7 +-
 .../lib/generic/atomic/atomic_fetch_min.cl    |   7 +-
 .../lib/generic/atomic/atomic_fetch_or.cl     |   7 +-
 .../lib/generic/atomic/atomic_fetch_sub.cl    |   7 +-
 .../lib/generic/atomic/atomic_fetch_xor.cl    |   7 +-
 .../opencl/lib/generic/atomic/atomic_load.cl  |   7 +-
 .../opencl/lib/generic/atomic/atomic_store.cl |   7 +-
 28 files changed, 325 insertions(+), 98 deletions(-)
 create mode 100644 libclc/opencl/include/clc/opencl/types.h
 create mode 100644 libclc/opencl/include/clc/opencl/utils.h

diff --git 
a/libclc/opencl/include/clc/opencl/atomic/atomic_compare_exchange_strong.h 
b/libclc/opencl/include/clc/opencl/atomic/atomic_compare_exchange_strong.h
index 59bfa0e87dd8f..4870b13329e4f 100644
--- a/libclc/opencl/include/clc/opencl/atomic/atomic_compare_exchange_strong.h
+++ b/libclc/opencl/include/clc/opencl/atomic/atomic_compare_exchange_strong.h
@@ -9,6 +9,9 @@
 #ifndef __CLC_OPENCL_ATOMIC_ATOMIC_COMPARE_EXCHANGE_STRONG_H__
 #define __CLC_OPENCL_ATOMIC_ATOMIC_COMPARE_EXCHANGE_STRONG_H__
 
+#include <clc/opencl/opencl-base.h>
+#include <clc/opencl/types.h>
+
 #define __CLC_FUNCTION atomic_compare_exchange_strong
 #define __CLC_COMPARE_EXCHANGE
 
diff --git 
a/libclc/opencl/include/clc/opencl/atomic/atomic_compare_exchange_weak.h 
b/libclc/opencl/include/clc/opencl/atomic/atomic_compare_exchange_weak.h
index 7106c3e061d65..103d4f5504d71 100644
--- a/libclc/opencl/include/clc/opencl/atomic/atomic_compare_exchange_weak.h
+++ b/libclc/opencl/include/clc/opencl/atomic/atomic_compare_exchange_weak.h
@@ -9,6 +9,9 @@
 #ifndef __CLC_OPENCL_ATOMIC_ATOMIC_COMPARE_EXCHANGE_WEAK_H__
 #define __CLC_OPENCL_ATOMIC_ATOMIC_COMPARE_EXCHANGE_WEAK_H__
 
+#include <clc/opencl/opencl-base.h>
+#include <clc/opencl/types.h>
+
 #define __CLC_FUNCTION atomic_compare_exchange_weak
 #define __CLC_COMPARE_EXCHANGE
 
diff --git a/libclc/opencl/include/clc/opencl/atomic/atomic_decl.inc 
b/libclc/opencl/include/clc/opencl/atomic/atomic_decl.inc
index 38d250f0693f7..a36e68bca86a2 100644
--- a/libclc/opencl/include/clc/opencl/atomic/atomic_decl.inc
+++ b/libclc/opencl/include/clc/opencl/atomic/atomic_decl.inc
@@ -25,32 +25,105 @@
 
 #define __CLC_ATOMIC_GENTYPE __CLC_XCONCAT(atomic_, __CLC_GENTYPE)
 
+#define __CLC_FUNCTION_EXPLICIT __CLC_XCONCAT(__CLC_FUNCTION, _explicit)
+
+#ifdef __CLC_NO_VALUE_ARG
+#define __CLC_DECL_ATOMIC(ADDRSPACE)                                           
\
+  _CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION_EXPLICIT(               
\
+      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr, memory_order Order,        
\
+      memory_scope Scope);
+#elif defined(__CLC_RETURN_VOID)
+#define __CLC_DECL_ATOMIC(ADDRSPACE)                                           
\
+  _CLC_OVERLOAD _CLC_DECL void __CLC_FUNCTION_EXPLICIT(                        
\
+      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr, __CLC_GENTYPE Value,       
\
+      memory_order Order, memory_scope Scope);
+#elif defined(__CLC_COMPARE_EXCHANGE)
+#define __CLC_DECL_ATOMIC(ADDRSPACE)                                           
\
+  _CLC_OVERLOAD _CLC_DECL bool __CLC_FUNCTION_EXPLICIT(                        
\
+      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr,                            
\
+      ADDRSPACE __CLC_GENTYPE *Expected, __CLC_GENTYPE Desired,                
\
+      memory_order Order, memory_scope Scope);
+#else
+#define __CLC_DECL_ATOMIC(ADDRSPACE)                                           
\
+  _CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION_EXPLICIT(               
\
+      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr, __CLC_GENTYPE Value,       
\
+      memory_order Order, memory_scope Scope);
+#endif
+
+__CLC_DECL_ATOMIC(global)
+__CLC_DECL_ATOMIC(local)
+#if _CLC_GENERIC_AS_SUPPORTED
+__CLC_DECL_ATOMIC()
+#endif
+
+#undef __CLC_DECL_ATOMIC
+
+#if defined(__opencl_c_atomic_scope_device)
+
+#ifdef __CLC_NO_VALUE_ARG
+#define __CLC_DECL_ATOMIC(ADDRSPACE)                                           
\
+  _CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION_EXPLICIT(               
\
+      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr, memory_order Order);
+#elif defined(__CLC_RETURN_VOID)
+#define __CLC_DECL_ATOMIC(ADDRSPACE)                                           
\
+  _CLC_OVERLOAD _CLC_DECL void __CLC_FUNCTION_EXPLICIT(                        
\
+      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr, __CLC_GENTYPE Value,       
\
+      memory_order Order);
+#elif defined(__CLC_COMPARE_EXCHANGE)
+#define __CLC_DECL_ATOMIC(ADDRSPACE)                                           
\
+  _CLC_OVERLOAD _CLC_DECL bool __CLC_FUNCTION_EXPLICIT(                        
\
+      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr,                            
\
+      ADDRSPACE __CLC_GENTYPE *Expected, __CLC_GENTYPE Desired,                
\
+      memory_order Success, memory_order Failure);
+#else
+#define __CLC_DECL_ATOMIC(ADDRSPACE)                                           
\
+  _CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION_EXPLICIT(               
\
+      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr, __CLC_GENTYPE Value,       
\
+      memory_order Order);
+#endif
+
+__CLC_DECL_ATOMIC(global)
+__CLC_DECL_ATOMIC(local)
+#if _CLC_GENERIC_AS_SUPPORTED
+__CLC_DECL_ATOMIC()
+#endif
+
+#undef __CLC_DECL_ATOMIC
+
+#endif // defined(__opencl_c_atomic_scope_device)
+
+#if defined(__opencl_c_atomic_order_seq_cst) &&                                
\
+    defined(__opencl_c_atomic_scope_device)
+
 #ifdef __CLC_NO_VALUE_ARG
-#define __CLC_DEFINE_ATOMIC(ADDRSPACE)                                         
\
+#define __CLC_DECL_ATOMIC(ADDRSPACE)                                           
\
   _CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(                        
\
       volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr);
 #elif defined(__CLC_RETURN_VOID)
-#define __CLC_DEFINE_ATOMIC(ADDRSPACE)                                         
\
+#define __CLC_DECL_ATOMIC(ADDRSPACE)                                           
\
   _CLC_OVERLOAD _CLC_DECL void __CLC_FUNCTION(                                 
\
       volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr, __CLC_GENTYPE Value);
 #elif defined(__CLC_COMPARE_EXCHANGE)
-#define __CLC_DEFINE_ATOMIC(ADDRSPACE)                                         
\
-  _CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(                        
\
+#define __CLC_DECL_ATOMIC(ADDRSPACE)                                           
\
+  _CLC_OVERLOAD _CLC_DECL bool __CLC_FUNCTION(                                 
\
       volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr,                            
\
       ADDRSPACE __CLC_GENTYPE *Expected, __CLC_GENTYPE Desired);
 #else
-#define __CLC_DEFINE_ATOMIC(ADDRSPACE)                                         
\
+#define __CLC_DECL_ATOMIC(ADDRSPACE)                                           
\
   _CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(                        
\
       volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr, __CLC_GENTYPE Value);
 #endif
 
-__CLC_DEFINE_ATOMIC(global)
-__CLC_DEFINE_ATOMIC(local)
+__CLC_DECL_ATOMIC(global)
+__CLC_DECL_ATOMIC(local)
 #if _CLC_GENERIC_AS_SUPPORTED
-__CLC_DEFINE_ATOMIC()
+__CLC_DECL_ATOMIC()
 #endif
 
-#undef __CLC_DEFINE_ATOMIC
+#undef __CLC_DECL_ATOMIC
+
+#endif // defined(__opencl_c_atomic_order_seq_cst) &&
+       // defined(__opencl_c_atomic_scope_device)
 
 #endif // __CLC_HAVE_FP_ATOMIC || __CLC_HAVE_INT_ATOMIC
 
diff --git a/libclc/opencl/include/clc/opencl/atomic/atomic_exchange.h 
b/libclc/opencl/include/clc/opencl/atomic/atomic_exchange.h
index 9d949825b58c3..d47691b373eb0 100644
--- a/libclc/opencl/include/clc/opencl/atomic/atomic_exchange.h
+++ b/libclc/opencl/include/clc/opencl/atomic/atomic_exchange.h
@@ -9,6 +9,9 @@
 #ifndef __CLC_OPENCL_ATOMIC_ATOMIC_EXCHANGE_H__
 #define __CLC_OPENCL_ATOMIC_ATOMIC_EXCHANGE_H__
 
+#include <clc/opencl/opencl-base.h>
+#include <clc/opencl/types.h>
+
 #define __CLC_FUNCTION atomic_exchange
 
 #define __CLC_BODY <clc/opencl/atomic/atomic_decl.inc>
diff --git a/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_add.h 
b/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_add.h
index bae5a7a7e19bb..9ec29e1a553da 100644
--- a/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_add.h
+++ b/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_add.h
@@ -9,6 +9,9 @@
 #ifndef __CLC_OPENCL_ATOMIC_ATOMIC_FETCH_ADD_H__
 #define __CLC_OPENCL_ATOMIC_ATOMIC_FETCH_ADD_H__
 
+#include <clc/opencl/opencl-base.h>
+#include <clc/opencl/types.h>
+
 #define __CLC_FUNCTION atomic_fetch_add
 
 #define __CLC_BODY <clc/opencl/atomic/atomic_decl.inc>
diff --git a/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_and.h 
b/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_and.h
index 9f9d2225f910e..fb51102911228 100644
--- a/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_and.h
+++ b/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_and.h
@@ -9,6 +9,9 @@
 #ifndef __CLC_OPENCL_ATOMIC_ATOMIC_FETCH_AND_H__
 #define __CLC_OPENCL_ATOMIC_ATOMIC_FETCH_AND_H__
 
+#include <clc/opencl/opencl-base.h>
+#include <clc/opencl/types.h>
+
 #define __CLC_FUNCTION atomic_fetch_and
 
 #define __CLC_BODY <clc/opencl/atomic/atomic_decl.inc>
diff --git a/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_max.h 
b/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_max.h
index bef102dc82f48..8902e000a1024 100644
--- a/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_max.h
+++ b/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_max.h
@@ -9,6 +9,9 @@
 #ifndef __CLC_OPENCL_ATOMIC_ATOMIC_FETCH_MAX_H__
 #define __CLC_OPENCL_ATOMIC_ATOMIC_FETCH_MAX_H__
 
+#include <clc/opencl/opencl-base.h>
+#include <clc/opencl/types.h>
+
 #define __CLC_FUNCTION atomic_fetch_max
 
 #define __CLC_BODY <clc/opencl/atomic/atomic_decl.inc>
diff --git a/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_min.h 
b/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_min.h
index d7e346dc44368..0b79b5d9f9d18 100644
--- a/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_min.h
+++ b/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_min.h
@@ -9,6 +9,9 @@
 #ifndef __CLC_OPENCL_ATOMIC_ATOMIC_FETCH_MIN_H__
 #define __CLC_OPENCL_ATOMIC_ATOMIC_FETCH_MIN_H__
 
+#include <clc/opencl/opencl-base.h>
+#include <clc/opencl/types.h>
+
 #define __CLC_FUNCTION atomic_fetch_min
 
 #define __CLC_BODY <clc/opencl/atomic/atomic_decl.inc>
diff --git a/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_or.h 
b/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_or.h
index aa00982e15a56..5928e15cc3f53 100644
--- a/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_or.h
+++ b/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_or.h
@@ -9,6 +9,9 @@
 #ifndef __CLC_OPENCL_ATOMIC_ATOMIC_FETCH_OR_H__
 #define __CLC_OPENCL_ATOMIC_ATOMIC_FETCH_OR_H__
 
+#include <clc/opencl/opencl-base.h>
+#include <clc/opencl/types.h>
+
 #define __CLC_FUNCTION atomic_fetch_or
 
 #define __CLC_BODY <clc/opencl/atomic/atomic_decl.inc>
diff --git a/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_sub.h 
b/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_sub.h
index 3d04ed7ba34f8..76e519f933121 100644
--- a/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_sub.h
+++ b/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_sub.h
@@ -9,6 +9,9 @@
 #ifndef __CLC_OPENCL_ATOMIC_ATOMIC_FETCH_SUB_H__
 #define __CLC_OPENCL_ATOMIC_ATOMIC_FETCH_SUB_H__
 
+#include <clc/opencl/opencl-base.h>
+#include <clc/opencl/types.h>
+
 #define __CLC_FUNCTION atomic_fetch_sub
 
 #define __CLC_BODY <clc/opencl/atomic/atomic_decl.inc>
diff --git a/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_xor.h 
b/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_xor.h
index 2cdff08069025..c0befd44eae20 100644
--- a/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_xor.h
+++ b/libclc/opencl/include/clc/opencl/atomic/atomic_fetch_xor.h
@@ -9,6 +9,9 @@
 #ifndef __CLC_OPENCL_ATOMIC_ATOMIC_FETCH_XOR_H__
 #define __CLC_OPENCL_ATOMIC_ATOMIC_FETCH_XOR_H__
 
+#include <clc/opencl/opencl-base.h>
+#include <clc/opencl/types.h>
+
 #define __CLC_FUNCTION atomic_fetch_xor
 
 #define __CLC_BODY <clc/opencl/atomic/atomic_decl.inc>
diff --git a/libclc/opencl/include/clc/opencl/atomic/atomic_load.h 
b/libclc/opencl/include/clc/opencl/atomic/atomic_load.h
index 7db259b136ec8..1aaa26bdecc9e 100644
--- a/libclc/opencl/include/clc/opencl/atomic/atomic_load.h
+++ b/libclc/opencl/include/clc/opencl/atomic/atomic_load.h
@@ -9,6 +9,9 @@
 #ifndef __CLC_OPENCL_ATOMIC_ATOMIC_LOAD_H__
 #define __CLC_OPENCL_ATOMIC_ATOMIC_LOAD_H__
 
+#include <clc/opencl/opencl-base.h>
+#include <clc/opencl/types.h>
+
 #define __CLC_FUNCTION atomic_load
 #define __CLC_NO_VALUE_ARG
 
diff --git a/libclc/opencl/include/clc/opencl/atomic/atomic_store.h 
b/libclc/opencl/include/clc/opencl/atomic/atomic_store.h
index b3cdfc6ffaeae..f754314918f82 100644
--- a/libclc/opencl/include/clc/opencl/atomic/atomic_store.h
+++ b/libclc/opencl/include/clc/opencl/atomic/atomic_store.h
@@ -9,6 +9,9 @@
 #ifndef __CLC_OPENCL_ATOMIC_ATOMIC_STORE_H__
 #define __CLC_OPENCL_ATOMIC_ATOMIC_STORE_H__
 
+#include <clc/opencl/opencl-base.h>
+#include <clc/opencl/types.h>
+
 #define __CLC_FUNCTION atomic_store
 #define __CLC_RETURN_VOID
 
diff --git a/libclc/opencl/include/clc/opencl/types.h 
b/libclc/opencl/include/clc/opencl/types.h
new file mode 100644
index 0000000000000..b1be88f21bdaa
--- /dev/null
+++ b/libclc/opencl/include/clc/opencl/types.h
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __CLC_OPENCL_TYPES_H__
+#define __CLC_OPENCL_TYPES_H__
+
+// Copied from clang/lib/Headers/opencl-c-base.h
+
+typedef enum memory_scope {
+  memory_scope_work_item = __OPENCL_MEMORY_SCOPE_WORK_ITEM,
+  memory_scope_work_group = __OPENCL_MEMORY_SCOPE_WORK_GROUP,
+  memory_scope_device = __OPENCL_MEMORY_SCOPE_DEVICE,
+#if defined(__opencl_c_atomic_scope_all_devices)
+  memory_scope_all_svm_devices = __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES,
+#if (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 
202100)
+  memory_scope_all_devices = memory_scope_all_svm_devices,
+#endif // (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >=
+       // 202100)
+#endif // defined(__opencl_c_atomic_scope_all_devices)
+/**
+ * Subgroups have different requirements on forward progress, so just test
+ * all the relevant macros.
+ * CL 3.0 sub-groups "they are not guaranteed to make independent forward
+ * progress" KHR subgroups "Subgroups within a workgroup are independent, make
+ * forward progress with respect to each other"
+ */
+#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups) ||                
\
+    defined(__opencl_c_subgroups)
+  memory_scope_sub_group = __OPENCL_MEMORY_SCOPE_SUB_GROUP
+#endif
+} memory_scope;
+
+typedef enum memory_order {
+  memory_order_relaxed = __ATOMIC_RELAXED,
+  memory_order_acquire = __ATOMIC_ACQUIRE,
+  memory_order_release = __ATOMIC_RELEASE,
+  memory_order_acq_rel = __ATOMIC_ACQ_REL,
+#if defined(__opencl_c_atomic_order_seq_cst)
+  memory_order_seq_cst = __ATOMIC_SEQ_CST
+#endif
+} memory_order;
+
+#endif // __CLC_OPENCL_TYPES_H__
diff --git a/libclc/opencl/include/clc/opencl/utils.h 
b/libclc/opencl/include/clc/opencl/utils.h
new file mode 100644
index 0000000000000..c677f82ebb67d
--- /dev/null
+++ b/libclc/opencl/include/clc/opencl/utils.h
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __CLC_OPENCL_UTILS_H__
+#define __CLC_OPENCL_UTILS_H__
+
+#include <clc/internal/clc.h>
+#include <clc/opencl/types.h>
+
+static _CLC_INLINE int __opencl_get_clang_memory_scope(memory_scope scope) {
+  switch (scope) {
+  case __OPENCL_MEMORY_SCOPE_WORK_ITEM:
+    return __MEMORY_SCOPE_SINGLE;
+#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups) ||                
\
+    defined(__opencl_c_subgroups)
+  case __OPENCL_MEMORY_SCOPE_SUB_GROUP:
+    return __MEMORY_SCOPE_WVFRNT;
+#endif
+  case __OPENCL_MEMORY_SCOPE_WORK_GROUP:
+    return __MEMORY_SCOPE_WRKGRP;
+  case __OPENCL_MEMORY_SCOPE_DEVICE:
+    return __MEMORY_SCOPE_DEVICE;
+  default:
+    return __MEMORY_SCOPE_SYSTEM;
+  }
+}
+
+#endif // __CLC_OPENCL_UTILS_H__
diff --git a/libclc/opencl/lib/generic/atomic/atomic_compare_exchange_strong.cl 
b/libclc/opencl/lib/generic/atomic/atomic_compare_exchange_strong.cl
index 2c1f07d8ca485..c0ca3f8f7d332 100644
--- a/libclc/opencl/lib/generic/atomic/atomic_compare_exchange_strong.cl
+++ b/libclc/opencl/lib/generic/atomic/atomic_compare_exchange_strong.cl
@@ -6,11 +6,9 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#if defined(__opencl_c_atomic_order_seq_cst) &&                                
\
-    defined(__opencl_c_atomic_scope_device)
-
 #include <clc/atomic/clc_atomic_compare_exchange.h>
 #include <clc/opencl/atomic/atomic_compare_exchange_strong.h>
+#include <clc/opencl/utils.h>
 
 #define __CLC_FUNCTION atomic_compare_exchange_strong
 #define __CLC_COMPARE_EXCHANGE
@@ -20,6 +18,3 @@
 
 #define __CLC_BODY <atomic_def.inc>
 #include <clc/math/gentype.inc>
-
-#endif // defined(__opencl_c_atomic_order_seq_cst) &&
-       // defined(__opencl_c_atomic_scope_device)
diff --git a/libclc/opencl/lib/generic/atomic/atomic_compare_exchange_weak.cl 
b/libclc/opencl/lib/generic/atomic/atomic_compare_exchange_weak.cl
index 69bdf37250f70..39768fb345714 100644
--- a/libclc/opencl/lib/generic/atomic/atomic_compare_exchange_weak.cl
+++ b/libclc/opencl/lib/generic/atomic/atomic_compare_exchange_weak.cl
@@ -6,11 +6,9 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#if defined(__opencl_c_atomic_order_seq_cst) &&                                
\
-    defined(__opencl_c_atomic_scope_device)
-
 #include <clc/atomic/clc_atomic_compare_exchange.h>
 #include <clc/opencl/atomic/atomic_compare_exchange_weak.h>
+#include <clc/opencl/utils.h>
 
 #define __CLC_FUNCTION atomic_compare_exchange_weak
 #define __CLC_COMPARE_EXCHANGE
@@ -20,6 +18,3 @@
 
 #define __CLC_BODY <atomic_def.inc>
 #include <clc/math/gentype.inc>
-
-#endif // defined(__opencl_c_atomic_order_seq_cst) &&
-       // defined(__opencl_c_atomic_scope_device)
diff --git a/libclc/opencl/lib/generic/atomic/atomic_def.inc 
b/libclc/opencl/lib/generic/atomic/atomic_def.inc
index a4ccab5990888..99fb778a8b342 100644
--- a/libclc/opencl/lib/generic/atomic/atomic_def.inc
+++ b/libclc/opencl/lib/generic/atomic/atomic_def.inc
@@ -12,7 +12,8 @@
                                  defined(cl_khr_int64_extended_atomics))
 #define __CLC_HAVE_64_ATOMIC
 #endif
-#if defined(__CLC_FPSIZE) && (__CLC_FPSIZE < 64 || 
defined(__CLC_HAVE_64_ATOMIC)
+#if defined(__CLC_FPSIZE) &&                                                   
\
+    (__CLC_FPSIZE < 64 || defined(__CLC_HAVE_64_ATOMIC))
 #define __CLC_HAVE_FP_ATOMIC
 #endif
 #if defined(__CLC_GENSIZE) &&                                                  
\
@@ -24,41 +25,134 @@
 
 #define __CLC_ATOMIC_GENTYPE __CLC_XCONCAT(atomic_, __CLC_GENTYPE)
 
+#define __CLC_FUNCTION_EXPLICIT __CLC_XCONCAT(__CLC_FUNCTION, _explicit)
+
 #ifdef __CLC_NO_VALUE_ARG
 #define __CLC_DEFINE_ATOMIC(ADDRSPACE)                                         
\
-  _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNCTION(                         
\
-      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr) {                          
\
-    return __CLC_IMPL_FUNCTION((volatile ADDRSPACE __CLC_GENTYPE *)Ptr,        
\
-                               __ATOMIC_SEQ_CST, __MEMORY_SCOPE_DEVICE);       
\
+  _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNCTION_EXPLICIT(                
\
+      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr, memory_order Order,        
\
+      memory_scope Scope) {                                                    
\
+    return __CLC_IMPL_FUNCTION((volatile ADDRSPACE __CLC_GENTYPE *)Ptr, Order, 
\
+                               __opencl_get_clang_memory_scope(Scope));        
\
   }
 #elif defined(__CLC_RETURN_VOID)
 #define __CLC_DEFINE_ATOMIC(ADDRSPACE)                                         
\
-  _CLC_OVERLOAD _CLC_DEF void __CLC_FUNCTION(                                  
\
-      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr, __CLC_GENTYPE Value) {     
\
-    __CLC_IMPL_FUNCTION((volatile ADDRSPACE __CLC_GENTYPE *)Ptr, Value,        
\
-                        __ATOMIC_SEQ_CST, __MEMORY_SCOPE_DEVICE);              
\
+  _CLC_OVERLOAD _CLC_DEF void __CLC_FUNCTION_EXPLICIT(                         
\
+      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr, __CLC_GENTYPE Value,       
\
+      memory_order Order, memory_scope Scope) {                                
\
+    __CLC_IMPL_FUNCTION((volatile ADDRSPACE __CLC_GENTYPE *)Ptr, Value, Order, 
\
+                        __opencl_get_clang_memory_scope(Scope));               
\
   }
 #elif defined(__CLC_COMPARE_EXCHANGE)
 #define __CLC_DEFINE_ATOMIC(ADDRSPACE)                                         
\
-  _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNCTION(                         
\
+  _CLC_OVERLOAD _CLC_DEF bool __CLC_FUNCTION_EXPLICIT(                         
\
       volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr,                            
\
-      ADDRSPACE __CLC_GENTYPE *Expected, __CLC_GENTYPE Desired) {              
\
+      ADDRSPACE __CLC_GENTYPE *Expected, __CLC_GENTYPE Desired,                
\
+      memory_order Success, memory_order Failure, memory_scope Scope) {        
\
     __CLC_GENTYPE Comparator = *Expected;                                      
\
     __CLC_GENTYPE RetValue = __clc_atomic_compare_exchange(                    
\
-        (volatile ADDRSPACE __CLC_GENTYPE *)Ptr, Comparator, Desired,          
\
-        __ATOMIC_SEQ_CST, __ATOMIC_RELAXED, __MEMORY_SCOPE_DEVICE);            
\
+        (volatile ADDRSPACE __CLC_GENTYPE *)Ptr, Comparator, Desired, Success, 
\
+        Failure, __opencl_get_clang_memory_scope(Scope));                      
\
     if (Comparator != RetValue) {                                              
\
       *Expected = RetValue;                                                    
\
-      return true;                                                             
\
+      return false;                                                            
\
     }                                                                          
\
-    return false;                                                              
\
+    return true;                                                               
\
+  }
+#else
+#define __CLC_DEFINE_ATOMIC(ADDRSPACE)                                         
\
+  _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNCTION_EXPLICIT(                
\
+      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr, __CLC_GENTYPE Value,       
\
+      memory_order Order, memory_scope Scope) {                                
\
+    return __CLC_IMPL_FUNCTION((volatile ADDRSPACE __CLC_GENTYPE *)Ptr, Value, 
\
+                               Order, __opencl_get_clang_memory_scope(Scope)); 
\
+  }
+#endif
+
+__CLC_DEFINE_ATOMIC(global)
+__CLC_DEFINE_ATOMIC(local)
+#if _CLC_GENERIC_AS_SUPPORTED
+__CLC_DEFINE_ATOMIC()
+#endif
+
+#undef __CLC_DEFINE_ATOMIC
+
+#if defined(__opencl_c_atomic_scope_device)
+
+#ifdef __CLC_NO_VALUE_ARG
+#define __CLC_DEFINE_ATOMIC(ADDRSPACE)                                         
\
+  _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNCTION_EXPLICIT(                
\
+      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr, memory_order Order) {      
\
+    return __CLC_FUNCTION_EXPLICIT(Ptr, Order, __OPENCL_MEMORY_SCOPE_DEVICE);  
\
+  }
+#elif defined(__CLC_RETURN_VOID)
+#define __CLC_DEFINE_ATOMIC(ADDRSPACE)                                         
\
+  _CLC_OVERLOAD _CLC_DEF void __CLC_FUNCTION_EXPLICIT(                         
\
+      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr, __CLC_GENTYPE Value,       
\
+      memory_order Order) {                                                    
\
+    __CLC_FUNCTION_EXPLICIT(Ptr, Value, Order, __OPENCL_MEMORY_SCOPE_DEVICE);  
\
+  }
+#elif defined(__CLC_COMPARE_EXCHANGE)
+#define __CLC_DEFINE_ATOMIC(ADDRSPACE)                                         
\
+  _CLC_OVERLOAD _CLC_DEF bool __CLC_FUNCTION_EXPLICIT(                         
\
+      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr,                            
\
+      ADDRSPACE __CLC_GENTYPE *Expected, __CLC_GENTYPE Desired,                
\
+      memory_order Success, memory_order Failure) {                            
\
+    return __CLC_FUNCTION_EXPLICIT(Ptr, Expected, Desired, Success, Failure,   
\
+                                   __OPENCL_MEMORY_SCOPE_DEVICE);              
\
+  }
+#else
+#define __CLC_DEFINE_ATOMIC(ADDRSPACE)                                         
\
+  _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNCTION_EXPLICIT(                
\
+      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr, __CLC_GENTYPE Value,       
\
+      memory_order Order) {                                                    
\
+    return __CLC_FUNCTION_EXPLICIT(Ptr, Value, Order,                          
\
+                                   __OPENCL_MEMORY_SCOPE_DEVICE);              
\
+  }
+#endif
+
+__CLC_DEFINE_ATOMIC(global)
+__CLC_DEFINE_ATOMIC(local)
+#if _CLC_GENERIC_AS_SUPPORTED
+__CLC_DEFINE_ATOMIC()
+#endif
+
+#undef __CLC_DEFINE_ATOMIC
+
+#endif // defined(__opencl_c_atomic_scope_device)
+
+#if defined(__opencl_c_atomic_order_seq_cst) &&                                
\
+    defined(__opencl_c_atomic_scope_device)
+
+#ifdef __CLC_NO_VALUE_ARG
+#define __CLC_DEFINE_ATOMIC(ADDRSPACE)                                         
\
+  _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNCTION(                         
\
+      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr) {                          
\
+    return __CLC_FUNCTION_EXPLICIT(Ptr, __ATOMIC_SEQ_CST,                      
\
+                                   __OPENCL_MEMORY_SCOPE_DEVICE);              
\
+  }
+#elif defined(__CLC_RETURN_VOID)
+#define __CLC_DEFINE_ATOMIC(ADDRSPACE)                                         
\
+  _CLC_OVERLOAD _CLC_DEF void __CLC_FUNCTION(                                  
\
+      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr, __CLC_GENTYPE Value) {     
\
+    __CLC_FUNCTION_EXPLICIT(Ptr, Value, __ATOMIC_SEQ_CST,                      
\
+                            __OPENCL_MEMORY_SCOPE_DEVICE);                     
\
+  }
+#elif defined(__CLC_COMPARE_EXCHANGE)
+#define __CLC_DEFINE_ATOMIC(ADDRSPACE)                                         
\
+  _CLC_OVERLOAD _CLC_DEF bool __CLC_FUNCTION(                                  
\
+      volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr,                            
\
+      ADDRSPACE __CLC_GENTYPE *Expected, __CLC_GENTYPE Desired) {              
\
+    return __CLC_FUNCTION_EXPLICIT(Ptr, Expected, Desired, __ATOMIC_SEQ_CST,   
\
+                                   __ATOMIC_SEQ_CST,                           
\
+                                   __OPENCL_MEMORY_SCOPE_DEVICE);              
\
   }
 #else
 #define __CLC_DEFINE_ATOMIC(ADDRSPACE)                                         
\
   _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNCTION(                         
\
       volatile ADDRSPACE __CLC_ATOMIC_GENTYPE *Ptr, __CLC_GENTYPE Value) {     
\
-    return __CLC_IMPL_FUNCTION((volatile ADDRSPACE __CLC_GENTYPE *)Ptr, Value, 
\
-                               __ATOMIC_SEQ_CST, __MEMORY_SCOPE_DEVICE);       
\
+    return __CLC_FUNCTION_EXPLICIT(Ptr, Value, __ATOMIC_SEQ_CST,               
\
+                                   __OPENCL_MEMORY_SCOPE_DEVICE);              
\
   }
 #endif
 
@@ -70,6 +164,9 @@ __CLC_DEFINE_ATOMIC()
 
 #undef __CLC_DEFINE_ATOMIC
 
+#endif // defined(__opencl_c_atomic_order_seq_cst) &&
+       // defined(__opencl_c_atomic_scope_device)
+
 #endif // __CLC_HAVE_FP_ATOMIC || __CLC_HAVE_INT_ATOMIC
 
 #undef __CLC_HAVE_INT_ATOMIC
diff --git a/libclc/opencl/lib/generic/atomic/atomic_exchange.cl 
b/libclc/opencl/lib/generic/atomic/atomic_exchange.cl
index 5f7e2fa593e3f..f7568f6ace38c 100644
--- a/libclc/opencl/lib/generic/atomic/atomic_exchange.cl
+++ b/libclc/opencl/lib/generic/atomic/atomic_exchange.cl
@@ -6,11 +6,9 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#if defined(__opencl_c_atomic_order_seq_cst) &&                                
\
-    defined(__opencl_c_atomic_scope_device)
-
 #include <clc/atomic/clc_atomic_exchange.h>
 #include <clc/opencl/atomic/atomic_exchange.h>
+#include <clc/opencl/utils.h>
 
 #define __CLC_FUNCTION atomic_exchange
 #define __CLC_IMPL_FUNCTION __clc_atomic_exchange
@@ -20,6 +18,3 @@
 
 #define __CLC_BODY <atomic_def.inc>
 #include <clc/math/gentype.inc>
-
-#endif // defined(__opencl_c_atomic_order_seq_cst) &&
-       // defined(__opencl_c_atomic_scope_device)
diff --git a/libclc/opencl/lib/generic/atomic/atomic_fetch_add.cl 
b/libclc/opencl/lib/generic/atomic/atomic_fetch_add.cl
index 0362ff89d1d78..d27cc7120ccce 100644
--- a/libclc/opencl/lib/generic/atomic/atomic_fetch_add.cl
+++ b/libclc/opencl/lib/generic/atomic/atomic_fetch_add.cl
@@ -6,11 +6,9 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#if defined(__opencl_c_atomic_order_seq_cst) &&                                
\
-    defined(__opencl_c_atomic_scope_device)
-
 #include <clc/atomic/clc_atomic_fetch_add.h>
 #include <clc/opencl/atomic/atomic_fetch_add.h>
+#include <clc/opencl/utils.h>
 
 #define __CLC_FUNCTION atomic_fetch_add
 #define __CLC_IMPL_FUNCTION __clc_atomic_fetch_add
@@ -20,6 +18,3 @@
 
 #define __CLC_BODY <atomic_def.inc>
 #include <clc/math/gentype.inc>
-
-#endif // defined(__opencl_c_atomic_order_seq_cst) &&
-       // defined(__opencl_c_atomic_scope_device)
diff --git a/libclc/opencl/lib/generic/atomic/atomic_fetch_and.cl 
b/libclc/opencl/lib/generic/atomic/atomic_fetch_and.cl
index a1796f20c6e44..b8531722911cf 100644
--- a/libclc/opencl/lib/generic/atomic/atomic_fetch_and.cl
+++ b/libclc/opencl/lib/generic/atomic/atomic_fetch_and.cl
@@ -6,17 +6,12 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#if defined(__opencl_c_atomic_order_seq_cst) &&                                
\
-    defined(__opencl_c_atomic_scope_device)
-
 #include <clc/atomic/clc_atomic_fetch_and.h>
 #include <clc/opencl/atomic/atomic_fetch_and.h>
+#include <clc/opencl/utils.h>
 
 #define __CLC_FUNCTION atomic_fetch_and
 #define __CLC_IMPL_FUNCTION __clc_atomic_fetch_and
 
 #define __CLC_BODY <atomic_def.inc>
 #include <clc/integer/gentype.inc>
-
-#endif // defined(__opencl_c_atomic_order_seq_cst) &&
-       // defined(__opencl_c_atomic_scope_device)
diff --git a/libclc/opencl/lib/generic/atomic/atomic_fetch_max.cl 
b/libclc/opencl/lib/generic/atomic/atomic_fetch_max.cl
index 03b5d1d8ae7bd..b644ca336437a 100644
--- a/libclc/opencl/lib/generic/atomic/atomic_fetch_max.cl
+++ b/libclc/opencl/lib/generic/atomic/atomic_fetch_max.cl
@@ -6,11 +6,9 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#if defined(__opencl_c_atomic_order_seq_cst) &&                                
\
-    defined(__opencl_c_atomic_scope_device)
-
 #include <clc/atomic/clc_atomic_fetch_max.h>
 #include <clc/opencl/atomic/atomic_fetch_max.h>
+#include <clc/opencl/utils.h>
 
 #define __CLC_FUNCTION atomic_fetch_max
 #define __CLC_IMPL_FUNCTION __clc_atomic_fetch_max
@@ -20,6 +18,3 @@
 
 #define __CLC_BODY <atomic_def.inc>
 #include <clc/math/gentype.inc>
-
-#endif // defined(__opencl_c_atomic_order_seq_cst) &&
-       // defined(__opencl_c_atomic_scope_device)
diff --git a/libclc/opencl/lib/generic/atomic/atomic_fetch_min.cl 
b/libclc/opencl/lib/generic/atomic/atomic_fetch_min.cl
index 60ffeff04cc6a..f24fcf329b6f2 100644
--- a/libclc/opencl/lib/generic/atomic/atomic_fetch_min.cl
+++ b/libclc/opencl/lib/generic/atomic/atomic_fetch_min.cl
@@ -6,11 +6,9 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#if defined(__opencl_c_atomic_order_seq_cst) &&                                
\
-    defined(__opencl_c_atomic_scope_device)
-
 #include <clc/atomic/clc_atomic_fetch_min.h>
 #include <clc/opencl/atomic/atomic_fetch_min.h>
+#include <clc/opencl/utils.h>
 
 #define __CLC_FUNCTION atomic_fetch_min
 #define __CLC_IMPL_FUNCTION __clc_atomic_fetch_min
@@ -20,6 +18,3 @@
 
 #define __CLC_BODY <atomic_def.inc>
 #include <clc/math/gentype.inc>
-
-#endif // defined(__opencl_c_atomic_order_seq_cst) &&
-       // defined(__opencl_c_atomic_scope_device)
diff --git a/libclc/opencl/lib/generic/atomic/atomic_fetch_or.cl 
b/libclc/opencl/lib/generic/atomic/atomic_fetch_or.cl
index 8f4100bb150e3..1f6fe4cac090a 100644
--- a/libclc/opencl/lib/generic/atomic/atomic_fetch_or.cl
+++ b/libclc/opencl/lib/generic/atomic/atomic_fetch_or.cl
@@ -6,17 +6,12 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#if defined(__opencl_c_atomic_order_seq_cst) &&                                
\
-    defined(__opencl_c_atomic_scope_device)
-
 #include <clc/atomic/clc_atomic_fetch_or.h>
 #include <clc/opencl/atomic/atomic_fetch_or.h>
+#include <clc/opencl/utils.h>
 
 #define __CLC_FUNCTION atomic_fetch_or
 #define __CLC_IMPL_FUNCTION __clc_atomic_fetch_or
 
 #define __CLC_BODY <atomic_def.inc>
 #include <clc/integer/gentype.inc>
-
-#endif // defined(__opencl_c_atomic_order_seq_cst) &&
-       // defined(__opencl_c_atomic_scope_device)
diff --git a/libclc/opencl/lib/generic/atomic/atomic_fetch_sub.cl 
b/libclc/opencl/lib/generic/atomic/atomic_fetch_sub.cl
index ecb5b4315ee86..94323a2c0fcb6 100644
--- a/libclc/opencl/lib/generic/atomic/atomic_fetch_sub.cl
+++ b/libclc/opencl/lib/generic/atomic/atomic_fetch_sub.cl
@@ -6,11 +6,9 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#if defined(__opencl_c_atomic_order_seq_cst) &&                                
\
-    defined(__opencl_c_atomic_scope_device)
-
 #include <clc/atomic/clc_atomic_fetch_sub.h>
 #include <clc/opencl/atomic/atomic_fetch_sub.h>
+#include <clc/opencl/utils.h>
 
 #define __CLC_FUNCTION atomic_fetch_sub
 #define __CLC_IMPL_FUNCTION __clc_atomic_fetch_sub
@@ -20,6 +18,3 @@
 
 #define __CLC_BODY <atomic_def.inc>
 #include <clc/math/gentype.inc>
-
-#endif // defined(__opencl_c_atomic_order_seq_cst) &&
-       // defined(__opencl_c_atomic_scope_device)
diff --git a/libclc/opencl/lib/generic/atomic/atomic_fetch_xor.cl 
b/libclc/opencl/lib/generic/atomic/atomic_fetch_xor.cl
index c49a55820c8d4..13e1db1124f9a 100644
--- a/libclc/opencl/lib/generic/atomic/atomic_fetch_xor.cl
+++ b/libclc/opencl/lib/generic/atomic/atomic_fetch_xor.cl
@@ -6,17 +6,12 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#if defined(__opencl_c_atomic_order_seq_cst) &&                                
\
-    defined(__opencl_c_atomic_scope_device)
-
 #include <clc/atomic/clc_atomic_fetch_xor.h>
 #include <clc/opencl/atomic/atomic_fetch_xor.h>
+#include <clc/opencl/utils.h>
 
 #define __CLC_FUNCTION atomic_fetch_xor
 #define __CLC_IMPL_FUNCTION __clc_atomic_fetch_xor
 
 #define __CLC_BODY <atomic_def.inc>
 #include <clc/integer/gentype.inc>
-
-#endif // defined(__opencl_c_atomic_order_seq_cst) &&
-       // defined(__opencl_c_atomic_scope_device)
diff --git a/libclc/opencl/lib/generic/atomic/atomic_load.cl 
b/libclc/opencl/lib/generic/atomic/atomic_load.cl
index e904330be0064..1b93ce84ea863 100644
--- a/libclc/opencl/lib/generic/atomic/atomic_load.cl
+++ b/libclc/opencl/lib/generic/atomic/atomic_load.cl
@@ -6,11 +6,9 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#if defined(__opencl_c_atomic_order_seq_cst) &&                                
\
-    defined(__opencl_c_atomic_scope_device)
-
 #include <clc/atomic/clc_atomic_load.h>
 #include <clc/opencl/atomic/atomic_load.h>
+#include <clc/opencl/utils.h>
 
 #define __CLC_FUNCTION atomic_load
 #define __CLC_IMPL_FUNCTION __clc_atomic_load
@@ -21,6 +19,3 @@
 
 #define __CLC_BODY <atomic_def.inc>
 #include <clc/math/gentype.inc>
-
-#endif // defined(__opencl_c_atomic_order_seq_cst) &&
-       // defined(__opencl_c_atomic_scope_device)
diff --git a/libclc/opencl/lib/generic/atomic/atomic_store.cl 
b/libclc/opencl/lib/generic/atomic/atomic_store.cl
index 584e29ef99a5f..fcaa4d3128f7d 100644
--- a/libclc/opencl/lib/generic/atomic/atomic_store.cl
+++ b/libclc/opencl/lib/generic/atomic/atomic_store.cl
@@ -6,11 +6,9 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#if defined(__opencl_c_atomic_order_seq_cst) &&                                
\
-    defined(__opencl_c_atomic_scope_device)
-
 #include <clc/atomic/clc_atomic_store.h>
 #include <clc/opencl/atomic/atomic_store.h>
+#include <clc/opencl/utils.h>
 
 #define __CLC_FUNCTION atomic_store
 #define __CLC_IMPL_FUNCTION __clc_atomic_store
@@ -21,6 +19,3 @@
 
 #define __CLC_BODY <atomic_def.inc>
 #include <clc/math/gentype.inc>
-
-#endif // defined(__opencl_c_atomic_order_seq_cst) &&
-       // defined(__opencl_c_atomic_scope_device)

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to