[libclc] [libclc] Add generic implementation of some atomic functions in OpenCL spec section 6.15.12.7 (PR #146814)

Wenju He via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 10 20:04:25 PDT 2025


================
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_ATOMIC_ATOMIC_COMPARE_EXCHANGE_STRONG_H__
+#define __CLC_OPENCL_ATOMIC_ATOMIC_COMPARE_EXCHANGE_STRONG_H__
+
+#define FUNCTION atomic_compare_exchange_strong
----------------
wenju-he wrote:

> We should probably be only declaring/defining these OpenCL builtins according to the appropriate language features. For instance, for `atomic_compare_exchange_strong` we have:
> 
> ```c
> // Requires OpenCL C 3.0 or newer and both the __opencl_c_atomic_order_seq_cst
> // and __opencl_c_atomic_scope_device features.
> ```
> 
> The CLC functions are probably fine and we can unconditionally include them, for simplicity. But I feel we should be adhering to the spec for OpenCL builtins.

thanks @frasercrmck, done in https://github.com/llvm/llvm-project/pull/146814/commits/01866e742d694e8119705ed8446530d18c3d761f for all new built-ins introduced in this PR.

I also changed __MEMORY_SCOPE_SYSTEM to __MEMORY_SCOPE_DEVICE since these new built-ins requires __opencl_c_atomic_scope_device definition.


https://github.com/llvm/llvm-project/pull/146814


More information about the cfe-commits mailing list