[clang] [clang][SYCL] Implement address space attributes for SYCL (PR #200849)

Tom Honermann via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 15 15:55:21 PDT 2026


================
@@ -70,43 +70,89 @@ bool Qualifiers::isStrictSupersetOf(Qualifiers Other) const {
           (hasObjCLifetime() && !Other.hasObjCLifetime()));
 }
 
+// When targeting the OpenCL execution environment, corresponding SYCL and
+// OpenCL address spaces designate the same underlying address space and are
+// mutually convertible.
+static bool isConvertibleOpenCLSYCLAddressSpace(LangAS A, LangAS B) {
+  return (A == LangAS::sycl_global && B == LangAS::opencl_global) ||
+         (A == LangAS::opencl_global && B == LangAS::sycl_global) ||
+         (A == LangAS::sycl_global_device &&
+          B == LangAS::opencl_global_device) ||
+         (A == LangAS::opencl_global_device &&
+          B == LangAS::sycl_global_device) ||
+         (A == LangAS::sycl_global_host && B == LangAS::opencl_global_host) ||
+         (A == LangAS::opencl_global_host && B == LangAS::sycl_global_host) ||
+         (A == LangAS::sycl_local && B == LangAS::opencl_local) ||
+         (A == LangAS::opencl_local && B == LangAS::sycl_local) ||
+         (A == LangAS::sycl_private && B == LangAS::opencl_private) ||
+         (A == LangAS::opencl_private && B == LangAS::sycl_private) ||
+         (A == LangAS::sycl_generic && B == LangAS::opencl_generic) ||
+         (A == LangAS::opencl_generic && B == LangAS::sycl_generic) ||
+         (A == LangAS::sycl_constant && B == LangAS::opencl_constant) ||
+         (A == LangAS::opencl_constant && B == LangAS::sycl_constant);
----------------
tahonermann wrote:

I think this can be expressed in a way that is easier to understand by doing something like this:
```
enum class MemoryRegion {
  Global,
  Local,
  Private,
  Generic,
  Constant
};
MemoryRegion getMemoryRegion(LangAS AS) {
  if (AS == LangAS::sycl_global || AS == LangAS::opencl_global)
    return MemoryRegion::Global;
  if (AS == LangAS::sycl_local || AS == LangAS::opencl_local)
    return MemoryRegion::Local;
  ...
}
static bool isConvertibleOpenCLSYCLAddressSpace(LangAS A, LangAS B) {
  return getMemoryRegion(A) == getMemoryRegion(B);
}
```

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


More information about the cfe-commits mailing list