[clang] [llvm] [clang] Simplify device kernel attributes (PR #137882)
Nick Sarnie via llvm-commits
llvm-commits at lists.llvm.org
Fri May 9 07:49:43 PDT 2025
================
@@ -1538,11 +1533,32 @@ def CUDAShared : InheritableAttr {
}
def : MutualExclusions<[CUDAConstant, CUDAShared, HIPManaged]>;
-def SYCLKernel : InheritableAttr {
- let Spellings = [Clang<"sycl_kernel">];
- let Subjects = SubjectList<[FunctionTmpl]>;
- let LangOpts = [SYCLDevice];
+def DeviceKernel : DeclOrTypeAttr {
+ let Spellings = [Clang<"device_kernel">, Clang<"sycl_kernel">,
+ Clang<"nvptx_kernel">, Clang<"amdgpu_kernel">,
+ CustomKeyword<"__kernel">, CustomKeyword<"kernel">];
let Documentation = [SYCLKernelDocs];
+ let AdditionalMembers =
----------------
sarnex wrote:
I might be missing something, but I'm not sure how I could use `Accessors` without having to duplicate the implementation for `ParsedAttr` or do something weird. For example:
```
let Accessors = [Accessor<"isAMDGPU", [Clang<"amdgpu_kernel">]>];
```
automatically generates
```
bool isAMDGPU() const { return getAttributeSpellingListIndex() == 9 ||
getAttributeSpellingListIndex() == 10 ||
getAttributeSpellingListIndex() == 11; }
```
which is inside the generated `DeviceKernelAttr` class :
```
class CLANG_ABI DeviceKernelAttr : public InheritableAttr {
...
bool isAMDGPU() const { ... }
}
```
however, we need to do the same spelling check before we create and attach the `DeviceKernelAttr` attr to the `Decl/Type`, when we only have `ParsedAttr`, for example here:
```
static bool isMultiSubjectAttrAllowedOnType(const ParsedAttr &Attr) {
// The DeviceKernel attribute is shared for many targets, and
// it is only allowed to be a type attribute with the AMDGPU
// spelling, so skip processing the attr as a type attr
// unless it has that spelling.
if (Attr.getKind() != ParsedAttr::AT_DeviceKernel)
return true;
return DeviceKernelAttr::isAMDGPUSpelling(Attr);
}
```
and we can't use the generated function because `ParsedAttr` is not part of the class hierarchy for `DeviceKernelAttr`.
The only ways I see to use the `Accessor` and be able to do the required checks is to either duplicate the implementation for the `ParsedAttr` case, or create a temporary `DeviceKernelAttr` object from the `ParsedAttr` every time we want to do a name check and then destroy it if we don't actually need it, which I would expect impacts performance to some degree.
Did I miss something? Thanks
https://github.com/llvm/llvm-project/pull/137882
More information about the llvm-commits
mailing list