- 
                Notifications
    
You must be signed in to change notification settings  - Fork 15.1k
 
[clang] Simplify device kernel attributes #137882
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
Changes from 1 commit
080a9d4
              0c75247
              1036640
              47ae76a
              421950d
              66a7e1a
              eeb377d
              924839b
              168103d
              99a118a
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -190,8 +190,9 @@ def FunctionPointer : SubsetSubject<DeclBase, | |
| "functions pointers">; | ||
| 
     | 
||
| def OpenCLKernelFunction | ||
| : SubsetSubject<Function, [{S->hasAttr<OpenCLKernelAttr>()}], | ||
| "kernel functions">; | ||
| : SubsetSubject<Function, [{S->getASTContext().getLangOpts().OpenCL && | ||
| S->hasAttr<DeviceKernelAttr>()}], | ||
| "kernel functions">; | ||
| 
     | 
||
| // HasFunctionProto is a more strict version of FunctionLike, so it should | ||
| // never be specified in a Subjects list along with FunctionLike (due to the | ||
| 
          
            
          
           | 
    @@ -1498,12 +1499,6 @@ def CUDAGridConstant : InheritableAttr { | |
| let Documentation = [CUDAGridConstantAttrDocs]; | ||
| } | ||
| 
     | 
||
| def NVPTXKernel : InheritableAttr, TargetSpecificAttr<TargetNVPTX> { | ||
| let Spellings = [Clang<"nvptx_kernel">]; | ||
| let Subjects = SubjectList<[Function]>; | ||
| let Documentation = [Undocumented]; | ||
| } | ||
| 
     | 
||
| def HIPManaged : InheritableAttr { | ||
| let Spellings = [GNU<"managed">, Declspec<"__managed__">]; | ||
| let Subjects = SubjectList<[Var]>; | ||
| 
          
            
          
           | 
    @@ -1538,11 +1533,44 @@ 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 LangOpts = []; | ||
| let Documentation = [SYCLKernelDocs]; | ||
                
       | 
||
| let AdditionalMembers = | ||
                
      
                  AaronBallman marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| [{ | ||
| inline bool isAMDGPUSpelling() const { | ||
| return isAMDGPUSpelling(*this); | ||
| } | ||
| template<typename T> | ||
| static inline bool isAMDGPUSpelling(const T& Attr) { | ||
| return Attr.getAttrName()->getName() == "amdgpu_kernel"; | ||
| } | ||
| inline bool isNVPTXSpelling() const { | ||
| return isNVPTXSpelling(*this); | ||
| } | ||
                
       | 
||
| template<typename T> | ||
| static inline bool isNVPTXSpelling(const T& Attr) { | ||
| return Attr.getAttrName()->getName() == "nvptx_kernel"; | ||
| } | ||
| inline bool isOpenCLSpelling() const { | ||
| return isOpenCLSpelling(*this); | ||
| } | ||
| template<typename T> | ||
| static inline bool isOpenCLSpelling(const T& Attr) { | ||
| return Attr.getAttrName()->getName() == "kernel" || | ||
                
       | 
||
| Attr.getAttrName()->getName() == "__kernel"; | ||
| } | ||
| inline bool isSYCLSpelling() const { | ||
| return isSYCLSpelling(*this); | ||
| } | ||
| template<typename T> | ||
| static inline bool isSYCLSpelling(const T& Attr) { | ||
| return Attr.getAttrName()->getName() == "sycl_kernel"; | ||
| } | ||
| }]; | ||
| } | ||
| 
     | 
