@@ -111,6 +111,11 @@ class Util {
111
111
// / \param Tmpl whether the class is template instantiation or simple record
112
112
static bool isSyclType (QualType Ty, StringRef Name, bool Tmpl = false );
113
113
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
+
114
119
// / Checks whether given clang type is a full specialization of the SYCL
115
120
// / specialization constant class.
116
121
static bool isSyclSpecConstantType (QualType Ty);
@@ -1021,7 +1026,11 @@ static ParamDesc makeParamDesc(ASTContext &Ctx, StringRef Name, QualType Ty) {
1021
1026
}
1022
1027
1023
1028
// / \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
+
1025
1034
return static_cast <target>(
1026
1035
AccTy->getTemplateArgs ()[3 ].getAsIntegral ().getExtValue ());
1027
1036
}
@@ -1615,7 +1624,7 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
1615
1624
assert (Util::isSyclSpecialType (Ty) &&
1616
1625
" Should only be called on sycl special class types." );
1617
1626
const RecordDecl *RecD = Ty->getAsRecordDecl ();
1618
- if (IsSIMD && !Util::isSyclType (Ty, " accessor " , true /* Tmp */ ))
1627
+ if (IsSIMD && !Util::isSyclAccessorType (Ty))
1619
1628
return SemaRef.Diag (Loc.getBegin (),
1620
1629
diag::err_sycl_esimd_not_supported_for_type)
1621
1630
<< RecD;
@@ -1927,19 +1936,24 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
1927
1936
}
1928
1937
1929
1938
// 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) {
1931
1941
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
+ }
1937
1954
1938
1955
// Add implicit attribute to parameter decl when it is a read only
1939
1956
// SYCL accessor.
1940
- if (isReadOnlyAccessor (AccessModeArg))
1941
- Params.back ()->addAttr (
1942
- SYCLAccessorReadonlyAttr::CreateImplicit (SemaRef.getASTContext ()));
1943
1957
Params.back ()->addAttr (
1944
1958
SYCLAccessorPtrAttr::CreateImplicit (SemaRef.getASTContext ()));
1945
1959
}
@@ -1952,8 +1966,7 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
1952
1966
const auto *RecordDecl = FieldTy->getAsCXXRecordDecl ();
1953
1967
assert (RecordDecl && " The type must be a RecordDecl" );
1954
1968
llvm::StringLiteral MethodName =
1955
- KernelDecl->hasAttr <SYCLSimdAttr>() &&
1956
- Util::isSyclType (FieldTy, " accessor" , true /* Tmp*/ )
1969
+ KernelDecl->hasAttr <SYCLSimdAttr>() && Util::isSyclAccessorType (FieldTy)
1957
1970
? InitESIMDMethodName
1958
1971
: InitMethodName;
1959
1972
CXXMethodDecl *InitMethod = getMethodByName (RecordDecl, MethodName);
@@ -1978,8 +1991,8 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
1978
1991
// added, this code needs to be refactored to call
1979
1992
// handleAccessorPropertyList for each class which requires it.
1980
1993
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 ());
1983
1996
}
1984
1997
LastParamIndex = ParamIndex;
1985
1998
return true ;
@@ -2073,8 +2086,7 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
2073
2086
const auto *RecordDecl = FieldTy->getAsCXXRecordDecl ();
2074
2087
assert (RecordDecl && " The type must be a RecordDecl" );
2075
2088
llvm::StringLiteral MethodName =
2076
- KernelDecl->hasAttr <SYCLSimdAttr>() &&
2077
- Util::isSyclType (FieldTy, " accessor" , true /* Tmp*/ )
2089
+ KernelDecl->hasAttr <SYCLSimdAttr>() && Util::isSyclAccessorType (FieldTy)
2078
2090
? InitESIMDMethodName
2079
2091
: InitMethodName;
2080
2092
CXXMethodDecl *InitMethod = getMethodByName (RecordDecl, MethodName);
@@ -2093,8 +2105,8 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
2093
2105
// added, this code needs to be refactored to call
2094
2106
// handleAccessorPropertyList for each class which requires it.
2095
2107
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 ());
2098
2110
}
2099
2111
LastParamIndex = ParamIndex;
2100
2112
return true ;
@@ -2215,9 +2227,8 @@ class SyclKernelArgsSizeChecker : public SyclKernelFieldHandler {
2215
2227
const CXXRecordDecl *RecordDecl = FieldTy->getAsCXXRecordDecl ();
2216
2228
assert (RecordDecl && " The type must be a RecordDecl" );
2217
2229
llvm::StringLiteral MethodName =
2218
- (IsSIMD && Util::isSyclType (FieldTy, " accessor" , true /* Tmp*/ ))
2219
- ? InitESIMDMethodName
2220
- : InitMethodName;
2230
+ (IsSIMD && Util::isSyclAccessorType (FieldTy)) ? InitESIMDMethodName
2231
+ : InitMethodName;
2221
2232
CXXMethodDecl *InitMethod = getMethodByName (RecordDecl, MethodName);
2222
2233
assert (InitMethod && " The type must have the __init method" );
2223
2234
for (const ParmVarDecl *Param : InitMethod->parameters ())
@@ -3124,7 +3135,7 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
3124
3135
" Incorrect template args for Accessor Type" );
3125
3136
int Dims = static_cast <int >(
3126
3137
AccTy->getTemplateArgs ()[1 ].getAsIntegral ().getExtValue ());
3127
- int Info = getAccessTarget (AccTy) | (Dims << 11 );
3138
+ int Info = getAccessTarget (FieldTy, AccTy) | (Dims << 11 );
3128
3139
Header.addParamDesc (SYCLIntegrationHeader::kind_accessor, Info,
3129
3140
CurOffset +
3130
3141
offsetOf (RD, BC.getType ()->getAsCXXRecordDecl ()));
@@ -3134,14 +3145,14 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
3134
3145
bool handleSyclSpecialType (FieldDecl *FD, QualType FieldTy) final {
3135
3146
const auto *ClassTy = FieldTy->getAsCXXRecordDecl ();
3136
3147
assert (ClassTy && " Type must be a C++ record type" );
3137
- if (Util::isSyclType (FieldTy, " accessor " , true /* Tmp */ )) {
3148
+ if (Util::isSyclAccessorType (FieldTy)) {
3138
3149
const auto *AccTy =
3139
3150
cast<ClassTemplateSpecializationDecl>(FieldTy->getAsRecordDecl ());
3140
3151
assert (AccTy->getTemplateArgs ().size () >= 2 &&
3141
3152
" Incorrect template args for Accessor Type" );
3142
3153
int Dims = static_cast <int >(
3143
3154
AccTy->getTemplateArgs ()[1 ].getAsIntegral ().getExtValue ());
3144
- int Info = getAccessTarget (AccTy) | (Dims << 11 );
3155
+ int Info = getAccessTarget (FieldTy, AccTy) | (Dims << 11 );
3145
3156
3146
3157
Header.addParamDesc (SYCLIntegrationHeader::kind_accessor, Info,
3147
3158
CurOffset + offsetOf (FD, FieldTy));
@@ -5195,6 +5206,11 @@ bool Util::isSyclType(QualType Ty, StringRef Name, bool Tmpl) {
5195
5206
return matchQualifiedTypeName (Ty, Scopes);
5196
5207
}
5197
5208
5209
+ bool Util::isSyclAccessorType (QualType Ty) {
5210
+ return isSyclType (Ty, " accessor" , true /* Tmpl */ ) ||
5211
+ isSyclType (Ty, " local_accessor" , true /* Tmpl */ );
5212
+ }
5213
+
5198
5214
bool Util::isAccessorPropertyListType (QualType Ty) {
5199
5215
std::array<DeclContextDesc, 5 > Scopes = {
5200
5216
Util::MakeDeclContextDesc (Decl::Kind::Namespace, " sycl" ),
0 commit comments