[PATCH] D109874: [OpenCL] Defines helper function for OpenCL default address space

Justas Janickas via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 21 03:14:50 PDT 2021


Topotuna updated this revision to Diff 373834.
Topotuna edited the summary of this revision.
Topotuna added a comment.

Helper function renamed for clarity. Additional check added to `if` statement to ensure it is only carried out in OpenCL.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109874/new/

https://reviews.llvm.org/D109874

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/Expr.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaType.cpp


Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2092,9 +2092,7 @@
       !PointeeType->isSamplerT() &&
       !PointeeType.hasAddressSpace())
     PointeeType = S.getASTContext().getAddrSpaceQualType(
-        PointeeType, S.getLangOpts().OpenCLGenericAddressSpace
-                         ? LangAS::opencl_generic
-                         : LangAS::opencl_private);
+        PointeeType, S.getASTContext().getDefaultPointeeOpenCLAddrSpace());
   return PointeeType;
 }
 
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3894,8 +3894,9 @@
     //   "lvalue reference to A" is used in place of A for type deduction.
     if (isForwardingReference(QualType(ParamRefType, 0), FirstInnerIndex) &&
         Arg->isLValue()) {
-      if (S.getLangOpts().OpenCL  && !ArgType.hasAddressSpace())
-        ArgType = S.Context.getAddrSpaceQualType(ArgType, LangAS::opencl_generic);
+      if (S.getLangOpts().OpenCL && !ArgType.hasAddressSpace())
+        ArgType = S.Context.getAddrSpaceQualType(
+            ArgType, S.Context.getDefaultPointeeOpenCLAddrSpace());
       ArgType = S.Context.getLValueReferenceType(ArgType);
     }
   } else {
Index: clang/lib/Sema/Sema.cpp
===================================================================
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -1430,7 +1430,7 @@
 
 LangAS Sema::getDefaultCXXMethodAddrSpace() const {
   if (getLangOpts().OpenCL)
-    return LangAS::opencl_generic;
+    return getASTContext().getDefaultPointeeOpenCLAddrSpace();
   return LangAS::Default;
 }
 
Index: clang/lib/AST/Expr.cpp
===================================================================
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -3779,11 +3779,8 @@
         // has non-default address space it is not treated as nullptr.
         // (__generic void*)0 in OpenCL 2.0 should not be treated as nullptr
         // since it cannot be assigned to a pointer to constant address space.
-        if ((Ctx.getLangOpts().OpenCLVersion >= 200 &&
-             Pointee.getAddressSpace() == LangAS::opencl_generic) ||
-            (Ctx.getLangOpts().OpenCL &&
-             Ctx.getLangOpts().OpenCLVersion < 200 &&
-             Pointee.getAddressSpace() == LangAS::opencl_private))
+        if (Ctx.getLangOpts().OpenCL &&
+            Pointee.getAddressSpace() == Ctx.getDefaultPointeeOpenCLAddrSpace())
           Qs.removeAddressSpace();
 
         if (Pointee->isVoidType() && Qs.empty() && // to void*
Index: clang/include/clang/AST/ASTContext.h
===================================================================
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -1362,6 +1362,12 @@
   /// Get address space for OpenCL type.
   LangAS getOpenCLTypeAddrSpace(const Type *T) const;
 
+  /// Returns default address space based on OpenCL version and enabled features
+  inline LangAS getDefaultPointeeOpenCLAddrSpace() {
+    return LangOpts.OpenCLGenericAddressSpace ? LangAS::opencl_generic
+                                              : LangAS::opencl_private;
+  }
+
   void setcudaConfigureCallDecl(FunctionDecl *FD) {
     cudaConfigureCallDecl = FD;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109874.373834.patch
Type: text/x-patch
Size: 3430 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210921/63c41ed2/attachment.bin>


More information about the cfe-commits mailing list