||
| def SYCLKernelEntryPoint : InheritableAttr { | ||
| 
          
            
          
           | 
    @@ -1608,15 +1636,6 @@ def Allocating : TypeAttr { | |
| let Documentation = [AllocatingDocs]; | ||
| } | ||
| 
     | 
||
| // Similar to CUDA, OpenCL attributes do not receive a [[]] spelling because | ||
| // the specification does not expose them with one currently. | ||
| def OpenCLKernel : InheritableAttr { | ||
| let Spellings = [CustomKeyword<"__kernel">, CustomKeyword<"kernel">]; | ||
| let Subjects = SubjectList<[Function], ErrorDiag>; | ||
| let Documentation = [Undocumented]; | ||
| let SimpleHandler = 1; | ||
| } | ||
| 
     | 
||
| def OpenCLUnrollHint : StmtAttr { | ||
| let Spellings = [GNU<"opencl_unroll_hint">]; | ||
| let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt], | ||
| 
          
            
          
           | 
    @@ -2351,11 +2370,6 @@ def AMDGPUMaxNumWorkGroups : InheritableAttr { | |
| let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">; | ||
| } | ||
| 
     | 
||
| def AMDGPUKernelCall : DeclOrTypeAttr { | ||
| let Spellings = [Clang<"amdgpu_kernel">]; | ||
| let Documentation = [Undocumented]; | ||
| } | ||
| 
     | 
||
| def BPFPreserveAccessIndex : InheritableAttr, | ||
| TargetSpecificAttr<TargetBPF> { | ||
| let Spellings = [Clang<"preserve_access_index">]; | ||
| 
          
            
          
           | 
    ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -3541,7 +3541,7 @@ bool FunctionDecl::isExternC() const { | |
| } | ||
| 
     | 
||
| bool FunctionDecl::isInExternCContext() const { | ||
| if (hasAttr<OpenCLKernelAttr>()) | ||
| if (hasAttr<DeviceKernelAttr>() && getASTContext().getLangOpts().OpenCL) | ||
                
       | 
||
| return true; | ||
| return getLexicalDeclContext()->isExternCContext(); | ||
| } | ||
| 
          
            
          
           | 
    @@ -5512,7 +5512,7 @@ FunctionDecl *FunctionDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) { | |
| } | ||
| 
     | 
||
| bool FunctionDecl::isReferenceableKernel() const { | ||
| return hasAttr<CUDAGlobalAttr>() || hasAttr<OpenCLKernelAttr>(); | ||
| return hasAttr<CUDAGlobalAttr>() || hasAttr<DeviceKernelAttr>(); | ||
| } | ||
| 
     | 
||
| BlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) { | ||
| 
          
            
          
           | 
    ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -1556,7 +1556,8 @@ void CXXNameMangler::mangleUnqualifiedName( | |
| FD && FD->hasAttr<CUDAGlobalAttr>() && | ||
| GD.getKernelReferenceKind() == KernelReferenceKind::Stub; | ||
| bool IsOCLDeviceStub = | ||
| FD && FD->hasAttr<OpenCLKernelAttr>() && | ||
| getASTContext().getLangOpts().OpenCL && FD && | ||
| FD->hasAttr<DeviceKernelAttr>() && | ||
                
       | 
||
| GD.getKernelReferenceKind() == KernelReferenceKind::Stub; | ||
| if (IsDeviceStub) | ||
| mangleDeviceStubName(II); | ||
| 
          
            
          
           | 
    @@ -3529,10 +3530,9 @@ StringRef CXXNameMangler::getCallingConvQualifierName(CallingConv CC) { | |
| case CC_AAPCS_VFP: | ||
| case CC_AArch64VectorCall: | ||
| case CC_AArch64SVEPCS: | ||
| case CC_AMDGPUKernelCall: | ||
| case CC_IntelOclBicc: | ||
| case CC_SpirFunction: | ||
| case CC_OpenCLKernel: | ||
| case CC_DeviceKernel: | ||
| case CC_PreserveMost: | ||
| case CC_PreserveAll: | ||
| case CC_M68kRTD: | ||
| 
          
            
          
           | 
    ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -1164,7 +1164,8 @@ void MicrosoftCXXNameMangler::mangleUnqualifiedName(GlobalDecl GD, | |
| ->hasAttr<CUDAGlobalAttr>())) && | ||
| GD.getKernelReferenceKind() == KernelReferenceKind::Stub; | ||
| bool IsOCLDeviceStub = | ||
| ND && isa<FunctionDecl>(ND) && ND->hasAttr<OpenCLKernelAttr>() && | ||
| getASTContext().getLangOpts().OpenCL && ND && | ||
                
       | 
||
| isa<FunctionDecl>(ND) && ND->hasAttr<DeviceKernelAttr>() && | ||
| GD.getKernelReferenceKind() == KernelReferenceKind::Stub; | ||
| if (IsDeviceStub) | ||
| mangleSourceName( | ||
| 
          
            
          
           | 
    ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can drop this entirely.