Skip to content

Commit d78b932

Browse files
committed
Improve tests for special type parameters for free function kernels
1 parent b23734f commit d78b932

File tree

8 files changed

+348
-103
lines changed

8 files changed

+348
-103
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,17 +2092,7 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
20922092
}
20932093

20942094
bool handleSyclSpecialType(ParmVarDecl *PD, QualType ParamTy) final {
2095-
<<<<<<< HEAD
20962095
IsInvalid |= checkSyclSpecialType(ParamTy, PD->getLocation());
2097-
=======
2098-
if (!SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::work_group_memory) &&
2099-
!SemaSYCL::isSyclType(ParamTy,
2100-
SYCLTypeAttr::dynamic_work_group_memory)) {
2101-
Diag.Report(PD->getLocation(), diag::err_bad_kernel_param_type)
2102-
<< ParamTy;
2103-
IsInvalid = true;
2104-
}
2105-
>>>>>>> 8113cb9ccb03a97ae7f7c01cd107d549ebcbb322
21062096
return isValid();
21072097
}
21082098

@@ -2253,14 +2243,7 @@ class SyclKernelUnionChecker : public SyclKernelFieldHandler {
22532243
}
22542244

22552245
bool handleSyclSpecialType(ParmVarDecl *PD, QualType ParamTy) final {
2256-
<<<<<<< HEAD
22572246
return checkType(PD->getLocation(), ParamTy);
2258-
=======
2259-
if (!SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::work_group_memory) &&
2260-
!SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::dynamic_work_group_memory))
2261-
unsupportedFreeFunctionParamType(); // TODO
2262-
return true;
2263-
>>>>>>> 8113cb9ccb03a97ae7f7c01cd107d549ebcbb322
22642247
}
22652248

22662249
bool handleSyclSpecialType(const CXXRecordDecl *, const CXXBaseSpecifier &BS,
@@ -3044,7 +3027,6 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
30443027
}
30453028

30463029
bool handleSyclSpecialType(ParmVarDecl *PD, QualType ParamTy) final {
3047-
<<<<<<< HEAD
30483030
const auto *RecordDecl = ParamTy->getAsCXXRecordDecl();
30493031
assert(RecordDecl && "The type must be a RecordDecl");
30503032
CXXMethodDecl *InitMethod = getMethodByName(RecordDecl, InitMethodName);
@@ -3061,29 +3043,6 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
30613043
Params.back()->addAttr(AddIRAttr->clone(SemaSYCLRef.getASTContext()));
30623044
}
30633045
LastParamIndex = ParamIndex;
3064-
=======
3065-
if (SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::work_group_memory) ||
3066-
SemaSYCL::isSyclType(ParamTy,
3067-
SYCLTypeAttr::dynamic_work_group_memory)) {
3068-
const auto *RecordDecl = ParamTy->getAsCXXRecordDecl();
3069-
assert(RecordDecl && "The type must be a RecordDecl");
3070-
CXXMethodDecl *InitMethod = getMethodByName(RecordDecl, InitMethodName);
3071-
assert(InitMethod && "The type must have the __init method");
3072-
// Don't do -1 here because we count on this to be the first parameter
3073-
// added (if any).
3074-
size_t ParamIndex = Params.size();
3075-
for (const ParmVarDecl *Param : InitMethod->parameters()) {
3076-
QualType ParamTy = Param->getType();
3077-
addParam(Param, ParamTy.getCanonicalType());
3078-
// Propagate add_ir_attributes_kernel_parameter attribute.
3079-
if (const auto *AddIRAttr =
3080-
Param->getAttr<SYCLAddIRAttributesKernelParameterAttr>())
3081-
Params.back()->addAttr(AddIRAttr->clone(SemaSYCLRef.getASTContext()));
3082-
}
3083-
LastParamIndex = ParamIndex;
3084-
} else // TODO
3085-
unsupportedFreeFunctionParamType();
3086-
>>>>>>> 8113cb9ccb03a97ae7f7c01cd107d549ebcbb322
30873046
return true;
30883047
}
30893048

