Skip to content

Commit 5f7b808

Browse files
author
Erich Keane
committed
@elizabethandrews ' comments
1 parent 587cc77 commit 5f7b808

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
16741674
// Contains a count of how many containers we're in. This is used by the
16751675
// pointer-struct-wrapping code to ensure that we don't try to wrap
16761676
// non-top-level pointers.
1677-
uint64_t ContainerDepth = 0;
1677+
uint64_t StructDepth = 0;
16781678

16791679
// Using the statements/init expressions that we've created, this generates
16801680
// the kernel body compound stmt. CompoundStmt needs to know its number of
@@ -2018,7 +2018,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
20182018

20192019
bool handlePointerType(FieldDecl *FD, QualType FieldTy) final {
20202020
Expr *PointerRef =
2021-
createPointerParamReferenceExpr(FD->getType(), ContainerDepth != 0);
2021+
createPointerParamReferenceExpr(FD->getType(), StructDepth != 0);
20222022
addFieldInit(FD, FieldTy, PointerRef);
20232023
return true;
20242024
}
@@ -2034,7 +2034,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
20342034
}
20352035

20362036
bool enterStream(const CXXRecordDecl *RD, FieldDecl *FD, QualType Ty) final {
2037-
++ContainerDepth;
2037+
++StructDepth;
20382038
// Add a dummy init expression to catch the accessor initializers.
20392039
const auto *StreamDecl = Ty->getAsCXXRecordDecl();
20402040
CollectionInitExprs.push_back(createInitListExpr(StreamDecl));
@@ -2044,7 +2044,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
20442044
}
20452045

20462046
bool leaveStream(const CXXRecordDecl *RD, FieldDecl *FD, QualType Ty) final {
2047-
--ContainerDepth;
2047+
--StructDepth;
20482048
// Stream requires that its 'init' calls happen after its accessors init
20492049
// calls, so add them here instead.
20502050
const auto *StreamDecl = Ty->getAsCXXRecordDecl();
@@ -2059,15 +2059,15 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
20592059
}
20602060

20612061
bool enterStruct(const CXXRecordDecl *RD, FieldDecl *FD, QualType Ty) final {
2062-
++ContainerDepth;
2062+
++StructDepth;
20632063
addCollectionInitListExpr(Ty->getAsCXXRecordDecl());
20642064

20652065
addFieldMemberExpr(FD, Ty);
20662066
return true;
20672067
}
20682068

20692069
bool leaveStruct(const CXXRecordDecl *, FieldDecl *FD, QualType Ty) final {
2070-
--ContainerDepth;
2070+
--StructDepth;
20712071
CollectionInitExprs.pop_back();
20722072

20732073
removeFieldMemberExpr(FD, Ty);
@@ -2076,7 +2076,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
20762076

20772077
bool enterStruct(const CXXRecordDecl *RD, const CXXBaseSpecifier &BS,
20782078
QualType) final {
2079-
++ContainerDepth;
2079+
++StructDepth;
20802080

20812081
CXXCastPath BasePath;
20822082
QualType DerivedTy(RD->getTypeForDecl(), 0);
@@ -2095,7 +2095,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
20952095

20962096
bool leaveStruct(const CXXRecordDecl *RD, const CXXBaseSpecifier &BS,
20972097
QualType) final {
2098-
--ContainerDepth;
2098+
--StructDepth;
20992099
MemberExprBases.pop_back();
21002100
CollectionInitExprs.pop_back();
21012101
return true;
@@ -2250,6 +2250,11 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
22502250
const ParmVarDecl *SamplerArg = InitMethod->getParamDecl(0);
22512251
assert(SamplerArg && "sampler __init method must have sampler parameter");
22522252

2253+
// For samplers, we do some special work to ONLY initialize the first item
2254+
// to the InitMethod as a performance improvement presumably, so the normal
2255+
// offsetOf calculation wouldn't work correctly. Therefore, we need to call
2256+
// a version of addParam where we calculate the offset based on the true
2257+
// FieldDecl/FieldType pair, rather than the SampleArg type.
22532258
addParam(FD, SamplerArg->getType(), SYCLIntegrationHeader::kind_sampler,
22542259
offsetOf(FD, FieldTy));
22552260
return true;

0 commit comments

Comments
 (0)