Skip to content

Commit 69f4b4c

Browse files
authored
[SYCL] Disallow sycl_kernel attribute on host (#4618)
This is essentially a revert of PR #2186, as the supposed optimization did not materialize. I have removed the functionality added in that PR, while keeping the code cleanups.
1 parent 7aa5be0 commit 69f4b4c

File tree

6 files changed

+9
-91
lines changed

6 files changed

+9
-91
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ def SYCLGlobalVar : InheritableAttr {
12281228
def SYCLKernel : InheritableAttr {
12291229
let Spellings = [Clang<"sycl_kernel">];
12301230
let Subjects = SubjectList<[FunctionTmpl]>;
1231-
let LangOpts = [SYCLIsHost, SYCLIsDevice];
1231+
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
12321232
let Documentation = [SYCLKernelDocs];
12331233
}
12341234

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,9 +1042,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
10421042
if (D && D->hasAttr<NoProfileFunctionAttr>())
10431043
Fn->addFnAttr(llvm::Attribute::NoProfile);
10441044

1045-
if (getLangOpts().SYCLIsHost && D && D->hasAttr<SYCLKernelAttr>())
1046-
Fn->addFnAttr("sycl_kernel");
1047-
10481045
if (getLangOpts().SYCLIsDevice && D) {
10491046
if (const auto *A = D->getAttr<SYCLIntelLoopFuseAttr>()) {
10501047
const auto *CE = cast<ConstantExpr>(A->getValue());

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9314,7 +9314,7 @@ static void handleSYCLKernelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
93149314
// Function template must have at least two template parameters so it
93159315
// can be used in OpenCL kernel generation.
93169316
const TemplateParameterList *TL = FT->getTemplateParameters();
9317-
if (S.LangOpts.SYCLIsDevice && TL->size() < 2) {
9317+
if (TL->size() < 2) {
93189318
S.Diag(FT->getLocation(), diag::warn_sycl_kernel_num_of_template_params);
93199319
return;
93209320
}

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6583,27 +6583,6 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
65836583
return D;
65846584
}
65856585

6586-
static void processSYCLKernel(Sema &S, FunctionDecl *FD, MangleContext &MC) {
6587-
if (S.LangOpts.SYCLIsDevice) {
6588-
S.ConstructOpenCLKernel(FD, MC);
6589-
} else if (S.LangOpts.SYCLIsHost) {
6590-
QualType KernelParamTy = (*FD->param_begin())->getType();
6591-
const CXXRecordDecl *CRD = (KernelParamTy->isReferenceType()
6592-
? KernelParamTy->getPointeeCXXRecordDecl()
6593-
: KernelParamTy->getAsCXXRecordDecl());
6594-
if (!CRD) {
6595-
S.Diag(FD->getLocation(), diag::err_sycl_kernel_not_function_object);
6596-
FD->setInvalidDecl();
6597-
return;
6598-
}
6599-
6600-
for (auto *Method : CRD->methods())
6601-
if (Method->getOverloadedOperator() == OO_Call &&
6602-
!Method->hasAttr<AlwaysInlineAttr>())
6603-
Method->addAttr(AlwaysInlineAttr::CreateImplicit(S.getASTContext()));
6604-
}
6605-
}
6606-
66076586
static void processFunctionInstantiation(Sema &S,
66086587
SourceLocation PointOfInstantiation,
66096588
FunctionDecl *FD,
@@ -6613,8 +6592,8 @@ static void processFunctionInstantiation(Sema &S,
66136592
DefinitionRequired, true);
66146593
if (!FD->isDefined())
66156594
return;
6616-
if (FD->hasAttr<SYCLKernelAttr>())
6617-
processSYCLKernel(S, FD, MC);
6595+
if (S.LangOpts.SYCLIsDevice && FD->hasAttr<SYCLKernelAttr>())
6596+
S.ConstructOpenCLKernel(FD, MC);
66186597
FD->setInstantiationIsPending(false);
66196598
}
66206599

clang/test/CodeGenSYCL/sycl_kernel-host.cpp

Lines changed: 0 additions & 44 deletions
This file was deleted.

clang/test/SemaSYCL/kernel-attribute.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl-is-device -verify %s
22
// RUN: %clang_cc1 -fsycl-is-host -DHOST -fsyntax-only -verify %s
33

4+
#ifndef HOST
45
// Only function templates
56
[[clang::sycl_kernel]] int gv2 = 0; // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
67
__attribute__((sycl_kernel)) int gv3 = 0; // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
@@ -14,13 +15,11 @@ __attribute__((sycl_kernel(1))) void foo(T P); // expected-error {{'sycl_kernel'
1415
template <typename T, typename A, int I>
1516
[[clang::sycl_kernel(1)]] void foo1(T P);// expected-error {{'sycl_kernel' attribute takes no arguments}}
1617

17-
#ifndef HOST
1818
// At least two template parameters
1919
template <typename T>
2020
__attribute__((sycl_kernel)) void foo(T P); // expected-warning {{'sycl_kernel' attribute only applies to a function template with at least two template parameters}}
2121
template <typename T>
2222
[[clang::sycl_kernel]] void foo1(T P); // expected-warning {{'sycl_kernel' attribute only applies to a function template with at least two template parameters}}
23-
#endif
2423

2524
// First two template parameters cannot be non-type template parameters
2625
template <typename T, int A>
@@ -46,22 +45,9 @@ __attribute__((sycl_kernel)) void foo(T P);
4645
template <typename T, typename A, int I>
4746
[[clang::sycl_kernel]] void foo1(T P);
4847

49-
#ifdef HOST
50-
// No diagnostics
51-
template <typename Func>
52-
void __attribute__((sycl_kernel))
53-
KernelImpl4(const Func &f, int i, double d) {
54-
f(i, d);
55-
}
48+
#else
5649

57-
template <typename Name, typename Func>
58-
void __attribute__((sycl_kernel))
59-
Kernel(const Func &f) {
60-
KernelImpl4(f, 1, 2.0);
61-
}
62-
63-
void func() {
64-
auto Lambda = [](int i, double d) { d += i; };
65-
Kernel<class Foo>(Lambda);
66-
}
50+
// expected-no-diagnostics
51+
template <typename T, typename A>
52+
__attribute__((sycl_kernel)) void foo(T P);
6753
#endif

0 commit comments

Comments
 (0)