@@ -111,6 +111,11 @@ class Util {
111111 // / \param Tmpl whether the class is template instantiation or simple record
112112 static bool isSyclType (QualType Ty, StringRef Name, bool Tmpl = false );
113113
114+ // / Checks whether given clang type is a standard SYCL API accessor class,
115+ // / the check assumes the type is templated.
116+ // / \param Ty the clang type being checked
117+ static bool isSyclAccessorType (QualType Ty);
118+
114119 // / Checks whether given clang type is a full specialization of the SYCL
115120 // / specialization constant class.
116121 static bool isSyclSpecConstantType (QualType Ty);
@@ -1021,7 +1026,11 @@ static ParamDesc makeParamDesc(ASTContext &Ctx, StringRef Name, QualType Ty) {
10211026}
10221027
10231028// / \return the target of given SYCL accessor type
1024- static target getAccessTarget (const ClassTemplateSpecializationDecl *AccTy) {
1029+ static target getAccessTarget (QualType FieldTy,
1030+ const ClassTemplateSpecializationDecl *AccTy) {
1031+ if (Util::isSyclType (FieldTy, " local_accessor" , true /* Tmpl*/ ))
1032+ return local;
1033+
10251034 return static_cast <target>(
10261035 AccTy->getTemplateArgs ()[3 ].getAsIntegral ().getExtValue ());
10271036}
@@ -1615,7 +1624,7 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
16151624 assert (Util::isSyclSpecialType (Ty) &&
16161625 " Should only be called on sycl special class types." );
16171626 const RecordDecl *RecD = Ty->getAsRecordDecl ();
1618- if (IsSIMD && !Util::isSyclType (Ty, " accessor " , true /* Tmp */ ))
1627+ if (IsSIMD && !Util::isSyclAccessorType (Ty))
16191628 return SemaRef.Diag (Loc.getBegin (),
16201629 diag::err_sycl_esimd_not_supported_for_type)
16211630 << RecD;
@@ -1927,19 +1936,24 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
19271936 }
19281937
19291938 // Additional processing is required for accessor type.
1930- void handleAccessorType (const CXXRecordDecl *RecordDecl, SourceLocation Loc) {
1939+ void handleAccessorType (QualType FieldTy, const CXXRecordDecl *RecordDecl,
1940+ SourceLocation Loc) {
19311941 handleAccessorPropertyList (Params.back (), RecordDecl, Loc);
1932- // Get access mode of accessor.
1933- const auto *AccessorSpecializationDecl =
1934- cast<ClassTemplateSpecializationDecl>(RecordDecl);
1935- const TemplateArgument &AccessModeArg =
1936- AccessorSpecializationDecl->getTemplateArgs ().get (2 );
1942+
1943+ // If "accessor" type check if read only
1944+ if (Util::isSyclType (FieldTy, " accessor" , true /* Tmpl*/ )) {
1945+ // Get access mode of accessor.
1946+ const auto *AccessorSpecializationDecl =
1947+ cast<ClassTemplateSpecializationDecl>(RecordDecl);
1948+ const TemplateArgument &AccessModeArg =
1949+ AccessorSpecializationDecl->getTemplateArgs ().get (2 );
1950+ if (isReadOnlyAccessor (AccessModeArg))
1951+ Params.back ()->addAttr (
1952+ SYCLAccessorReadonlyAttr::CreateImplicit (SemaRef.getASTContext ()));
1953+ }
19371954
19381955 // Add implicit attribute to parameter decl when it is a read only
19391956 // SYCL accessor.
1940- if (isReadOnlyAccessor (AccessModeArg))
1941- Params.back ()->addAttr (
1942- SYCLAccessorReadonlyAttr::CreateImplicit (SemaRef.getASTContext ()));
19431957 Params.back ()->addAttr (
19441958 SYCLAccessorPtrAttr::CreateImplicit (SemaRef.getASTContext ()));
19451959 }
@@ -1952,8 +1966,7 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
19521966 const auto *RecordDecl = FieldTy->getAsCXXRecordDecl ();
19531967 assert (RecordDecl && " The type must be a RecordDecl" );
19541968 llvm::StringLiteral MethodName =
1955- KernelDecl->hasAttr <SYCLSimdAttr>() &&
1956- Util::isSyclType (FieldTy, " accessor" , true /* Tmp*/ )
1969+ KernelDecl->hasAttr <SYCLSimdAttr>() && Util::isSyclAccessorType (FieldTy)
19571970 ? InitESIMDMethodName
19581971 : InitMethodName;
19591972 CXXMethodDecl *InitMethod = getMethodByName (RecordDecl, MethodName);
@@ -1978,8 +1991,8 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
19781991 // added, this code needs to be refactored to call
19791992 // handleAccessorPropertyList for each class which requires it.
19801993 if (ParamTy.getTypePtr ()->isPointerType () &&
1981- Util::isSyclType (FieldTy, " accessor " , true /* Tmp */ ))
1982- handleAccessorType (RecordDecl, FD->getBeginLoc ());
1994+ Util::isSyclAccessorType (FieldTy))
1995+ handleAccessorType (FieldTy, RecordDecl, FD->getBeginLoc ());
19831996 }
19841997 LastParamIndex = ParamIndex;
19851998 return true ;
@@ -2073,8 +2086,7 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
20732086 const auto *RecordDecl = FieldTy->getAsCXXRecordDecl ();
20742087 assert (RecordDecl && " The type must be a RecordDecl" );
20752088 llvm::StringLiteral MethodName =
2076- KernelDecl->hasAttr <SYCLSimdAttr>() &&
2077- Util::isSyclType (FieldTy, " accessor" , true /* Tmp*/ )
2089+ KernelDecl->hasAttr <SYCLSimdAttr>() && Util::isSyclAccessorType (FieldTy)
20782090 ? InitESIMDMethodName
20792091 : InitMethodName;
20802092 CXXMethodDecl *InitMethod = getMethodByName (RecordDecl, MethodName);
@@ -2093,8 +2105,8 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
20932105 // added, this code needs to be refactored to call
20942106 // handleAccessorPropertyList for each class which requires it.
20952107 if (ParamTy.getTypePtr ()->isPointerType () &&
2096- Util::isSyclType (FieldTy, " accessor " , true /* Tmp */ ))
2097- handleAccessorType (RecordDecl, BS.getBeginLoc ());
2108+ Util::isSyclAccessorType (FieldTy))
2109+ handleAccessorType (FieldTy, RecordDecl, BS.getBeginLoc ());
20982110 }
20992111 LastParamIndex = ParamIndex;
21002112 return true ;
@@ -2215,9 +2227,8 @@ class SyclKernelArgsSizeChecker : public SyclKernelFieldHandler {
22152227 const CXXRecordDecl *RecordDecl = FieldTy->getAsCXXRecordDecl ();
22162228 assert (RecordDecl && " The type must be a RecordDecl" );
22172229 llvm::StringLiteral MethodName =
2218- (IsSIMD && Util::isSyclType (FieldTy, " accessor" , true /* Tmp*/ ))
2219- ? InitESIMDMethodName
2220- : InitMethodName;
2230+ (IsSIMD && Util::isSyclAccessorType (FieldTy)) ? InitESIMDMethodName
2231+ : InitMethodName;
22212232 CXXMethodDecl *InitMethod = getMethodByName (RecordDecl, MethodName);
22222233 assert (InitMethod && " The type must have the __init method" );
22232234 for (const ParmVarDecl *Param : InitMethod->parameters ())
@@ -3124,7 +3135,7 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
31243135 " Incorrect template args for Accessor Type" );
31253136 int Dims = static_cast <int >(
31263137 AccTy->getTemplateArgs ()[1 ].getAsIntegral ().getExtValue ());
3127- int Info = getAccessTarget (AccTy) | (Dims << 11 );
3138+ int Info = getAccessTarget (FieldTy, AccTy) | (Dims << 11 );
31283139 Header.addParamDesc (SYCLIntegrationHeader::kind_accessor, Info,
31293140 CurOffset +
31303141 offsetOf (RD, BC.getType ()->getAsCXXRecordDecl ()));
@@ -3134,14 +3145,14 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
31343145 bool handleSyclSpecialType (FieldDecl *FD, QualType FieldTy) final {
31353146 const auto *ClassTy = FieldTy->getAsCXXRecordDecl ();
31363147 assert (ClassTy && " Type must be a C++ record type" );
3137- if (Util::isSyclType (FieldTy, " accessor " , true /* Tmp */ )) {
3148+ if (Util::isSyclAccessorType (FieldTy)) {
31383149 const auto *AccTy =
31393150 cast<ClassTemplateSpecializationDecl>(FieldTy->getAsRecordDecl ());
31403151 assert (AccTy->getTemplateArgs ().size () >= 2 &&
31413152 " Incorrect template args for Accessor Type" );
31423153 int Dims = static_cast <int >(
31433154 AccTy->getTemplateArgs ()[1 ].getAsIntegral ().getExtValue ());
3144- int Info = getAccessTarget (AccTy) | (Dims << 11 );
3155+ int Info = getAccessTarget (FieldTy, AccTy) | (Dims << 11 );
31453156
31463157 Header.addParamDesc (SYCLIntegrationHeader::kind_accessor, Info,
31473158 CurOffset + offsetOf (FD, FieldTy));
@@ -5195,6 +5206,11 @@ bool Util::isSyclType(QualType Ty, StringRef Name, bool Tmpl) {
51955206 return matchQualifiedTypeName (Ty, Scopes);
51965207}
51975208
5209+ bool Util::isSyclAccessorType (QualType Ty) {
5210+ return isSyclType (Ty, " accessor" , true /* Tmpl */ ) ||
5211+ isSyclType (Ty, " local_accessor" , true /* Tmpl */ );
5212+ }
5213+
51985214bool Util::isAccessorPropertyListType (QualType Ty) {
51995215 std::array<DeclContextDesc, 5 > Scopes = {
52005216 Util::MakeDeclContextDesc (Decl::Kind::Namespace, " sycl" ),
0 commit comments