[clang] 32b994b - [OpenCL] Defines helper function for OpenCL default address space
Justas Janickas via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 21 07:12:48 PDT 2021
Author: Justas Janickas
Date: 2021-09-21T15:12:08+01:00
New Revision: 32b994bca66641cdac8586f25315daf349921ebc
URL: https://github.com/llvm/llvm-project/commit/32b994bca66641cdac8586f25315daf349921ebc
DIFF: https://github.com/llvm/llvm-project/commit/32b994bca66641cdac8586f25315daf349921ebc.diff
LOG: [OpenCL] Defines helper function for OpenCL default address space
Helper function `getDefaultOpenCLPointeeAddrSpace()` introduced to
`ASTContext` class. It returns default OpenCL address space
depending on language version and enabled features. If generic
address space is supported, the helper function returns value
`LangAS::opencl_generic`. Otherwise, value `LangAS::opencl_private`
is returned. Code refactoring changes performed in several suitable
places.
Differential Revision: https://reviews.llvm.org/D109874
Added:
Modified:
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
Removed:
################################################################################
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index b8f7c3aae2608..f1b057c8003f8 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1362,6 +1362,12 @@ class ASTContext : public RefCountedBase<ASTContext> {
/// 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 getDefaultOpenCLPointeeAddrSpace() {
+ return LangOpts.OpenCLGenericAddressSpace ? LangAS::opencl_generic
+ : LangAS::opencl_private;
+ }
+
void setcudaConfigureCallDecl(FunctionDecl *FD) {
cudaConfigureCallDecl = FD;
}
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 31733932361f3..9fde21c7ee9e1 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -3779,11 +3779,8 @@ Expr::isNullPointerConstant(ASTContext &Ctx,
// 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.getDefaultOpenCLPointeeAddrSpace())
Qs.removeAddressSpace();
if (Pointee->isVoidType() && Qs.empty() && // to void*
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 0b936d60fc5ee..c997c70d17cef 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1430,7 +1430,7 @@ NamedDecl *Sema::getCurFunctionOrMethodDecl() {
LangAS Sema::getDefaultCXXMethodAddrSpace() const {
if (getLangOpts().OpenCL)
- return LangAS::opencl_generic;
+ return getASTContext().getDefaultOpenCLPointeeAddrSpace();
return LangAS::Default;
}
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 826abbd8c3623..060f42bf9d644 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3894,8 +3894,9 @@ static bool AdjustFunctionParmAndArgTypesForDeduction(
// "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.getDefaultOpenCLPointeeAddrSpace());
ArgType = S.Context.getLValueReferenceType(ArgType);
}
} else {
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index fcc2cf055be9e..d2d54281c63e0 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2092,9 +2092,7 @@ static QualType deduceOpenCLPointeeAddrSpace(Sema &S, QualType PointeeType) {
!PointeeType->isSamplerT() &&
!PointeeType.hasAddressSpace())
PointeeType = S.getASTContext().getAddrSpaceQualType(
- PointeeType, S.getLangOpts().OpenCLGenericAddressSpace
- ? LangAS::opencl_generic
- : LangAS::opencl_private);
+ PointeeType, S.getASTContext().getDefaultOpenCLPointeeAddrSpace());
return PointeeType;
}
More information about the cfe-commits
mailing list