[clang] 2ab513c - [SYCL] Enable `opencl_global_[host,device]` attributes for SYCL

Alexey Bader via cfe-commits cfe-commits at lists.llvm.org
Tue May 18 03:27:51 PDT 2021


Author: Alexey Bader
Date: 2021-05-18T10:27:35+03:00
New Revision: 2ab513cd3e0648806db7ed1f8170ad4a3d4e7749

URL: https://github.com/llvm/llvm-project/commit/2ab513cd3e0648806db7ed1f8170ad4a3d4e7749
DIFF: https://github.com/llvm/llvm-project/commit/2ab513cd3e0648806db7ed1f8170ad4a3d4e7749.diff

LOG: [SYCL] Enable `opencl_global_[host,device]` attributes for SYCL

Differential Revision: https://reviews.llvm.org/D100396

Added: 
    

Modified: 
    clang/docs/SYCLSupport.rst
    clang/include/clang/AST/Type.h
    clang/include/clang/Basic/AddressSpaces.h
    clang/include/clang/Sema/ParsedAttr.h
    clang/lib/AST/ASTContext.cpp
    clang/lib/AST/ItaniumMangle.cpp
    clang/lib/AST/TypePrinter.cpp
    clang/lib/Basic/Targets/AMDGPU.cpp
    clang/lib/Basic/Targets/NVPTX.h
    clang/lib/Basic/Targets/SPIR.h
    clang/lib/Basic/Targets/TCE.h
    clang/lib/Basic/Targets/X86.h
    clang/test/CodeGenSYCL/address-space-conversions.cpp
    clang/test/SemaSYCL/address-space-conversions.cpp
    clang/test/SemaTemplate/address_space-dependent.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/SYCLSupport.rst b/clang/docs/SYCLSupport.rst
index d45ecfbea53f8..6b529e3eb0127 100644
--- a/clang/docs/SYCLSupport.rst
+++ b/clang/docs/SYCLSupport.rst
@@ -34,10 +34,20 @@ the address space qualifier inference as detailed in
 
 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 @@ space attributes for pointers:
      - 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
index 84de51aba5b2d..9f46d53378976 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -486,13 +486,16 @@ class Qualifiers {
            // 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
index 5fa031250a629..99bb67fd26d19 100644
--- a/clang/include/clang/Basic/AddressSpaces.h
+++ b/clang/include/clang/Basic/AddressSpaces.h
@@ -46,6 +46,8 @@ enum class LangAS : unsigned {
 
   // 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
index 347925873b30f..f47f557adeb10 100644
--- a/clang/include/clang/Sema/ParsedAttr.h
+++ b/clang/include/clang/Sema/ParsedAttr.h
@@ -657,6 +657,10 @@ class ParsedAttr final
     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
index 06f232557708b..47d64a5fa48ea 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -937,6 +937,8 @@ static const LangASMap *getAddressSpaceMap(const TargetInfo &T,
         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
index 65e04f1d55ca3..2a3a94f58a557 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -2572,10 +2572,17 @@ void CXXNameMangler::mangleQualifiers(Qualifiers Quals, const DependentAddressSp
       case LangAS::opencl_generic:
         ASString = "CLgeneric";
         break;
-      //  <SYCL-addrspace> ::= "SY" [ "global" | "local" | "private" ]
+      //  <SYCL-addrspace> ::= "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
index 748a48f8eca4b..b2ce28e0ae1e7 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2135,8 +2135,10 @@ std::string Qualifiers::getAddrSpaceAsString(LangAS AS) {
   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
index 7cffe3d527b86..12cab8bd456b3 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -51,6 +51,8 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = {
     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 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
     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
index b7b0aae65819d..d193c4dd4771e 100644
--- a/clang/lib/Basic/Targets/NVPTX.h
+++ b/clang/lib/Basic/Targets/NVPTX.h
@@ -36,6 +36,8 @@ static const unsigned NVPTXAddrSpaceMap[] = {
     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
index 6d19016b07a79..638071d0cdce0 100644
--- a/clang/lib/Basic/Targets/SPIR.h
+++ b/clang/lib/Basic/Targets/SPIR.h
@@ -35,6 +35,8 @@ static const unsigned SPIRDefIsPrivMap[] = {
     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 @@ static const unsigned SPIRDefIsGenMap[] = {
     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
index 5a122bee7f96d..251b4d4b56f7b 100644
--- a/clang/lib/Basic/Targets/TCE.h
+++ b/clang/lib/Basic/Targets/TCE.h
@@ -42,8 +42,10 @@ static const unsigned TCEOpenCLAddrSpaceMap[] = {
     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
index 86a9339744b28..58b48ffd63288 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -36,6 +36,8 @@ static const unsigned X86AddrSpaceMap[] = {
     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
index 2da9963df7529..3732c4a1b889b 100644
--- a/clang/test/CodeGenSYCL/address-space-conversions.cpp
+++ b/clang/test/CodeGenSYCL/address-space-conversions.cpp
@@ -29,6 +29,10 @@ void usages() {
   // 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 @@ void usages() {
   // 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
index 2183f0ceb469f..d2e19b6f901d5 100644
--- a/clang/test/SemaSYCL/address-space-conversions.cpp
+++ b/clang/test/SemaSYCL/address-space-conversions.cpp
@@ -61,4 +61,17 @@ void usages() {
   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
index 821703bf78257..de23e694d6d16 100644
--- a/clang/test/SemaTemplate/address_space-dependent.cpp
+++ b/clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@ void neg() {
 
 template <long int I>
 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 <long int I>
@@ -101,7 +101,7 @@ int main() {
   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;


        


More information about the cfe-commits mailing list