Skip to content

Commit aa0a48b

Browse files
Refactor common code
1 parent 373dd69 commit aa0a48b

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,27 @@ static QualType GetSYCLKernelObjectType(const FunctionDecl *KernelCaller) {
976976
return KernelParamTy.getUnqualifiedType();
977977
}
978978

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+
9791000
/// Creates a kernel parameter descriptor
9801001
/// \param Src field declaration to construct name from
9811002
/// \param Ty the desired parameter type
@@ -2399,32 +2420,11 @@ class SyclOptReportCreator : public SyclKernelFieldHandler {
23992420
}
24002421
};
24012422

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-
24102423
static bool isESIMDKernelType(const CXXRecordDecl *KernelObjType) {
24112424
const CXXMethodDecl *OpParens = getOperatorParens(KernelObjType);
24122425
return (OpParens != nullptr) && OpParens->hasAttr<SYCLSimdAttr>();
24132426
}
24142427

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-
24282428
class SyclKernelBodyCreator : public SyclKernelFieldHandler {
24292429
SyclKernelDeclCreator &DeclCreator;
24302430
llvm::SmallVector<Stmt *, 16> BodyStmts;
@@ -2509,11 +2509,8 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
25092509
// (of either the lambda or the function object).
25102510
CXXRecordDecl *KernelObj =
25112511
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+
25172514
assert(WGLambdaFn && "non callable object is passed as kernel obj");
25182515
// Mark the function that it "works" in a work group scope:
25192516
// NOTE: In case of parallel_for_work_item the marker call itself is
@@ -3467,11 +3464,11 @@ void Sema::CheckSYCLKernelCall(FunctionDecl *KernelFunc, SourceRange CallLoc,
34673464
if (!LangOpts.SYCLIsDevice)
34683465
return;
34693466

3470-
const CXXRecordDecl *KernelObj =
3467+
CXXRecordDecl *KernelObj =
34713468
GetSYCLKernelObjectType(KernelFunc)->getAsCXXRecordDecl();
34723469

3473-
bool IsKernelTypeValid = IsCallOperatorDefined(KernelObj);
3474-
if (!IsKernelTypeValid) {
3470+
CXXMethodDecl *CallOperator = IsCallOperatorDefined(KernelObj);
3471+
if (!CallOperator) {
34753472
Diag(Args[0]->getExprLoc(), diag::err_sycl_kernel_not_function_object);
34763473
KernelFunc->setInvalidDecl();
34773474
return;

0 commit comments

Comments
 (0)