@@ -196,8 +196,10 @@ def FunctionPointer : SubsetSubject<DeclBase,
196196 "functions pointers">;
197197
198198def OpenCLKernelFunction
199- : SubsetSubject<Function, [{S->hasAttr<OpenCLKernelAttr>()}],
200- "kernel functions">;
199+ : SubsetSubject<Function, [{S->getASTContext().getLangOpts().OpenCL &&
200+ DeviceKernelAttr::isOpenCLSpelling(
201+ S->getAttr<DeviceKernelAttr>()}],
202+ "kernel functions">;
201203
202204// HasFunctionProto is a more strict version of FunctionLike, so it should
203205// never be specified in a Subjects list along with FunctionLike (due to the
@@ -1515,12 +1517,6 @@ def CUDAGridConstant : InheritableAttr {
15151517 let Documentation = [CUDAGridConstantAttrDocs];
15161518}
15171519
1518- def NVPTXKernel : InheritableAttr, TargetSpecificAttr<TargetNVPTX> {
1519- let Spellings = [Clang<"nvptx_kernel">];
1520- let Subjects = SubjectList<[Function]>;
1521- let Documentation = [Undocumented];
1522- }
1523-
15241520def HIPManaged : InheritableAttr {
15251521 let Spellings = [GNU<"managed">, Declspec<"__managed__">];
15261522 let Subjects = SubjectList<[Var]>;
@@ -1555,11 +1551,52 @@ def CUDAShared : InheritableAttr {
15551551}
15561552def : MutualExclusions<[CUDAConstant, CUDAShared, HIPManaged]>;
15571553
1558- def SYCLKernel : InheritableAttr {
1559- let Spellings = [Clang<"sycl_kernel">];
1560- let Subjects = SubjectList<[FunctionTmpl]>;
1561- let LangOpts = [SYCLDevice];
1562- let Documentation = [SYCLKernelDocs];
1554+ def DeviceKernel : DeclOrTypeAttr {
1555+ let Spellings = [Clang<"device_kernel">, Clang<"sycl_kernel">,
1556+ Clang<"nvptx_kernel">, Clang<"amdgpu_kernel">,
1557+ CustomKeyword<"__kernel">, CustomKeyword<"kernel">];
1558+ let Documentation = [DeviceKernelDocs];
1559+ let AdditionalMembers =
1560+ [{
1561+ static inline bool isAMDGPUSpelling(const AttributeCommonInfo& A) {
1562+ return A.getAttributeSpellingListIndex() == GNU_amdgpu_kernel ||
1563+ A.getAttributeSpellingListIndex() == CXX11_clang_amdgpu_kernel ||
1564+ A.getAttributeSpellingListIndex() == C23_clang_amdgpu_kernel;
1565+ }
1566+ static inline bool isAMDGPUSpelling(const AttributeCommonInfo* A) {
1567+ if(!A) return false;
1568+ return isAMDGPUSpelling(*A);
1569+ }
1570+ static inline bool isNVPTXSpelling(const AttributeCommonInfo& A) {
1571+ return A.getAttributeSpellingListIndex() == GNU_nvptx_kernel ||
1572+ A.getAttributeSpellingListIndex() == CXX11_clang_nvptx_kernel ||
1573+ A.getAttributeSpellingListIndex() == C23_clang_nvptx_kernel;
1574+ }
1575+ static inline bool isNVPTXSpelling(const AttributeCommonInfo* A) {
1576+ if(!A) return false;
1577+ return isNVPTXSpelling(*A);
1578+ }
1579+ static inline bool isSYCLSpelling(const AttributeCommonInfo& A) {
1580+ return A.getAttributeSpellingListIndex() == GNU_sycl_kernel ||
1581+ A.getAttributeSpellingListIndex() == CXX11_clang_sycl_kernel ||
1582+ A.getAttributeSpellingListIndex() == C23_clang_sycl_kernel;
1583+ }
1584+ static inline bool isSYCLSpelling(const AttributeCommonInfo* A) {
1585+ if(!A) return false;
1586+ return isSYCLSpelling(*A);
1587+ }
1588+ static inline bool isOpenCLSpelling(const AttributeCommonInfo& A) {
1589+ // Tablegen trips underscores from spellings to build the spelling
1590+ // list, but here we have the same spelling with unscores and without,
1591+ // so handle that case manually.
1592+ return A.getAttributeSpellingListIndex() == Keyword_kernel ||
1593+ A.getAttrName()->getName() == "kernel";
1594+ }
1595+ static inline bool isOpenCLSpelling(const AttributeCommonInfo* A) {
1596+ if (!A) return false;
1597+ return isOpenCLSpelling(*A);
1598+ }
1599+ }];
15631600}
15641601
15651602def SYCLKernelEntryPoint : InheritableAttr {
@@ -1625,15 +1662,6 @@ def Allocating : TypeAttr {
16251662 let Documentation = [AllocatingDocs];
16261663}
16271664
1628- // Similar to CUDA, OpenCL attributes do not receive a [[]] spelling because
1629- // the specification does not expose them with one currently.
1630- def OpenCLKernel : InheritableAttr {
1631- let Spellings = [CustomKeyword<"__kernel">, CustomKeyword<"kernel">];
1632- let Subjects = SubjectList<[Function], ErrorDiag>;
1633- let Documentation = [Undocumented];
1634- let SimpleHandler = 1;
1635- }
1636-
16371665def OpenCLUnrollHint : StmtAttr {
16381666 let Spellings = [GNU<"opencl_unroll_hint">];
16391667 let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
@@ -2370,11 +2398,6 @@ def AMDGPUMaxNumWorkGroups : InheritableAttr {
23702398 let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">;
23712399}
23722400
2373- def AMDGPUKernelCall : DeclOrTypeAttr {
2374- let Spellings = [Clang<"amdgpu_kernel">];
2375- let Documentation = [Undocumented];
2376- }
2377-
23782401def BPFPreserveAccessIndex : InheritableAttr,
23792402 TargetSpecificAttr<TargetBPF> {
23802403 let Spellings = [Clang<"preserve_access_index">];
0 commit comments