Skip to content

Commit 8924fcc

Browse files
authored
[SYCL] Do not treat sycl::half kernel argument specially (#5812)
There was some special handling added when all struct kernel arguments were decomposed since OpenCL doesn't allow half kernel argument. Once we've implemented conditional decomposition no special handling needed for half type.
1 parent 18f873d commit 8924fcc

File tree

2 files changed

+2
-64
lines changed

2 files changed

+2
-64
lines changed

clang/lib/Sema/SemaSYCL.cpp

-62
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ class Util {
9292

9393
static bool isSyclSpecialType(QualType Ty);
9494

95-
/// Checks whether given clang type is a full specialization of the SYCL
96-
/// half class.
97-
static bool isSyclHalfType(QualType Ty);
98-
9995
/// Checks whether given clang type is a full specialization of the SYCL
10096
/// accessor_property_list class.
10197
static bool isAccessorPropertyListType(QualType Ty);
@@ -1313,8 +1309,6 @@ class KernelObjVisitor {
13131309
QualType FieldTy, HandlerTys &... Handlers) {
13141310
if (Util::isSyclSpecialType(FieldTy))
13151311
KF_FOR_EACH(handleSyclSpecialType, Field, FieldTy);
1316-
else if (Util::isSyclHalfType(FieldTy))
1317-
KF_FOR_EACH(handleSyclHalfType, Field, FieldTy);
13181312
else if (Util::isSyclSpecConstantType(FieldTy))
13191313
KF_FOR_EACH(handleSyclSpecConstantType, Field, FieldTy);
13201314
else if (FieldTy->isStructureOrClassType()) {
@@ -1383,11 +1377,6 @@ class SyclKernelFieldHandlerBase {
13831377
return true;
13841378
}
13851379

1386-
virtual bool handleSyclHalfType(const CXXRecordDecl *,
1387-
const CXXBaseSpecifier &, QualType) {
1388-
return true;
1389-
}
1390-
virtual bool handleSyclHalfType(FieldDecl *, QualType) { return true; }
13911380
virtual bool handleStructType(FieldDecl *, QualType) { return true; }
13921381
virtual bool handleUnionType(FieldDecl *, QualType) { return true; }
13931382
virtual bool handleReferenceType(FieldDecl *, QualType) { return true; }
@@ -1815,16 +1804,6 @@ class SyclKernelDecompMarker : public SyclKernelFieldHandler {
18151804
return true;
18161805
}
18171806

1818-
bool handleSyclHalfType(const CXXRecordDecl *, const CXXBaseSpecifier &,
1819-
QualType) final {
1820-
CollectionStack.back() = true;
1821-
return true;
1822-
}
1823-
bool handleSyclHalfType(FieldDecl *, QualType) final {
1824-
CollectionStack.back() = true;
1825-
return true;
1826-
}
1827-
18281807
bool handlePointerType(FieldDecl *, QualType) final {
18291808
CollectionStack.back() = true;
18301809
return true;
@@ -2230,11 +2209,6 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
22302209
return handleScalarType(FD, FieldTy);
22312210
}
22322211

2233-
bool handleSyclHalfType(FieldDecl *FD, QualType FieldTy) final {
2234-
addParam(FD, FieldTy);
2235-
return true;
2236-
}
2237-
22382212
// Generate kernel argument to initialize specialization constants.
22392213
void handleSyclKernelHandlerType() {
22402214
ASTContext &Context = SemaRef.getASTContext();
@@ -2251,7 +2225,6 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
22512225
return ArrayRef<ParmVarDecl *>(std::begin(Params) + LastParamIndex,
22522226
std::end(Params));
22532227
}
2254-
using SyclKernelFieldHandler::handleSyclHalfType;
22552228
};
22562229

22572230
class SyclKernelArgsSizeChecker : public SyclKernelFieldHandler {
@@ -2328,12 +2301,6 @@ class SyclKernelArgsSizeChecker : public SyclKernelFieldHandler {
23282301
bool handleUnionType(FieldDecl *FD, QualType FieldTy) final {
23292302
return handleScalarType(FD, FieldTy);
23302303
}
2331-
2332-
bool handleSyclHalfType(FieldDecl *FD, QualType FieldTy) final {
2333-
addParam(FieldTy);
2334-
return true;
2335-
}
2336-
using SyclKernelFieldHandler::handleSyclHalfType;
23372304
};
23382305

23392306
std::string getKernelArgDesc(StringRef KernelArgDescription) {
@@ -2476,16 +2443,10 @@ class SyclOptReportCreator : public SyclKernelFieldHandler {
24762443
return handleScalarType(FD, FieldTy);
24772444
}
24782445

2479-
bool handleSyclHalfType(FieldDecl *FD, QualType FieldTy) final {
2480-
addParam(FD, FieldTy);
2481-
return true;
2482-
}
2483-
24842446
void handleSyclKernelHandlerType() {
24852447
addParam(DC.getParamVarDeclsForCurrentField()[0]->getType(),
24862448
"SYCL2020 specialization constant");
24872449
}
2488-
using SyclKernelFieldHandler::handleSyclHalfType;
24892450
};
24902451

24912452
static CXXMethodDecl *getOperatorParens(const CXXRecordDecl *Rec) {
@@ -2940,11 +2901,6 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
29402901
return handleSpecialType(FD, Ty);
29412902
}
29422903

2943-
bool handleSyclHalfType(FieldDecl *FD, QualType Ty) final {
2944-
addSimpleFieldInit(FD, Ty);
2945-
return true;
2946-
}
2947-
29482904
bool handlePointerType(FieldDecl *FD, QualType FieldTy) final {
29492905
Expr *PointerRef =
29502906
createPointerParamReferenceExpr(FieldTy, StructDepth != 0);
@@ -3102,8 +3058,6 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
31023058
removeFieldMemberExpr(FD, ArrayType);
31033059
return true;
31043060
}
3105-
3106-
using SyclKernelFieldHandler::handleSyclHalfType;
31073061
};
31083062

31093063
// Kernels are only the unnamed-lambda feature if the feature is enabled, AND
@@ -3263,11 +3217,6 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
32633217
return handleScalarType(FD, FieldTy);
32643218
}
32653219

3266-
bool handleSyclHalfType(FieldDecl *FD, QualType FieldTy) final {
3267-
addParam(FD, FieldTy, SYCLIntegrationHeader::kind_std_layout);
3268-
return true;
3269-
}
3270-
32713220
void handleSyclKernelHandlerType(QualType Ty) {
32723221
// The compiler generated kernel argument used to initialize SYCL 2020
32733222
// specialization constants, `specialization_constants_buffer`, should
@@ -3321,7 +3270,6 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
33213270
}
33223271

33233272
using SyclKernelFieldHandler::enterStruct;
3324-
using SyclKernelFieldHandler::handleSyclHalfType;
33253273
using SyclKernelFieldHandler::leaveStruct;
33263274
};
33273275

@@ -5158,16 +5106,6 @@ bool Util::isSyclSpecialType(const QualType Ty) {
51585106
return RecTy->hasAttr<SYCLSpecialClassAttr>();
51595107
}
51605108

5161-
bool Util::isSyclHalfType(QualType Ty) {
5162-
std::array<DeclContextDesc, 5> Scopes = {
5163-
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "cl"),
5164-
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "sycl"),
5165-
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "detail"),
5166-
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "half_impl"),
5167-
Util::MakeDeclContextDesc(Decl::Kind::CXXRecord, "half")};
5168-
return matchQualifiedTypeName(Ty, Scopes);
5169-
}
5170-
51715109
bool Util::isSyclSpecConstantType(QualType Ty) {
51725110
std::array<DeclContextDesc, 6> Scopes = {
51735111
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "cl"),

clang/test/SemaSYCL/decomposition.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ int main() {
144144
myQueue.submit([&](sycl::handler &h) {
145145
h.single_task<class Half1>([=]() { return t1.i; });
146146
});
147-
// CHECK: FunctionDecl {{.*}}Half1{{.*}} 'void (sycl::half, sycl::half, sycl::half, StructNonDecomposed, int)'
147+
// CHECK: FunctionDecl {{.*}}Half1{{.*}} 'void (StructWithArray<StructWithHalf>)'
148148

149149
DerivedStruct<StructWithHalf> t2;
150150
myQueue.submit([&](sycl::handler &h) {
151151
h.single_task<class Half2>([=]() { return t2.i; });
152152
});
153-
// CHECK: FunctionDecl {{.*}}Half2{{.*}} 'void (sycl::half, StructNonDecomposed, int)'
153+
// CHECK: FunctionDecl {{.*}}Half2{{.*}} 'void (DerivedStruct<StructWithHalf>)'
154154
}
155155
}

0 commit comments

Comments
 (0)