Skip to content

Commit 1db148c

Browse files
authored
[clang][Sema] Split SYCLKernel back into its own attribute (llvm#162868)
Based on feedback from llvm#161905, partially revert llvm#137882 so that `sycl_kernel` is a separate attribute and not just a spelling of `device_kernel`. Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 50aac2c commit 1db148c

File tree

7 files changed

+39
-37
lines changed

7 files changed

+39
-37
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,8 +1599,15 @@ def CUDAShared : InheritableAttr {
15991599
}
16001600
def : MutualExclusions<[CUDAConstant, CUDAShared, HIPManaged]>;
16011601

1602+
def SYCLKernel : InheritableAttr {
1603+
let Spellings = [Clang<"sycl_kernel">];
1604+
let Subjects = SubjectList<[FunctionTmpl]>;
1605+
let LangOpts = [SYCLDevice];
1606+
let Documentation = [SYCLKernelDocs];
1607+
}
1608+
16021609
def DeviceKernel : DeclOrTypeAttr {
1603-
let Spellings = [Clang<"device_kernel">, Clang<"sycl_kernel">,
1610+
let Spellings = [Clang<"device_kernel">,
16041611
Clang<"nvptx_kernel">, Clang<"amdgpu_kernel">,
16051612
CustomKeyword<"__kernel">, CustomKeyword<"kernel">];
16061613
let Documentation = [DeviceKernelDocs];
@@ -1624,15 +1631,6 @@ def DeviceKernel : DeclOrTypeAttr {
16241631
if(!A) return false;
16251632
return isNVPTXSpelling(*A);
16261633
}
1627-
static inline bool isSYCLSpelling(const AttributeCommonInfo& A) {
1628-
return A.getAttributeSpellingListIndex() == GNU_sycl_kernel ||
1629-
A.getAttributeSpellingListIndex() == CXX11_clang_sycl_kernel ||
1630-
A.getAttributeSpellingListIndex() == C23_clang_sycl_kernel;
1631-
}
1632-
static inline bool isSYCLSpelling(const AttributeCommonInfo* A) {
1633-
if(!A) return false;
1634-
return isSYCLSpelling(*A);
1635-
}
16361634
static inline bool isOpenCLSpelling(const AttributeCommonInfo& A) {
16371635
// Tablegen trips underscores from spellings to build the spelling
16381636
// list, but here we have the same spelling with unscores and without,

clang/include/clang/Basic/AttrDocs.td

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,10 @@ any option of a multiversioned function is undefined.
396396
}];
397397
}
398398

399-
def DeviceKernelDocs : Documentation {
399+
def SYCLKernelDocs : Documentation {
400400
let Category = DocCatFunction;
401-
let Heading = "device_kernel, sycl_kernel, nvptx_kernel, amdgpu_kernel, "
402-
"kernel, __kernel";
401+
let Heading = "sycl_kernel";
403402
let Content = [{
404-
These attributes specify that the function represents a kernel for device offloading.
405-
The specific semantics depend on the offloading language, target, and attribute spelling.
406403
The ``sycl_kernel`` attribute specifies that a function template will be used
407404
to outline device code and to generate an OpenCL kernel.
408405
Here is a code example of the SYCL program, which demonstrates the compiler's
@@ -476,6 +473,21 @@ The SYCL kernel in the previous code sample meets these expectations.
476473
}];
477474
}
478475

476+
def DeviceKernelDocs : Documentation {
477+
let Category = DocCatFunction;
478+
let Heading = "device_kernel, nvptx_kernel, amdgpu_kernel, "
479+
"kernel, __kernel";
480+
let Content = [{
481+
These attributes specify that the function represents a kernel for device offloading.
482+
The specific semantics depend on the offloading language, target, and attribute spelling.
483+
Here is a code example using the attribute to mark a function as a kernel:
484+
485+
.. code-block:: c++
486+
487+
[[clang::device_kernel]] int foo(int x) { return ++x; }
488+
}];
489+
}
490+
479491
def SYCLExternalDocs : Documentation {
480492
let Category = DocCatFunction;
481493
let Heading = "sycl_external";

clang/lib/Sema/SemaDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20797,7 +20797,7 @@ Sema::FunctionEmissionStatus Sema::getEmissionStatus(const FunctionDecl *FD,
2079720797

2079820798
// SYCL functions can be template, so we check if they have appropriate
2079920799
// attribute prior to checking if it is a template.
20800-
if (LangOpts.SYCLIsDevice && FD->hasAttr<DeviceKernelAttr>())
20800+
if (LangOpts.SYCLIsDevice && FD->hasAttr<SYCLKernelAttr>())
2080120801
return FunctionEmissionStatus::Emitted;
2080220802

2080320803
// Templates are emitted when they're instantiated.

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5204,16 +5204,7 @@ static void handleCallConvAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
52045204
static void handleDeviceKernelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
52055205
const auto *FD = dyn_cast_or_null<FunctionDecl>(D);
52065206
bool IsFunctionTemplate = FD && FD->getDescribedFunctionTemplate();
5207-
if (S.getLangOpts().SYCLIsDevice) {
5208-
if (!IsFunctionTemplate) {
5209-
S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type_str)
5210-
<< AL << AL.isRegularKeywordAttribute() << "function templates";
5211-
} else {
5212-
S.SYCL().handleKernelAttr(D, AL);
5213-
}
5214-
} else if (DeviceKernelAttr::isSYCLSpelling(AL)) {
5215-
S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL;
5216-
} else if (S.getASTContext().getTargetInfo().getTriple().isNVPTX()) {
5207+
if (S.getASTContext().getTargetInfo().getTriple().isNVPTX()) {
52175208
handleGlobalAttr(S, D, AL);
52185209
} else {
52195210
// OpenCL C++ will throw a more specific error.
@@ -7100,6 +7091,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
71007091
case ParsedAttr::AT_EnumExtensibility:
71017092
handleEnumExtensibilityAttr(S, D, AL);
71027093
break;
7094+
case ParsedAttr::AT_SYCLKernel:
7095+
S.SYCL().handleKernelAttr(D, AL);
7096+
break;
71037097
case ParsedAttr::AT_SYCLExternal:
71047098
handleSimpleAttribute<SYCLExternalAttr>(S, D, AL);
71057099
break;

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void SemaSYCL::handleKernelAttr(Decl *D, const ParsedAttr &AL) {
199199
return;
200200
}
201201

202-
handleSimpleAttribute<DeviceKernelAttr>(*this, D, AL);
202+
handleSimpleAttribute<SYCLKernelAttr>(*this, D, AL);
203203
}
204204

205205
void SemaSYCL::handleKernelEntryPointAttr(Decl *D, const ParsedAttr &AL) {

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -710,9 +710,9 @@ static void instantiateDependentAMDGPUMaxNumWorkGroupsAttr(
710710
// This doesn't take any template parameters, but we have a custom action that
711711
// needs to happen when the kernel itself is instantiated. We need to run the
712712
// ItaniumMangler to mark the names required to name this kernel.
713-
static void instantiateDependentDeviceKernelAttr(
713+
static void instantiateDependentSYCLKernelAttr(
714714
Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
715-
const DeviceKernelAttr &Attr, Decl *New) {
715+
const SYCLKernelAttr &Attr, Decl *New) {
716716
New->addAttr(Attr.clone(S.getASTContext()));
717717
}
718718

@@ -966,8 +966,8 @@ void Sema::InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
966966
continue;
967967
}
968968

969-
if (auto *A = dyn_cast<DeviceKernelAttr>(TmplAttr)) {
970-
instantiateDependentDeviceKernelAttr(*this, TemplateArgs, *A, New);
969+
if (auto *A = dyn_cast<SYCLKernelAttr>(TmplAttr)) {
970+
instantiateDependentSYCLKernelAttr(*this, TemplateArgs, *A, New);
971971
continue;
972972
}
973973

clang/lib/Sema/SemaType.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3780,12 +3780,10 @@ static CallingConv getCCForDeclaratorChunk(
37803780
}
37813781
}
37823782
}
3783-
if (!S.getLangOpts().isSYCL()) {
3784-
for (const ParsedAttr &AL : D.getDeclSpec().getAttributes()) {
3785-
if (AL.getKind() == ParsedAttr::AT_DeviceKernel) {
3786-
CC = CC_DeviceKernel;
3787-
break;
3788-
}
3783+
for (const ParsedAttr &AL : D.getDeclSpec().getAttributes()) {
3784+
if (AL.getKind() == ParsedAttr::AT_DeviceKernel) {
3785+
CC = CC_DeviceKernel;
3786+
break;
37893787
}
37903788
}
37913789
return CC;

0 commit comments

Comments
 (0)