@@ -4577,26 +4536,13 @@ class FreeFunctionKernelBodyCreator : public SyclKernelFieldHandler {
45774536
// TODO: Revisit this approach once https://github.com/intel/llvm/issues/16061
45784537
// is closed.
45794538
bool handleSyclSpecialType(ParmVarDecl *PD, QualType ParamTy) final {
4580-
<<<<<<< HEAD
45814539
const auto *RecordDecl = ParamTy->getAsCXXRecordDecl();
45824540
AccessSpecifier DefaultConstructorAccess;
45834541
auto DefaultConstructor =
45844542
std::find_if(RecordDecl->ctor_begin(), RecordDecl->ctor_end(),
45854543
[](auto it) { return it->isDefaultConstructor(); });
45864544
DefaultConstructorAccess = DefaultConstructor->getAccess();
45874545
DefaultConstructor->setAccess(AS_public);
4588-
=======
4589-
if (SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::work_group_memory) ||
4590-
SemaSYCL::isSyclType(ParamTy,
4591-
SYCLTypeAttr::dynamic_work_group_memory)) {
4592-
const auto *RecordDecl = ParamTy->getAsCXXRecordDecl();
4593-
AccessSpecifier DefaultConstructorAccess;
4594-
auto DefaultConstructor =
4595-
std::find_if(RecordDecl->ctor_begin(), RecordDecl->ctor_end(),
4596-
[](auto it) { return it->isDefaultConstructor(); });
4597-
DefaultConstructorAccess = DefaultConstructor->getAccess();
4598-
DefaultConstructor->setAccess(AS_public);
4599-
>>>>>>> 8113cb9ccb03a97ae7f7c01cd107d549ebcbb322
46004546

46014547
QualType Ty = PD->getOriginalType();
46024548
ASTContext &Ctx = SemaSYCLRef.SemaRef.getASTContext();
@@ -4936,7 +4882,6 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
49364882
addParam(PD, ParamTy, SYCLIntegrationHeader::kind_stream);
49374883
} else if (SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::work_group_memory)) {
49384884
addParam(PD, ParamTy, SYCLIntegrationHeader::kind_work_group_memory);
4939-
<<<<<<< HEAD
49404885
} else if (SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::sampler) ||
49414886
SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::annotated_ptr) ||
49424887
SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::annotated_arg)) {
@@ -4951,18 +4896,15 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
49514896
: (T->isPointerType() ? SYCLIntegrationHeader::kind_pointer
49524897
: SYCLIntegrationHeader::kind_std_layout);
49534898
addParam(PD, ParamTy, ParamKind);
4954-
} else {
4899+
} else if (SemaSYCL::isSyclType(ParamTy,
4900+
SYCLTypeAttr::dynamic_work_group_memory))
4901+
addParam(PD, ParamTy,
4902+
SYCLIntegrationHeader::kind_dynamic_work_group_memory);
4903+
4904+
else {
49554905
llvm_unreachable(
49564906
"Unexpected SYCL special class when generating integration header");
49574907
}
4958-
=======
4959-
else if (SemaSYCL::isSyclType(ParamTy,
4960-
SYCLTypeAttr::dynamic_work_group_memory))
4961-
addParam(PD, ParamTy,
4962-
SYCLIntegrationHeader::kind_dynamic_work_group_memory);
4963-
else
4964-
unsupportedFreeFunctionParamType(); // TODO
4965-
>>>>>>> 8113cb9ccb03a97ae7f7c01cd107d549ebcbb322
49664908
return true;
49674909
}
49684910

clang/test/CodeGenSYCL/Inputs/sycl.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct sampler_impl {
3434
class __attribute__((sycl_special_class)) __SYCL_TYPE(sampler) sampler {
3535
struct sampler_impl impl;
3636
#ifdef __SYCL_DEVICE_ONLY__
37+
sampler() = default;
3738
void __init(__ocl_sampler_t Sampler) { impl.m_Sampler = Sampler; }
3839
#endif
3940

@@ -327,6 +328,9 @@ template <typename dataT, int dimensions, access::mode accessmode,
327328
class __attribute__((sycl_special_class)) __SYCL_TYPE(accessor) accessor {
328329

329330
public:
331+
#ifdef __SYCL_DEVICE_ONLY__
332+
accessor() = default;
333+
#endif
330334
void use(void) const {}
331335
template <typename... T>
332336
void use(T... args) {}
@@ -420,6 +424,9 @@ local_accessor: public accessor<dataT,
420424
dimensions, access::mode::read_write,
421425
access::target::local> {
422426
public:
427+
#ifdef __SYCL_DEVICE_ONLY__
428+
local_accessor();
429+
#endif
423430
void use(void) const {}
424431
template <typename... T>
425432
void use(T... args) {}
@@ -488,6 +495,7 @@ template <typename T, typename... Props>
488495
class __attribute__((sycl_special_class)) __SYCL_TYPE(annotated_arg) annotated_arg {
489496
T obj;
490497
#ifdef __SYCL_DEVICE_ONLY__
498+
annotated_arg() = default;
491499
void __init(T _obj) {}
492500
#endif
493501
};
@@ -496,6 +504,7 @@ template <typename T, typename... Props>
496504
class __attribute__((sycl_special_class)) __SYCL_TYPE(annotated_ptr) annotated_ptr {
497505
T* obj;
498506
#ifdef __SYCL_DEVICE_ONLY__
507+
annotated_ptr() = default;
499508
void __init(T* _obj) {}
500509
#endif
501510
};

0 commit comments

Comments
 (0)