-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[clang] Fix inconsistencies with the device_kernel attr on different targets #161905
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a27574f
[clang] Fix inconsistencies with the device_kernel attr on different …
sarnex d796500
minor cleanup and address code review comments
sarnex 48a98e2
Merge remote-tracking branch 'upstream/main'
sarnex 68cf3dd
format
sarnex 948aabd
add error
sarnex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,7 +134,6 @@ static void diagnoseBadTypeAttribute(Sema &S, const ParsedAttr &attr, | |
| case ParsedAttr::AT_VectorCall: \ | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
| case ParsedAttr::AT_AArch64VectorPcs: \ | ||
| case ParsedAttr::AT_AArch64SVEPcs: \ | ||
| case ParsedAttr::AT_DeviceKernel: \ | ||
| case ParsedAttr::AT_MSABI: \ | ||
| case ParsedAttr::AT_SysVABI: \ | ||
| case ParsedAttr::AT_Pcs: \ | ||
|
|
@@ -3780,7 +3779,8 @@ static CallingConv getCCForDeclaratorChunk( | |
| } | ||
| } | ||
| } | ||
| for (const ParsedAttr &AL : D.getDeclSpec().getAttributes()) { | ||
| for (const ParsedAttr &AL : llvm::concat<ParsedAttr>( | ||
| D.getDeclSpec().getAttributes(), D.getAttributes())) { | ||
| if (AL.getKind() == ParsedAttr::AT_DeviceKernel) { | ||
| CC = CC_DeviceKernel; | ||
| break; | ||
|
|
@@ -7563,8 +7563,6 @@ static Attr *getCCTypeAttr(ASTContext &Ctx, ParsedAttr &Attr) { | |
| return createSimpleAttr<AArch64SVEPcsAttr>(Ctx, Attr); | ||
| case ParsedAttr::AT_ArmStreaming: | ||
| return createSimpleAttr<ArmStreamingAttr>(Ctx, Attr); | ||
| case ParsedAttr::AT_DeviceKernel: | ||
| return createSimpleAttr<DeviceKernelAttr>(Ctx, Attr); | ||
| case ParsedAttr::AT_Pcs: { | ||
| // The attribute may have had a fixit applied where we treated an | ||
| // identifier as a string literal. The contents of the string are valid, | ||
|
|
@@ -8803,16 +8801,6 @@ static void HandleHLSLParamModifierAttr(TypeProcessingState &State, | |
| } | ||
| } | ||
|
|
||
| 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); | ||
| } | ||
|
|
||
| static void processTypeAttrs(TypeProcessingState &state, QualType &type, | ||
| TypeAttrLocation TAL, | ||
| const ParsedAttributesView &attrs, | ||
|
|
@@ -9066,8 +9054,6 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type, | |
| break; | ||
| [[fallthrough]]; | ||
| FUNCTION_TYPE_ATTRS_CASELIST: | ||
| if (!isMultiSubjectAttrAllowedOnType(attr)) | ||
| break; | ||
|
|
||
| attr.setUsedAsTypeAttr(); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm %s 2>&1 -o -| FileCheck -check-prefix=CHECK-AMDGPU %s | ||
jhuber6 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda- -emit-llvm %s 2>&1 -o -| FileCheck -check-prefix=CHECK-NVPTX %s | ||
| // RUN: %clang_cc1 -triple spir64 -emit-llvm %s 2>&1 -o - | FileCheck -check-prefix=CHECK-SPIR %s | ||
| // RUN: %clang_cc1 -triple spirv64 -emit-llvm %s 2>&1 -o - | FileCheck -check-prefix=CHECK-SPIR %s | ||
|
|
||
| // CHECK-AMDGPU-DAG: amdgpu_kernel void @kernel1() | ||
| // CHECK-NVPTX-DAG: ptx_kernel void @kernel1() | ||
| // CHECK-SPIR-DAG: spir_kernel void @kernel1() | ||
| [[clang::device_kernel]] void kernel1() {} | ||
|
|
||
| // CHECK-AMDGPU-DAG: amdgpu_kernel void @kernel2() | ||
| // CHECK-NVPTX-DAG: 14:3: warning: 'clang::amdgpu_kernel' calling convention is not supported for this target | ||
| // CHECK-SPIR-DAG: 14:3: warning: 'clang::amdgpu_kernel' calling convention is not supported for this target | ||
| [[clang::amdgpu_kernel]] void kernel2() {} | ||
|
|
||
| // CHECK-AMDGPU-DAG: 19:3: warning: 'clang::nvptx_kernel' calling convention is not supported for this target | ||
| // CHECK-NVPTX-DAG: ptx_kernel void @kernel3() | ||
| // CHECK-SPIR-DAG: 19:3: warning: 'clang::nvptx_kernel' calling convention is not supported for this target | ||
| [[clang::nvptx_kernel]] void kernel3() {} | ||
|
|
||
| // CHECK-AMDGPU-DAG: 24:3: warning: 'clang::sycl_kernel' attribute ignored | ||
| // CHECK-NVPTX-DAG: 24:3: warning: 'clang::sycl_kernel' attribute ignored | ||
| // CHECK-SPIR-DAG: 24:3: warning: 'clang::sycl_kernel' attribute ignored | ||
| [[clang::sycl_kernel]] void kernel4() {} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Honestly I'm wondering what we should do here. Realistically it would make sense for these 'named' attributes to just be legacy aliases to
device_kernel. I don't see any real value in keeping separate names unless there are special semantics that I'm unaware of. Ever since PTX moved over, this attribute is more plainly "set the kernel calling convention on this function."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.
It would definitely be simpler to have them as aliases. I'm happy to implement whatever the consensus us, so others feel free to drop in.
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.
I'd prefer to just make it an alias, I don't see any significant reason to keep it separate since this all implies the same thing of 'make this function callable by the external runtime'.
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.
Sure will do