Skip to content

Commit b2f3950

Browse files
[SYCL] Add kernel object to Kernel function and integration header
Signed-off-by: Elizabeth Andrews <[email protected]>
1 parent 7e3cca4 commit b2f3950

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,15 @@ static ParamDesc makeParamDesc(const FieldDecl *Src, QualType Ty) {
628628
Ctx.getTrivialTypeSourceInfo(Ty));
629629
}
630630

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+
631640
static ParamDesc makeParamDesc(ASTContext &Ctx, const CXXBaseSpecifier &Src,
632641
QualType Ty) {
633642
// TODO: There is no name for the base available, but duplicate names are
@@ -721,12 +730,17 @@ static void VisitAccessorWrapper(CXXRecordDecl *Owner, ParentTy &Parent,
721730
// A visitor function that dispatches to functions as defined in
722731
// SyclKernelFieldHandler for the purposes of kernel generation.
723732
template <typename... Handlers>
724-
static void VisitRecordFields(RecordDecl::field_range Fields,
733+
static void VisitRecordFields(CXXRecordDecl *KernelObject,
725734
Handlers &... handlers) {
735+
736+
QualType KernelType = QualType(KernelObject->getTypeForDecl(), 0);
737+
(void)std::initializer_list<int>{
738+
(handlers.handleKernelObject(KernelObject, KernelType), 0)...};
739+
726740
#define KF_FOR_EACH(FUNC) \
727741
(void)std::initializer_list<int> { (handlers.FUNC(Field, FieldTy), 0)... }
728742

729-
for (const auto &Field : Fields) {
743+
for (const auto &Field : KernelObject->fields()) {
730744
QualType FieldTy = Field->getType();
731745

732746
if (Util::isSyclAccessorType(FieldTy))
@@ -781,6 +795,7 @@ template <typename Derived> class SyclKernelFieldHandler {
781795
virtual void handlePointerType(FieldDecl *, QualType) {}
782796
virtual void handleArrayType(FieldDecl *, QualType) {}
783797
virtual void handleScalarType(FieldDecl *, QualType) {}
798+
virtual void handleKernelObject(CXXRecordDecl *, QualType) {}
784799
// Most handlers shouldn't be handling this, just the field checker.
785800
virtual void handleOtherType(FieldDecl *, QualType) {}
786801

@@ -830,6 +845,10 @@ class SyclKernelFieldChecker
830845
<< 1 << FieldTy;
831846
}
832847
}
848+
void handleKernelObject(CXXRecordDecl *KernelObject,
849+
QualType KernelType) final {
850+
// Do we need any diagnostics for Kernel Object?
851+
}
833852

834853
// We should be able to handle this, so we made it part of the visitor, but
835854
// this is 'to be implemented'.
@@ -860,6 +879,11 @@ class SyclKernelDeclCreator
860879
addParam(newParamDesc, FieldTy);
861880
}
862881

882+
void addParam(const CXXRecordDecl *KernelObject, QualType KernelType) {
883+
ParamDesc newParamDesc = makeParamDesc(KernelObject, KernelType);
884+
addParam(newParamDesc, KernelType);
885+
}
886+
863887
void addParam(const CXXBaseSpecifier &BS, QualType FieldTy) {
864888
ParamDesc newParamDesc =
865889
makeParamDesc(SemaRef.getASTContext(), BS, FieldTy);
@@ -1002,6 +1026,11 @@ class SyclKernelDeclCreator
10021026
// See https://github.com/intel/llvm/issues/1552
10031027
}
10041028

1029+
void handleKernelObject(CXXRecordDecl *KernelObject,
1030+
QualType KernelType) final {
1031+
addParam(KernelObject, KernelType);
1032+
}
1033+
10051034
void setBody(CompoundStmt *KB) { KernelDecl->setBody(KB); }
10061035

10071036
FunctionDecl *getKernelDecl() { return KernelDecl; }
@@ -1376,6 +1405,14 @@ class SyclKernelIntHeaderCreator
13761405
CurStruct = FD->getType()->getAsCXXRecordDecl();
13771406
CurOffset += SemaRef.getASTContext().getFieldOffset(FD) / 8;
13781407
}
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+
}
13791416

13801417
void leaveStruct(const CXXRecordDecl *RD, FieldDecl *FD) final {
13811418
CurStruct = RD;
@@ -1447,7 +1484,7 @@ void Sema::ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc,
14471484
StableName);
14481485

14491486
ConstructingOpenCLKernel = true;
1450-
VisitRecordFields(KernelLambda->fields(), checker, kernel_decl, kernel_body,
1487+
VisitRecordFields(KernelLambda, checker, kernel_decl, kernel_body,
14511488
int_header);
14521489
ConstructingOpenCLKernel = false;
14531490
}

0 commit comments

Comments
 (0)