@@ -976,6 +976,27 @@ static QualType GetSYCLKernelObjectType(const FunctionDecl *KernelCaller) {
976
976
return KernelParamTy.getUnqualifiedType ();
977
977
}
978
978
979
+ static CXXMethodDecl *getOperatorParens (const CXXRecordDecl *Rec) {
980
+ for (auto *MD : Rec->methods ()) {
981
+ if (MD->getOverloadedOperator () == OO_Call)
982
+ return MD;
983
+ }
984
+ return nullptr ;
985
+ }
986
+
987
+ // Fetch the associated call operator of the kernel object
988
+ // (of either the lambda or the function object).
989
+ CXXMethodDecl *IsCallOperatorDefined (const CXXRecordDecl *KernelObjType) {
990
+ CXXMethodDecl *CallOperator = nullptr ;
991
+ if (!KernelObjType)
992
+ return CallOperator;
993
+ if (KernelObjType->isLambda ())
994
+ CallOperator = KernelObjType->getLambdaCallOperator ();
995
+ else
996
+ CallOperator = getOperatorParens (KernelObjType);
997
+ return CallOperator;
998
+ }
999
+
979
1000
// / Creates a kernel parameter descriptor
980
1001
// / \param Src field declaration to construct name from
981
1002
// / \param Ty the desired parameter type
@@ -2399,32 +2420,11 @@ class SyclOptReportCreator : public SyclKernelFieldHandler {
2399
2420
}
2400
2421
};
2401
2422
2402
- static CXXMethodDecl *getOperatorParens (const CXXRecordDecl *Rec) {
2403
- for (auto *MD : Rec->methods ()) {
2404
- if (MD->getOverloadedOperator () == OO_Call)
2405
- return MD;
2406
- }
2407
- return nullptr ;
2408
- }
2409
-
2410
2423
static bool isESIMDKernelType (const CXXRecordDecl *KernelObjType) {
2411
2424
const CXXMethodDecl *OpParens = getOperatorParens (KernelObjType);
2412
2425
return (OpParens != nullptr ) && OpParens->hasAttr <SYCLSimdAttr>();
2413
2426
}
2414
2427
2415
- // Fetch the associated call operator of the kernel object
2416
- // (of either the lambda or the function object).
2417
- static bool IsCallOperatorDefined (const CXXRecordDecl *KernelObjType) {
2418
- const CXXMethodDecl *CallOperator = nullptr ;
2419
- if (!KernelObjType)
2420
- return false ;
2421
- if (KernelObjType->isLambda ())
2422
- CallOperator = KernelObjType->getLambdaCallOperator ();
2423
- else
2424
- CallOperator = getOperatorParens (KernelObjType);
2425
- return (CallOperator != nullptr );
2426
- }
2427
-
2428
2428
class SyclKernelBodyCreator : public SyclKernelFieldHandler {
2429
2429
SyclKernelDeclCreator &DeclCreator;
2430
2430
llvm::SmallVector<Stmt *, 16 > BodyStmts;
@@ -2509,11 +2509,8 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
2509
2509
// (of either the lambda or the function object).
2510
2510
CXXRecordDecl *KernelObj =
2511
2511
GetSYCLKernelObjectType (KernelCallerFunc)->getAsCXXRecordDecl ();
2512
- CXXMethodDecl *WGLambdaFn = nullptr ;
2513
- if (KernelObj->isLambda ())
2514
- WGLambdaFn = KernelObj->getLambdaCallOperator ();
2515
- else
2516
- WGLambdaFn = getOperatorParens (KernelObj);
2512
+ CXXMethodDecl *WGLambdaFn = IsCallOperatorDefined (KernelObj);
2513
+
2517
2514
assert (WGLambdaFn && " non callable object is passed as kernel obj" );
2518
2515
// Mark the function that it "works" in a work group scope:
2519
2516
// NOTE: In case of parallel_for_work_item the marker call itself is
@@ -3467,11 +3464,11 @@ void Sema::CheckSYCLKernelCall(FunctionDecl *KernelFunc, SourceRange CallLoc,
3467
3464
if (!LangOpts.SYCLIsDevice )
3468
3465
return ;
3469
3466
3470
- const CXXRecordDecl *KernelObj =
3467
+ CXXRecordDecl *KernelObj =
3471
3468
GetSYCLKernelObjectType (KernelFunc)->getAsCXXRecordDecl ();
3472
3469
3473
- bool IsKernelTypeValid = IsCallOperatorDefined (KernelObj);
3474
- if (!IsKernelTypeValid ) {
3470
+ CXXMethodDecl *CallOperator = IsCallOperatorDefined (KernelObj);
3471
+ if (!CallOperator ) {
3475
3472
Diag (Args[0 ]->getExprLoc (), diag::err_sycl_kernel_not_function_object);
3476
3473
KernelFunc->setInvalidDecl ();
3477
3474
return ;
0 commit comments