Skip to content

[SYCL] Revert support for templated call operators #8047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 18 additions & 43 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,42 +991,6 @@ static QualType GetSYCLKernelObjectType(const FunctionDecl *KernelCaller) {
return KernelParamTy.getUnqualifiedType();
}

// Get the call operator function associated with the function object
// for both templated and non-templated operator()().

static CXXMethodDecl *getFunctorCallOperator(const CXXRecordDecl *RD) {
DeclarationName Name =
RD->getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);
DeclContext::lookup_result Calls = RD->lookup(Name);

if (Calls.empty())
return nullptr;

NamedDecl *CallOp = Calls.front();

if (CallOp == nullptr)
return nullptr;

if (const auto *CallOpTmpl = dyn_cast<FunctionTemplateDecl>(CallOp))
return cast<CXXMethodDecl>(CallOpTmpl->getTemplatedDecl());

return cast<CXXMethodDecl>(CallOp);
}

// Fetch the associated call operator of the kernel object
// (of either the lambda or the function object).
static CXXMethodDecl *
GetCallOperatorOfKernelObject(const CXXRecordDecl *KernelObjType) {
CXXMethodDecl *CallOperator = nullptr;
if (!KernelObjType)
return CallOperator;
if (KernelObjType->isLambda())
CallOperator = KernelObjType->getLambdaCallOperator();
else
CallOperator = getFunctorCallOperator(KernelObjType);
return CallOperator;
}

/// Creates a kernel parameter descriptor
/// \param Src field declaration to construct name from
/// \param Ty the desired parameter type
Expand Down Expand Up @@ -2815,8 +2779,16 @@ class SyclOptReportCreator : public SyclKernelFieldHandler {
}
};

static CXXMethodDecl *getOperatorParens(const CXXRecordDecl *Rec) {
for (auto *MD : Rec->methods()) {
if (MD->getOverloadedOperator() == OO_Call)
return MD;
}
return nullptr;
}

static bool isESIMDKernelType(const CXXRecordDecl *KernelObjType) {
const CXXMethodDecl *OpParens = getFunctorCallOperator(KernelObjType);
const CXXMethodDecl *OpParens = getOperatorParens(KernelObjType);
return (OpParens != nullptr) && OpParens->hasAttr<SYCLSimdAttr>();
}

Expand Down Expand Up @@ -2903,10 +2875,13 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {

// Fetch the kernel object and the associated call operator
// (of either the lambda or the function object).
const CXXRecordDecl *KernelObj =
CXXRecordDecl *KernelObj =
GetSYCLKernelObjectType(KernelCallerFunc)->getAsCXXRecordDecl();
CXXMethodDecl *WGLambdaFn = GetCallOperatorOfKernelObject(KernelObj);

CXXMethodDecl *WGLambdaFn = nullptr;
if (KernelObj->isLambda())
WGLambdaFn = KernelObj->getLambdaCallOperator();
else
WGLambdaFn = getOperatorParens(KernelObj);
assert(WGLambdaFn && "non callable object is passed as kernel obj");
// Mark the function that it "works" in a work group scope:
// NOTE: In case of parallel_for_work_item the marker call itself is
Expand Down Expand Up @@ -3563,7 +3538,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
static bool IsSYCLUnnamedKernel(Sema &SemaRef, const FunctionDecl *FD) {
if (!SemaRef.getLangOpts().SYCLUnnamedLambda)
return false;
const QualType FunctorTy = GetSYCLKernelObjectType(FD);
QualType FunctorTy = GetSYCLKernelObjectType(FD);
QualType TmplArgTy = calculateKernelNameType(SemaRef.Context, FD);
return SemaRef.Context.hasSameType(FunctorTy, TmplArgTy);
}
Expand Down Expand Up @@ -3989,7 +3964,7 @@ void Sema::CheckSYCLKernelCall(FunctionDecl *KernelFunc,
const CXXRecordDecl *KernelObj =
GetSYCLKernelObjectType(KernelFunc)->getAsCXXRecordDecl();

if (!GetCallOperatorOfKernelObject(KernelObj)) {
if (!KernelObj) {
Diag(Args[0]->getExprLoc(), diag::err_sycl_kernel_not_function_object);
KernelFunc->setInvalidDecl();
return;
Expand Down Expand Up @@ -4055,7 +4030,7 @@ void Sema::CheckSYCLKernelCall(FunctionDecl *KernelFunc,
// kernel to wrapped kernel.
void Sema::copySYCLKernelAttrs(const CXXRecordDecl *KernelObj) {
// Get the operator() function of the wrapper.
CXXMethodDecl *OpParens = getFunctorCallOperator(KernelObj);
CXXMethodDecl *OpParens = getOperatorParens(KernelObj);
assert(OpParens && "invalid kernel object");

typedef std::pair<FunctionDecl *, FunctionDecl *> ChildParentPair;
Expand Down
50 changes: 0 additions & 50 deletions clang/test/SemaSYCL/undefined-functor.cpp

This file was deleted.