diff --git a/clang/docs/SYCLSupport.rst b/clang/docs/SYCLSupport.rst --- a/clang/docs/SYCLSupport.rst +++ b/clang/docs/SYCLSupport.rst @@ -34,10 +34,20 @@ The default address space is "generic-memory", which is a virtual address space that overlaps the global, local, and private address spaces. SYCL mode enables -explicit conversions to/from the default address space from/to the address -space-attributed type and implicit conversions from the address space-attributed -type to the default address space. All named address spaces are disjoint and -sub-sets of default address space. +following conversions: + +- explicit conversions to/from the default address space from/to the address + space-attributed type +- implicit conversions from the address space-attributed type to the default + address space +- explicit conversions to/from the global address space from/to the + ``__attribute__((opencl_global_device))`` or + ``__attribute__((opencl_global_host))`` address space-attributed type +- implicit conversions from the ``__attribute__((opencl_global_device))`` or + ``__attribute__((opencl_global_host))`` address space-attributed type to the + global address space + +All named address spaces are disjoint and sub-sets of default address space. The SPIR target allocates SYCL namespace scope variables in the global address space. @@ -93,6 +103,10 @@ - SYCL address_space enumeration * - ``__attribute__((opencl_global))`` - global_space, constant_space + * - ``__attribute__((opencl_global_device))`` + - global_space + * - ``__attribute__((opencl_global_host))`` + - global_space * - ``__attribute__((opencl_local))`` - local_space * - ``__attribute__((opencl_private))`` diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -486,13 +486,16 @@ // allocated on device, which are a subset of __global. (A == LangAS::opencl_global && (B == LangAS::opencl_global_device || B == LangAS::opencl_global_host)) || + (A == LangAS::sycl_global && (B == LangAS::sycl_global_device || + B == LangAS::sycl_global_host)) || // Consider pointer size address spaces to be equivalent to default. ((isPtrSizeAddressSpace(A) || A == LangAS::Default) && (isPtrSizeAddressSpace(B) || B == LangAS::Default)) || // Default is a superset of SYCL address spaces. (A == LangAS::Default && (B == LangAS::sycl_private || B == LangAS::sycl_local || - B == LangAS::sycl_global)); + B == LangAS::sycl_global || B == LangAS::sycl_global_device || + B == LangAS::sycl_global_host)); } /// Returns true if the address space in these qualifiers is equal to or diff --git a/clang/include/clang/Basic/AddressSpaces.h b/clang/include/clang/Basic/AddressSpaces.h --- a/clang/include/clang/Basic/AddressSpaces.h +++ b/clang/include/clang/Basic/AddressSpaces.h @@ -46,6 +46,8 @@ // SYCL specific address spaces. sycl_global, + sycl_global_device, + sycl_global_host, sycl_local, sycl_private, diff --git a/clang/include/clang/Sema/ParsedAttr.h b/clang/include/clang/Sema/ParsedAttr.h --- a/clang/include/clang/Sema/ParsedAttr.h +++ b/clang/include/clang/Sema/ParsedAttr.h @@ -657,6 +657,10 @@ switch (getKind()) { case ParsedAttr::AT_OpenCLGlobalAddressSpace: return LangAS::sycl_global; + case ParsedAttr::AT_OpenCLGlobalDeviceAddressSpace: + return LangAS::sycl_global_device; + case ParsedAttr::AT_OpenCLGlobalHostAddressSpace: + return LangAS::sycl_global_host; case ParsedAttr::AT_OpenCLLocalAddressSpace: return LangAS::sycl_local; case ParsedAttr::AT_OpenCLPrivateAddressSpace: diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -937,6 +937,8 @@ 8, // cuda_constant 9, // cuda_shared 1, // sycl_global + 5, // sycl_global_device + 6, // sycl_global_host 3, // sycl_local 0, // sycl_private 10, // ptr32_sptr diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -2572,10 +2572,17 @@ case LangAS::opencl_generic: ASString = "CLgeneric"; break; - // ::= "SY" [ "global" | "local" | "private" ] + // ::= "SY" [ "global" | "local" | "private" | + // "device" | "host" ] case LangAS::sycl_global: ASString = "SYglobal"; break; + case LangAS::sycl_global_device: + ASString = "SYdevice"; + break; + case LangAS::sycl_global_host: + ASString = "SYhost"; + break; case LangAS::sycl_local: ASString = "SYlocal"; break; diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -2135,8 +2135,10 @@ case LangAS::opencl_generic: return "__generic"; case LangAS::opencl_global_device: + case LangAS::sycl_global_device: return "__global_device"; case LangAS::opencl_global_host: + case LangAS::sycl_global_host: return "__global_host"; case LangAS::cuda_device: return "__device__"; diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp --- a/clang/lib/Basic/Targets/AMDGPU.cpp +++ b/clang/lib/Basic/Targets/AMDGPU.cpp @@ -51,6 +51,8 @@ Constant, // cuda_constant Local, // cuda_shared Global, // sycl_global + Global, // sycl_global_device + Global, // sycl_global_host Local, // sycl_local Private, // sycl_private Generic, // ptr32_sptr @@ -72,6 +74,8 @@ Local, // cuda_shared // SYCL address space values for this map are dummy Generic, // sycl_global + Generic, // sycl_global_device + Generic, // sycl_global_host Generic, // sycl_local Generic, // sycl_private Generic, // ptr32_sptr diff --git a/clang/lib/Basic/Targets/NVPTX.h b/clang/lib/Basic/Targets/NVPTX.h --- a/clang/lib/Basic/Targets/NVPTX.h +++ b/clang/lib/Basic/Targets/NVPTX.h @@ -36,6 +36,8 @@ 4, // cuda_constant 3, // cuda_shared 1, // sycl_global + 1, // sycl_global_device + 1, // sycl_global_host 3, // sycl_local 0, // sycl_private 0, // ptr32_sptr diff --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h --- a/clang/lib/Basic/Targets/SPIR.h +++ b/clang/lib/Basic/Targets/SPIR.h @@ -35,6 +35,8 @@ 0, // cuda_shared // SYCL address space values for this map are dummy 0, // sycl_global + 0, // sycl_global_device + 0, // sycl_global_host 0, // sycl_local 0, // sycl_private 0, // ptr32_sptr @@ -56,6 +58,8 @@ 0, // cuda_constant 0, // cuda_shared 1, // sycl_global + 5, // sycl_global_device + 6, // sycl_global_host 3, // sycl_local 0, // sycl_private 0, // ptr32_sptr diff --git a/clang/lib/Basic/Targets/TCE.h b/clang/lib/Basic/Targets/TCE.h --- a/clang/lib/Basic/Targets/TCE.h +++ b/clang/lib/Basic/Targets/TCE.h @@ -42,8 +42,10 @@ 0, // cuda_device 0, // cuda_constant 0, // cuda_shared - 3, // sycl_global - 4, // sycl_local + 0, // sycl_global + 0, // sycl_global_device + 0, // sycl_global_host + 0, // sycl_local 0, // sycl_private 0, // ptr32_sptr 0, // ptr32_uptr diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -36,6 +36,8 @@ 0, // cuda_constant 0, // cuda_shared 0, // sycl_global + 0, // sycl_global_device + 0, // sycl_global_host 0, // sycl_local 0, // sycl_private 270, // ptr32_sptr diff --git a/clang/test/CodeGenSYCL/address-space-conversions.cpp b/clang/test/CodeGenSYCL/address-space-conversions.cpp --- a/clang/test/CodeGenSYCL/address-space-conversions.cpp +++ b/clang/test/CodeGenSYCL/address-space-conversions.cpp @@ -29,6 +29,10 @@ // CHECK-DAG: [[PRIV:%[a-zA-Z0-9]+]] = alloca i32* // CHECK-DAG: [[PRIV]].ascast = addrspacecast i32** [[PRIV]] to i32* addrspace(4)* __attribute__((opencl_private)) int *PRIV; + // CHECK-DAG: [[GLOB_DEVICE:%[a-zA-Z0-9]+]] = alloca i32 addrspace(5)* + __attribute__((opencl_global_device)) int *GLOBDEVICE; + // CHECK-DAG: [[GLOB_HOST:%[a-zA-Z0-9]+]] = alloca i32 addrspace(6)* + __attribute__((opencl_global_host)) int *GLOBHOST; // Explicit conversions // From names address spaces to default address space @@ -57,6 +61,15 @@ // CHECK-DAG: [[NoAS_CAST:%[a-zA-Z0-9]+]] = addrspacecast i32 addrspace(4)* [[NoAS_LOAD]] to i32* // CHECK-DAG: store i32* [[NoAS_CAST]], i32* addrspace(4)* [[PRIV]].ascast PRIV = (__attribute__((opencl_private)) int *)NoAS; + // From opencl_global_[host/device] address spaces to opencl_global + // CHECK-DAG: [[GLOBDEVICE_LOAD:%[a-zA-Z0-9]+]] = load i32 addrspace(5)*, i32 addrspace(5)* addrspace(4)* [[GLOB_DEVICE]].ascast + // CHECK-DAG: [[GLOBDEVICE_CAST:%[a-zA-Z0-9]+]] = addrspacecast i32 addrspace(5)* [[GLOBDEVICE_LOAD]] to i32 addrspace(1)* + // CHECK-DAG: store i32 addrspace(1)* [[GLOBDEVICE_CAST]], i32 addrspace(1)* addrspace(4)* [[GLOB]].ascast + GLOB = (__attribute__((opencl_global)) int *)GLOBDEVICE; + // CHECK-DAG: [[GLOBHOST_LOAD:%[a-zA-Z0-9]+]] = load i32 addrspace(6)*, i32 addrspace(6)* addrspace(4)* [[GLOB_HOST]].ascast + // CHECK-DAG: [[GLOBHOST_CAST:%[a-zA-Z0-9]+]] = addrspacecast i32 addrspace(6)* [[GLOBHOST_LOAD]] to i32 addrspace(1)* + // CHECK-DAG: store i32 addrspace(1)* [[GLOBHOST_CAST]], i32 addrspace(1)* addrspace(4)* [[GLOB]].ascast + GLOB = (__attribute__((opencl_global)) int *)GLOBHOST; bar(*GLOB); // CHECK-DAG: [[GLOB_LOAD:%[a-zA-Z0-9]+]] = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(4)* [[GLOB]].ascast diff --git a/clang/test/SemaSYCL/address-space-conversions.cpp b/clang/test/SemaSYCL/address-space-conversions.cpp --- a/clang/test/SemaSYCL/address-space-conversions.cpp +++ b/clang/test/SemaSYCL/address-space-conversions.cpp @@ -61,4 +61,17 @@ void *v = GLOB; (void)i; (void)v; + + __attribute__((opencl_global_host)) int *GLOB_HOST; + bar(*GLOB_HOST); + bar2(*GLOB_HOST); + GLOB = GLOB_HOST; + GLOB_HOST = GLOB; // expected-error {{assigning '__global int *' to '__global_host int *' changes address space of pointer}} + GLOB_HOST = static_cast<__attribute__((opencl_global_host)) int *>(GLOB); // expected-error {{static_cast from '__global int *' to '__global_host int *' is not allowed}} + __attribute__((opencl_global_device)) int *GLOB_DEVICE; + bar(*GLOB_DEVICE); + bar2(*GLOB_DEVICE); + GLOB = GLOB_DEVICE; + GLOB_DEVICE = GLOB; // expected-error {{assigning '__global int *' to '__global_device int *' changes address space of pointer}} + GLOB_DEVICE = static_cast<__attribute__((opencl_global_device)) int *>(GLOB); // expected-error {{static_cast from '__global int *' to '__global_device int *' is not allowed}} } diff --git a/clang/test/SemaTemplate/address_space-dependent.cpp b/clang/test/SemaTemplate/address_space-dependent.cpp --- a/clang/test/SemaTemplate/address_space-dependent.cpp +++ b/clang/test/SemaTemplate/address_space-dependent.cpp @@ -43,7 +43,7 @@ template void tooBig() { - __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388590)}} + __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388588)}} } template @@ -101,7 +101,7 @@ car<1, 2, 3>(); // expected-note {{in instantiation of function template specialization 'car<1, 2, 3>' requested here}} HasASTemplateFields<1> HASTF; neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}} - correct<0x7FFFED>(); + correct<0x7FFFEB>(); tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650L>' requested here}} __attribute__((address_space(1))) char *x;