@@ -628,6 +628,15 @@ static ParamDesc makeParamDesc(const FieldDecl *Src, QualType Ty) {
628
628
Ctx.getTrivialTypeSourceInfo (Ty));
629
629
}
630
630
631
+ // Creates a parameter descriptor for kernel object
632
+ static ParamDesc makeParamDesc (const CXXRecordDecl *Src, QualType Ty) {
633
+ ASTContext &Ctx = Src->getASTContext ();
634
+ // Should the name of parameter be fixed as _arg_kernel_object?
635
+ std::string Name = (Twine (" _arg_" ) + Src->getName ()).str ();
636
+ return std::make_tuple (Ty, &Ctx.Idents .get (Name),
637
+ Ctx.getTrivialTypeSourceInfo (Ty));
638
+ }
639
+
631
640
static ParamDesc makeParamDesc (ASTContext &Ctx, const CXXBaseSpecifier &Src,
632
641
QualType Ty) {
633
642
// TODO: There is no name for the base available, but duplicate names are
@@ -721,12 +730,17 @@ static void VisitAccessorWrapper(CXXRecordDecl *Owner, ParentTy &Parent,
721
730
// A visitor function that dispatches to functions as defined in
722
731
// SyclKernelFieldHandler for the purposes of kernel generation.
723
732
template <typename ... Handlers>
724
- static void VisitRecordFields (RecordDecl::field_range Fields ,
733
+ static void VisitRecordFields (CXXRecordDecl *KernelObject ,
725
734
Handlers &... handlers) {
735
+
736
+ QualType KernelType = QualType (KernelObject->getTypeForDecl (), 0 );
737
+ (void )std::initializer_list<int >{
738
+ (handlers.handleKernelObject (KernelObject, KernelType), 0 )...};
739
+
726
740
#define KF_FOR_EACH (FUNC ) \
727
741
(void )std::initializer_list<int > { (handlers.FUNC (Field, FieldTy), 0 )... }
728
742
729
- for (const auto &Field : Fields ) {
743
+ for (const auto &Field : KernelObject-> fields () ) {
730
744
QualType FieldTy = Field->getType ();
731
745
732
746
if (Util::isSyclAccessorType (FieldTy))
@@ -781,6 +795,7 @@ template <typename Derived> class SyclKernelFieldHandler {
781
795
virtual void handlePointerType (FieldDecl *, QualType) {}
782
796
virtual void handleArrayType (FieldDecl *, QualType) {}
783
797
virtual void handleScalarType (FieldDecl *, QualType) {}
798
+ virtual void handleKernelObject (CXXRecordDecl *, QualType) {}
784
799
// Most handlers shouldn't be handling this, just the field checker.
785
800
virtual void handleOtherType (FieldDecl *, QualType) {}
786
801
@@ -830,6 +845,10 @@ class SyclKernelFieldChecker
830
845
<< 1 << FieldTy;
831
846
}
832
847
}
848
+ void handleKernelObject (CXXRecordDecl *KernelObject,
849
+ QualType KernelType) final {
850
+ // Do we need any diagnostics for Kernel Object?
851
+ }
833
852
834
853
// We should be able to handle this, so we made it part of the visitor, but
835
854
// this is 'to be implemented'.
@@ -860,6 +879,11 @@ class SyclKernelDeclCreator
860
879
addParam (newParamDesc, FieldTy);
861
880
}
862
881
882
+ void addParam (const CXXRecordDecl *KernelObject, QualType KernelType) {
883
+ ParamDesc newParamDesc = makeParamDesc (KernelObject, KernelType);
884
+ addParam (newParamDesc, KernelType);
885
+ }
886
+
863
887
void addParam (const CXXBaseSpecifier &BS, QualType FieldTy) {
864
888
ParamDesc newParamDesc =
865
889
makeParamDesc (SemaRef.getASTContext (), BS, FieldTy);
@@ -1002,6 +1026,11 @@ class SyclKernelDeclCreator
1002
1026
// See https://github.com/intel/llvm/issues/1552
1003
1027
}
1004
1028
1029
+ void handleKernelObject (CXXRecordDecl *KernelObject,
1030
+ QualType KernelType) final {
1031
+ addParam (KernelObject, KernelType);
1032
+ }
1033
+
1005
1034
void setBody (CompoundStmt *KB) { KernelDecl->setBody (KB); }
1006
1035
1007
1036
FunctionDecl *getKernelDecl () { return KernelDecl; }
@@ -1376,6 +1405,14 @@ class SyclKernelIntHeaderCreator
1376
1405
CurStruct = FD->getType ()->getAsCXXRecordDecl ();
1377
1406
CurOffset += SemaRef.getASTContext ().getFieldOffset (FD) / 8 ;
1378
1407
}
1408
+ void handleKernelObject (CXXRecordDecl *KernelObject,
1409
+ QualType KernelType) final {
1410
+ uint64_t Size =
1411
+ SemaRef.getASTContext ().getTypeSizeInChars (KernelType).getQuantity ();
1412
+ // Offset for kernel object is 0
1413
+ Header.addParamDesc (SYCLIntegrationHeader::kind_std_layout,
1414
+ static_cast <unsigned >(Size), 0 );
1415
+ }
1379
1416
1380
1417
void leaveStruct (const CXXRecordDecl *RD, FieldDecl *FD) final {
1381
1418
CurStruct = RD;
@@ -1447,7 +1484,7 @@ void Sema::ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc,
1447
1484
StableName);
1448
1485
1449
1486
ConstructingOpenCLKernel = true ;
1450
- VisitRecordFields (KernelLambda-> fields () , checker, kernel_decl, kernel_body,
1487
+ VisitRecordFields (KernelLambda, checker, kernel_decl, kernel_body,
1451
1488
int_header);
1452
1489
ConstructingOpenCLKernel = false ;
1453
1490
}
0 commit comments