14
14
#include " clang/AST/QualTypeNames.h"
15
15
#include " clang/AST/RecordLayout.h"
16
16
#include " clang/AST/RecursiveASTVisitor.h"
17
+ #include " clang/Analysis/CallGraph.h"
17
18
#include " clang/Sema/Sema.h"
18
19
#include " llvm/ADT/SmallPtrSet.h"
19
20
#include " llvm/ADT/SmallVector.h"
20
21
#include " llvm/Support/FileSystem.h"
21
22
#include " llvm/Support/Path.h"
22
23
#include " llvm/Support/raw_ostream.h"
23
- #include " clang/Analysis/CallGraph.h"
24
24
25
25
#include < array>
26
26
@@ -95,17 +95,17 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
95
95
// all functions used by kernel have already been parsed and have
96
96
// definitions.
97
97
if (RecursiveSet.count (Callee)) {
98
- SemaRef.Diag (e->getExprLoc (), diag::err_sycl_restrict) <<
99
- KernelCallRecursiveFunction;
98
+ SemaRef.Diag (e->getExprLoc (), diag::err_sycl_restrict)
99
+ << KernelCallRecursiveFunction;
100
100
SemaRef.Diag (Callee->getSourceRange ().getBegin (),
101
- diag::note_sycl_recursive_function_declared_here)
102
- << KernelCallRecursiveFunction;
101
+ diag::note_sycl_recursive_function_declared_here)
102
+ << KernelCallRecursiveFunction;
103
103
}
104
104
105
105
if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Callee))
106
106
if (Method->isVirtual ())
107
- SemaRef.Diag (e->getExprLoc (), diag::err_sycl_restrict) <<
108
- KernelCallVirtualFunction;
107
+ SemaRef.Diag (e->getExprLoc (), diag::err_sycl_restrict)
108
+ << KernelCallVirtualFunction;
109
109
110
110
CheckSYCLType (Callee->getReturnType (), Callee->getSourceRange ());
111
111
@@ -116,8 +116,8 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
116
116
}
117
117
}
118
118
} else if (!SemaRef.getLangOpts ().SYCLAllowFuncPtr )
119
- SemaRef.Diag (e->getExprLoc (), diag::err_sycl_restrict) <<
120
- KernelCallFunctionPointer;
119
+ SemaRef.Diag (e->getExprLoc (), diag::err_sycl_restrict)
120
+ << KernelCallFunctionPointer;
121
121
return true ;
122
122
}
123
123
@@ -178,8 +178,8 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
178
178
if (VarDecl *VD = dyn_cast<VarDecl>(E->getMemberDecl ())) {
179
179
bool IsConst = VD->getType ().getNonReferenceType ().isConstQualified ();
180
180
if (VD->isStaticDataMember () && !IsConst)
181
- SemaRef.Diag (E->getExprLoc (), diag::err_sycl_restrict) <<
182
- KernelNonConstStaticDataVariable;
181
+ SemaRef.Diag (E->getExprLoc (), diag::err_sycl_restrict)
182
+ << KernelNonConstStaticDataVariable;
183
183
}
184
184
return true ;
185
185
}
@@ -190,24 +190,24 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
190
190
bool IsConst = VD->getType ().getNonReferenceType ().isConstQualified ();
191
191
if (!IsConst && VD->hasGlobalStorage () && !VD->isStaticLocal () &&
192
192
!VD->isStaticDataMember () && !isa<ParmVarDecl>(VD))
193
- SemaRef.Diag (E->getLocation (), diag::err_sycl_restrict) <<
194
- KernelGlobalVariable;
193
+ SemaRef.Diag (E->getLocation (), diag::err_sycl_restrict)
194
+ << KernelGlobalVariable;
195
195
}
196
196
return true ;
197
197
}
198
198
199
199
bool VisitCXXNewExpr (CXXNewExpr *E) {
200
- // Memory storage allocation is not allowed in kernels.
201
- // All memory allocation for the device is done on
202
- // the host using accessor classes. Consequently, the default
203
- // allocation operator new overloads that allocate
204
- // storage are disallowed in a SYCL kernel. The placement
205
- // new operator and any user-defined overloads that
206
- // do not allocate storage are permitted.
200
+ // Memory storage allocation is not allowed in kernels.
201
+ // All memory allocation for the device is done on
202
+ // the host using accessor classes. Consequently, the default
203
+ // allocation operator new overloads that allocate
204
+ // storage are disallowed in a SYCL kernel. The placement
205
+ // new operator and any user-defined overloads that
206
+ // do not allocate storage are permitted.
207
207
if (FunctionDecl *FD = E->getOperatorNew ()) {
208
208
if (FD->isReplaceableGlobalAllocationFunction ()) {
209
- SemaRef.Diag (E->getExprLoc (), diag::err_sycl_restrict) <<
210
- KernelAllocateStorage;
209
+ SemaRef.Diag (E->getExprLoc (), diag::err_sycl_restrict)
210
+ << KernelAllocateStorage;
211
211
} else if (FunctionDecl *Def = FD->getDefinition ()) {
212
212
if (!Def->hasAttr <SYCLDeviceAttr>()) {
213
213
Def->addAttr (SYCLDeviceAttr::CreateImplicit (SemaRef.Context ));
@@ -219,26 +219,26 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
219
219
}
220
220
221
221
bool VisitCXXThrowExpr (CXXThrowExpr *E) {
222
- SemaRef.Diag (E->getExprLoc (), diag::err_sycl_restrict) <<
223
- KernelUseExceptions;
222
+ SemaRef.Diag (E->getExprLoc (), diag::err_sycl_restrict)
223
+ << KernelUseExceptions;
224
224
return true ;
225
225
}
226
226
227
227
bool VisitCXXCatchStmt (CXXCatchStmt *S) {
228
- SemaRef.Diag (S->getBeginLoc (), diag::err_sycl_restrict) <<
229
- KernelUseExceptions;
228
+ SemaRef.Diag (S->getBeginLoc (), diag::err_sycl_restrict)
229
+ << KernelUseExceptions;
230
230
return true ;
231
231
}
232
232
233
233
bool VisitCXXTryStmt (CXXTryStmt *S) {
234
- SemaRef.Diag (S->getBeginLoc (), diag::err_sycl_restrict) <<
235
- KernelUseExceptions;
234
+ SemaRef.Diag (S->getBeginLoc (), diag::err_sycl_restrict)
235
+ << KernelUseExceptions;
236
236
return true ;
237
237
}
238
238
239
239
bool VisitSEHTryStmt (SEHTryStmt *S) {
240
- SemaRef.Diag (S->getBeginLoc (), diag::err_sycl_restrict) <<
241
- KernelUseExceptions;
240
+ SemaRef.Diag (S->getBeginLoc (), diag::err_sycl_restrict)
241
+ << KernelUseExceptions;
242
242
return true ;
243
243
}
244
244
@@ -291,8 +291,8 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
291
291
}
292
292
}
293
293
}
294
- private:
295
294
295
+ private:
296
296
bool CheckSYCLType (QualType Ty, SourceRange Loc) {
297
297
if (Ty->isVariableArrayType ()) {
298
298
SemaRef.Diag (Loc.getBegin (), diag::err_vla_unsupported);
@@ -306,7 +306,7 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
306
306
// FIXME: this seems like a temporary fix for SYCL programs
307
307
// that pre-declare, use, but not define OclCXX classes,
308
308
// which are later translated into SPIRV types.
309
- if (!CRD->hasDefinition ())
309
+ if (!CRD->hasDefinition ())
310
310
return true ;
311
311
312
312
if (CRD->isPolymorphic ()) {
@@ -450,9 +450,10 @@ CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelCallerFunc, DeclContext *DC) {
450
450
QualType FieldType = Field->getType ();
451
451
CXXRecordDecl *CRD = FieldType->getAsCXXRecordDecl ();
452
452
if (CRD && Util::isSyclAccessorType (FieldType)) {
453
- // Since this is an accessor next 3 TargetFuncParams including current
454
- // should be set in __init method: _ValueType*, range<int>, id<int>
455
- const size_t NumParams = 3 ;
453
+ // Since this is an accessor next 4 TargetFuncParams including current
454
+ // should be set in __init method: _ValueType*, range<int>, range<int>,
455
+ // id<int>
456
+ const size_t NumParams = 4 ;
456
457
llvm::SmallVector<DeclRefExpr *, NumParams> ParamDREs (NumParams);
457
458
auto TFP = TargetFuncParam;
458
459
for (size_t I = 0 ; I < NumParams; ++TFP, ++I) {
@@ -495,7 +496,7 @@ CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelCallerFunc, DeclContext *DC) {
495
496
ExprValueKind VK = Expr::getValueKindForType (ResultTy);
496
497
ResultTy = ResultTy.getNonLValueExprType (S.Context );
497
498
498
- // __init needs three parameter
499
+ // __init needs four parameter
499
500
auto ParamItr = InitMethod->param_begin ();
500
501
// kernel_parameters
501
502
llvm::SmallVector<Expr *, NumParams> ParamStmts;
@@ -505,7 +506,10 @@ CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelCallerFunc, DeclContext *DC) {
505
506
S, ((*ParamItr++))->getOriginalType (), ParamDREs[1 ]));
506
507
ParamStmts.push_back (getExprForRangeOrOffset (
507
508
S, ((*ParamItr++))->getOriginalType (), ParamDREs[2 ]));
508
- // kernel_obj.accessor.__init(_ValueType*, range<int>, id<int>)
509
+ ParamStmts.push_back (getExprForRangeOrOffset (
510
+ S, ((*ParamItr++))->getOriginalType (), ParamDREs[3 ]));
511
+ // kernel_obj.accessor.__init(_ValueType*, range<int>, range<int>,
512
+ // id<int>)
509
513
CXXMemberCallExpr *Call = CXXMemberCallExpr::Create (
510
514
S.Context , ME, ParamStmts, ResultTy, VK, SourceLocation ());
511
515
BodyStmts.push_back (Call);
@@ -643,10 +647,17 @@ static void buildArgTys(ASTContext &Context, CXXRecordDecl *KernelObj,
643
647
644
648
CreateAndAddPrmDsc (Fld, PointerType);
645
649
646
- FieldDecl *RangeFld = getFieldDeclByName (RecordDecl, {" __impl" , " Range" });
647
- assert (RangeFld &&
648
- " The accessor must contain the Range from the __impl field" );
649
- CreateAndAddPrmDsc (RangeFld, RangeFld->getType ());
650
+ FieldDecl *AccessRangeFld =
651
+ getFieldDeclByName (RecordDecl, {" __impl" , " AccessRange" });
652
+ assert (AccessRangeFld &&
653
+ " The accessor must contain the AccessRange from the __impl field" );
654
+ CreateAndAddPrmDsc (AccessRangeFld, AccessRangeFld->getType ());
655
+
656
+ FieldDecl *MemRangeFld =
657
+ getFieldDeclByName (RecordDecl, {" __impl" , " MemRange" });
658
+ assert (MemRangeFld &&
659
+ " The accessor must contain the MemRange from the __impl field" );
660
+ CreateAndAddPrmDsc (MemRangeFld, MemRangeFld->getType ());
650
661
651
662
FieldDecl *OffsetFld =
652
663
getFieldDeclByName (RecordDecl, {" __impl" , " Offset" });
@@ -705,13 +716,22 @@ static void populateIntHeader(SYCLIntegrationHeader &H, const StringRef Name,
705
716
const auto *AccTmplTy = cast<ClassTemplateSpecializationDecl>(AccTy);
706
717
H.addParamDesc (SYCLIntegrationHeader::kind_accessor,
707
718
getAccessTarget (AccTmplTy), Offset);
708
- // ... second descriptor (translated to range kernel parameter):
709
- FieldDecl *RngFld =
710
- getFieldDeclByName (AccTy, {" __impl" , " Range" }, &Offset);
711
- uint64_t Sz = Ctx.getTypeSizeInChars (RngFld->getType ()).getQuantity ();
719
+ // ... second descriptor (translated to access range kernel parameter):
720
+ FieldDecl *AccessRngFld =
721
+ getFieldDeclByName (AccTy, {" __impl" , " AccessRange" }, &Offset);
722
+ uint64_t Sz =
723
+ Ctx.getTypeSizeInChars (AccessRngFld->getType ()).getQuantity ();
724
+ H.addParamDesc (SYCLIntegrationHeader::kind_std_layout,
725
+ static_cast <unsigned >(Sz), static_cast <unsigned >(Offset));
726
+ // ... third descriptor (translated to mem range kernel parameter):
727
+ // Get offset in bytes
728
+ Offset = Layout.getFieldOffset (Fld->getFieldIndex ()) / 8 ;
729
+ FieldDecl *MemRngFld =
730
+ getFieldDeclByName (AccTy, {" __impl" , " MemRange" }, &Offset);
731
+ Sz = Ctx.getTypeSizeInChars (MemRngFld->getType ()).getQuantity ();
712
732
H.addParamDesc (SYCLIntegrationHeader::kind_std_layout,
713
733
static_cast <unsigned >(Sz), static_cast <unsigned >(Offset));
714
- // ... third descriptor (translated to id kernel parameter):
734
+ // ... fourth descriptor (translated to id kernel parameter):
715
735
// Get offset in bytes
716
736
Offset = Layout.getFieldOffset (Fld->getFieldIndex ()) / 8 ;
717
737
FieldDecl *OffstFld =
0 commit comments