@@ -991,42 +991,6 @@ static QualType GetSYCLKernelObjectType(const FunctionDecl *KernelCaller) {
991
991
return KernelParamTy.getUnqualifiedType ();
992
992
}
993
993
994
- // Get the call operator function associated with the function object
995
- // for both templated and non-templated operator()().
996
-
997
- static CXXMethodDecl *getFunctorCallOperator (const CXXRecordDecl *RD) {
998
- DeclarationName Name =
999
- RD->getASTContext ().DeclarationNames .getCXXOperatorName (OO_Call);
1000
- DeclContext::lookup_result Calls = RD->lookup (Name);
1001
-
1002
- if (Calls.empty ())
1003
- return nullptr ;
1004
-
1005
- NamedDecl *CallOp = Calls.front ();
1006
-
1007
- if (CallOp == nullptr )
1008
- return nullptr ;
1009
-
1010
- if (const auto *CallOpTmpl = dyn_cast<FunctionTemplateDecl>(CallOp))
1011
- return cast<CXXMethodDecl>(CallOpTmpl->getTemplatedDecl ());
1012
-
1013
- return cast<CXXMethodDecl>(CallOp);
1014
- }
1015
-
1016
- // Fetch the associated call operator of the kernel object
1017
- // (of either the lambda or the function object).
1018
- static CXXMethodDecl *
1019
- GetCallOperatorOfKernelObject (const CXXRecordDecl *KernelObjType) {
1020
- CXXMethodDecl *CallOperator = nullptr ;
1021
- if (!KernelObjType)
1022
- return CallOperator;
1023
- if (KernelObjType->isLambda ())
1024
- CallOperator = KernelObjType->getLambdaCallOperator ();
1025
- else
1026
- CallOperator = getFunctorCallOperator (KernelObjType);
1027
- return CallOperator;
1028
- }
1029
-
1030
994
// / Creates a kernel parameter descriptor
1031
995
// / \param Src field declaration to construct name from
1032
996
// / \param Ty the desired parameter type
@@ -2815,8 +2779,16 @@ class SyclOptReportCreator : public SyclKernelFieldHandler {
2815
2779
}
2816
2780
};
2817
2781
2782
+ static CXXMethodDecl *getOperatorParens (const CXXRecordDecl *Rec) {
2783
+ for (auto *MD : Rec->methods ()) {
2784
+ if (MD->getOverloadedOperator () == OO_Call)
2785
+ return MD;
2786
+ }
2787
+ return nullptr ;
2788
+ }
2789
+
2818
2790
static bool isESIMDKernelType (const CXXRecordDecl *KernelObjType) {
2819
- const CXXMethodDecl *OpParens = getFunctorCallOperator (KernelObjType);
2791
+ const CXXMethodDecl *OpParens = getOperatorParens (KernelObjType);
2820
2792
return (OpParens != nullptr ) && OpParens->hasAttr <SYCLSimdAttr>();
2821
2793
}
2822
2794
@@ -2903,10 +2875,13 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
2903
2875
2904
2876
// Fetch the kernel object and the associated call operator
2905
2877
// (of either the lambda or the function object).
2906
- const CXXRecordDecl *KernelObj =
2878
+ CXXRecordDecl *KernelObj =
2907
2879
GetSYCLKernelObjectType (KernelCallerFunc)->getAsCXXRecordDecl ();
2908
- CXXMethodDecl *WGLambdaFn = GetCallOperatorOfKernelObject (KernelObj);
2909
-
2880
+ CXXMethodDecl *WGLambdaFn = nullptr ;
2881
+ if (KernelObj->isLambda ())
2882
+ WGLambdaFn = KernelObj->getLambdaCallOperator ();
2883
+ else
2884
+ WGLambdaFn = getOperatorParens (KernelObj);
2910
2885
assert (WGLambdaFn && " non callable object is passed as kernel obj" );
2911
2886
// Mark the function that it "works" in a work group scope:
2912
2887
// NOTE: In case of parallel_for_work_item the marker call itself is
@@ -3563,7 +3538,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
3563
3538
static bool IsSYCLUnnamedKernel (Sema &SemaRef, const FunctionDecl *FD) {
3564
3539
if (!SemaRef.getLangOpts ().SYCLUnnamedLambda )
3565
3540
return false ;
3566
- const QualType FunctorTy = GetSYCLKernelObjectType (FD);
3541
+ QualType FunctorTy = GetSYCLKernelObjectType (FD);
3567
3542
QualType TmplArgTy = calculateKernelNameType (SemaRef.Context , FD);
3568
3543
return SemaRef.Context .hasSameType (FunctorTy, TmplArgTy);
3569
3544
}
@@ -3989,7 +3964,7 @@ void Sema::CheckSYCLKernelCall(FunctionDecl *KernelFunc,
3989
3964
const CXXRecordDecl *KernelObj =
3990
3965
GetSYCLKernelObjectType (KernelFunc)->getAsCXXRecordDecl ();
3991
3966
3992
- if (!GetCallOperatorOfKernelObject ( KernelObj) ) {
3967
+ if (!KernelObj) {
3993
3968
Diag (Args[0 ]->getExprLoc (), diag::err_sycl_kernel_not_function_object);
3994
3969
KernelFunc->setInvalidDecl ();
3995
3970
return ;
@@ -4055,7 +4030,7 @@ void Sema::CheckSYCLKernelCall(FunctionDecl *KernelFunc,
4055
4030
// kernel to wrapped kernel.
4056
4031
void Sema::copySYCLKernelAttrs (const CXXRecordDecl *KernelObj) {
4057
4032
// Get the operator() function of the wrapper.
4058
- CXXMethodDecl *OpParens = getFunctorCallOperator (KernelObj);
4033
+ CXXMethodDecl *OpParens = getOperatorParens (KernelObj);
4059
4034
assert (OpParens && " invalid kernel object" );
4060
4035
4061
4036
typedef std::pair<FunctionDecl *, FunctionDecl *> ChildParentPair;
0 commit comments