@@ -1034,23 +1034,6 @@ class KernelObjVisitor {
1034
1034
VisitRecordFields (Owner, Handlers...);
1035
1035
}
1036
1036
1037
- // FIXME: Can this be refactored/handled some other way?
1038
- template <typename ParentTy, typename ... HandlerTys>
1039
- void visitStreamRecord (const CXXRecordDecl *Owner, ParentTy &Parent,
1040
- CXXRecordDecl *Wrapper, QualType RecordTy,
1041
- HandlerTys &... Handlers) {
1042
- (void )std::initializer_list<int >{
1043
- (Handlers.enterStream (Owner, Parent, RecordTy), 0 )...};
1044
- for (const auto &Field : Wrapper->fields ()) {
1045
- QualType FieldTy = Field->getType ();
1046
- // Required to initialize accessors inside streams.
1047
- if (Util::isSyclAccessorType (FieldTy))
1048
- KF_FOR_EACH (handleSyclAccessorType, Field, FieldTy);
1049
- }
1050
- (void )std::initializer_list<int >{
1051
- (Handlers.leaveStream (Owner, Parent, RecordTy), 0 )...};
1052
- }
1053
-
1054
1037
template <typename ... HandlerTys>
1055
1038
void visitArrayElementImpl (const CXXRecordDecl *Owner, FieldDecl *ArrayField,
1056
1039
QualType ElementTy, uint64_t Index,
@@ -1125,12 +1108,9 @@ class KernelObjVisitor {
1125
1108
KF_FOR_EACH (handleSyclHalfType, Field, FieldTy);
1126
1109
else if (Util::isSyclSpecConstantType (FieldTy))
1127
1110
KF_FOR_EACH (handleSyclSpecConstantType, Field, FieldTy);
1128
- else if (Util::isSyclStreamType (FieldTy)) {
1129
- CXXRecordDecl *RD = FieldTy->getAsCXXRecordDecl ();
1130
- // Handle accessors in stream class.
1111
+ else if (Util::isSyclStreamType (FieldTy))
1131
1112
KF_FOR_EACH (handleSyclStreamType, Field, FieldTy);
1132
- visitStreamRecord (Owner, Field, RD, FieldTy, Handlers...);
1133
- } else if (FieldTy->isStructureOrClassType ()) {
1113
+ else if (FieldTy->isStructureOrClassType ()) {
1134
1114
if (KF_FOR_EACH (handleStructType, Field, FieldTy)) {
1135
1115
CXXRecordDecl *RD = FieldTy->getAsCXXRecordDecl ();
1136
1116
visitRecord (Owner, Field, RD, FieldTy, Handlers...);
@@ -1244,12 +1224,6 @@ class SyclKernelFieldHandlerBase {
1244
1224
virtual bool leaveStruct (const CXXRecordDecl *, FieldDecl *, QualType) {
1245
1225
return true ;
1246
1226
}
1247
- virtual bool enterStream (const CXXRecordDecl *, FieldDecl *, QualType) {
1248
- return true ;
1249
- }
1250
- virtual bool leaveStream (const CXXRecordDecl *, FieldDecl *, QualType) {
1251
- return true ;
1252
- }
1253
1227
virtual bool enterStruct (const CXXRecordDecl *, const CXXBaseSpecifier &,
1254
1228
QualType) {
1255
1229
return true ;
@@ -1697,18 +1671,6 @@ class SyclKernelDecompMarker : public SyclKernelFieldHandler {
1697
1671
return true ;
1698
1672
}
1699
1673
1700
- // Stream is always decomposed (and whether it gets decomposed is handled in
1701
- // handleSyclStreamType), but we need a CollectionStack entry to capture the
1702
- // accessors that get handled.
1703
- bool enterStream (const CXXRecordDecl *, FieldDecl *, QualType) final {
1704
- CollectionStack.push_back (false );
1705
- return true ;
1706
- }
1707
- bool leaveStream (const CXXRecordDecl *, FieldDecl *, QualType Ty) final {
1708
- CollectionStack.pop_back ();
1709
- return true ;
1710
- }
1711
-
1712
1674
bool enterStruct (const CXXRecordDecl *, FieldDecl *, QualType) final {
1713
1675
CollectionStack.push_back (false );
1714
1676
return true ;
@@ -1956,14 +1918,6 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
1956
1918
SemaRef.addSyclDeviceDecl (KernelDecl);
1957
1919
}
1958
1920
1959
- bool enterStream (const CXXRecordDecl *RD, FieldDecl *FD, QualType Ty) final {
1960
- return enterStruct (RD, FD, Ty);
1961
- }
1962
-
1963
- bool leaveStream (const CXXRecordDecl *RD, FieldDecl *FD, QualType Ty) final {
1964
- return leaveStruct (RD, FD, Ty);
1965
- }
1966
-
1967
1921
bool enterStruct (const CXXRecordDecl *, FieldDecl *, QualType) final {
1968
1922
++StructDepth;
1969
1923
return true ;
@@ -2099,8 +2053,7 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
2099
2053
}
2100
2054
2101
2055
bool handleSyclStreamType (FieldDecl *FD, QualType FieldTy) final {
2102
- addParam (FD, FieldTy);
2103
- return true ;
2056
+ return handleSpecialType (FD, FieldTy);
2104
2057
}
2105
2058
2106
2059
bool handleSyclStreamType (const CXXRecordDecl *, const CXXBaseSpecifier &,
@@ -2419,15 +2372,6 @@ class SyclOptReportCreator : public SyclKernelFieldHandler {
2419
2372
}
2420
2373
2421
2374
bool handleSyclStreamType (FieldDecl *FD, QualType FieldTy) final {
2422
- // For the current implementation of stream class, the Visitor 'handles'
2423
- // stream argument and then visits each accessor field in stream. Therefore
2424
- // handleSpecialType in this case only adds a single argument for stream.
2425
- // The arguments corresponding to accessors in stream are handled in
2426
- // handleSyclAccessorType. The opt-report therefore does not diffrentiate
2427
- // between the accessors in streams and accessors captured by SYCL kernel.
2428
- // Once stream API is modified to use __init(), the visitor will no longer
2429
- // visit the stream object and opt-report output for stream class will be
2430
- // similar to that of other special types.
2431
2375
return handleSpecialType (
2432
2376
FD, FieldTy, KernelArgDescription (KernelArgDescription::Stream));
2433
2377
}
@@ -2805,6 +2749,13 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
2805
2749
2806
2750
const auto *RecordDecl = Ty->getAsCXXRecordDecl ();
2807
2751
createSpecialMethodCall (RecordDecl, getInitMethodName (), BodyStmts);
2752
+ CXXMethodDecl *FinalizeMethod =
2753
+ getMethodByName (RecordDecl, FinalizeMethodName);
2754
+ // A finalize-method is expected for stream class.
2755
+ if (!FinalizeMethod && Util::isSyclStreamType (Ty))
2756
+ SemaRef.Diag (FD->getLocation (), diag::err_sycl_expected_finalize_method);
2757
+ else
2758
+ createSpecialMethodCall (RecordDecl, FinalizeMethodName, FinalizeStmts);
2808
2759
2809
2760
removeFieldMemberExpr (FD, Ty);
2810
2761
@@ -2898,9 +2849,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
2898
2849
}
2899
2850
2900
2851
bool handleSyclStreamType (FieldDecl *FD, QualType Ty) final {
2901
- // Streams just get copied as a new init.
2902
- addSimpleFieldInit (FD, Ty);
2903
- return true ;
2852
+ return handleSpecialType (FD, Ty);
2904
2853
}
2905
2854
2906
2855
bool handleSyclStreamType (const CXXRecordDecl *, const CXXBaseSpecifier &BS,
@@ -2977,31 +2926,6 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
2977
2926
handleSpecialType (KernelHandlerArg->getType ());
2978
2927
}
2979
2928
2980
- bool enterStream (const CXXRecordDecl *RD, FieldDecl *FD, QualType Ty) final {
2981
- ++StructDepth;
2982
- // Add a dummy init expression to catch the accessor initializers.
2983
- const auto *StreamDecl = Ty->getAsCXXRecordDecl ();
2984
- CollectionInitExprs.push_back (createInitListExpr (StreamDecl));
2985
-
2986
- addFieldMemberExpr (FD, Ty);
2987
- return true ;
2988
- }
2989
-
2990
- bool leaveStream (const CXXRecordDecl *RD, FieldDecl *FD, QualType Ty) final {
2991
- --StructDepth;
2992
- // Stream requires that its 'init' calls happen after its accessors init
2993
- // calls, so add them here instead.
2994
- const auto *StreamDecl = Ty->getAsCXXRecordDecl ();
2995
-
2996
- createSpecialMethodCall (StreamDecl, getInitMethodName (), BodyStmts);
2997
- createSpecialMethodCall (StreamDecl, FinalizeMethodName, FinalizeStmts);
2998
-
2999
- removeFieldMemberExpr (FD, Ty);
3000
-
3001
- CollectionInitExprs.pop_back ();
3002
- return true ;
3003
- }
3004
-
3005
2929
bool enterStruct (const CXXRecordDecl *RD, FieldDecl *FD, QualType Ty) final {
3006
2930
++StructDepth;
3007
2931
addCollectionInitListExpr (Ty->getAsCXXRecordDecl ());
@@ -3315,7 +3239,7 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
3315
3239
}
3316
3240
3317
3241
bool handleSyclStreamType (FieldDecl *FD, QualType FieldTy) final {
3318
- addParam (FD, FieldTy, SYCLIntegrationHeader::kind_std_layout );
3242
+ addParam (FD, FieldTy, SYCLIntegrationHeader::kind_stream );
3319
3243
return true ;
3320
3244
}
3321
3245
@@ -3347,18 +3271,6 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
3347
3271
SYCLIntegrationHeader::kind_specialization_constants_buffer, 0 );
3348
3272
}
3349
3273
3350
- bool enterStream (const CXXRecordDecl *, FieldDecl *FD, QualType Ty) final {
3351
- ++StructDepth;
3352
- CurOffset += offsetOf (FD, Ty);
3353
- return true ;
3354
- }
3355
-
3356
- bool leaveStream (const CXXRecordDecl *, FieldDecl *FD, QualType Ty) final {
3357
- --StructDepth;
3358
- CurOffset -= offsetOf (FD, Ty);
3359
- return true ;
3360
- }
3361
-
3362
3274
bool enterStruct (const CXXRecordDecl *, FieldDecl *FD, QualType Ty) final {
3363
3275
++StructDepth;
3364
3276
CurOffset += offsetOf (FD, Ty);
@@ -4160,6 +4072,7 @@ static const char *paramKind2Str(KernelParamKind K) {
4160
4072
CASE (accessor);
4161
4073
CASE (std_layout);
4162
4074
CASE (sampler);
4075
+ CASE (stream);
4163
4076
CASE (specialization_constants_buffer);
4164
4077
CASE (pointer);
4165
4078
}
0 commit comments