-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NVPTX] Auto-Upgrade some nvvm.annotations to attributes #119261
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 all commits
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 |
---|---|---|
|
@@ -310,30 +310,21 @@ std::optional<unsigned> getMaxNReg(const Function &F) { | |
return findOneNVVMAnnotation(&F, "maxnreg"); | ||
} | ||
|
||
bool isKernelFunction(const Function &F) { | ||
if (F.getCallingConv() == CallingConv::PTX_Kernel) | ||
return true; | ||
|
||
if (const auto X = findOneNVVMAnnotation(&F, "kernel")) | ||
return (*X == 1); | ||
|
||
return false; | ||
} | ||
|
||
MaybeAlign getAlign(const Function &F, unsigned Index) { | ||
// First check the alignstack metadata | ||
if (MaybeAlign StackAlign = | ||
F.getAttributes().getAttributes(Index).getStackAlignment()) | ||
return StackAlign; | ||
|
||
// If that is missing, check the legacy nvvm metadata | ||
std::vector<unsigned> Vs; | ||
bool retval = findAllNVVMAnnotation(&F, "align", Vs); | ||
if (!retval) | ||
return std::nullopt; | ||
for (unsigned V : Vs) | ||
if ((V >> 16) == Index) | ||
return Align(V & 0xFFFF); | ||
// check the legacy nvvm metadata only for the return value since llvm does | ||
// not support stackalign attribute for this. | ||
if (Index == 0) { | ||
std::vector<unsigned> Vs; | ||
if (findAllNVVMAnnotation(&F, "align", Vs)) | ||
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. Offtopic: I think if
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. Yea, I agree the NVVM annotation APIs could be cleaned up significantly, hopefully this work will remove the need for them altogether though. |
||
for (unsigned V : Vs) | ||
if ((V >> 16) == Index) | ||
return Align(V & 0xFFFF); | ||
} | ||
|
||
return std::nullopt; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --check-globals all --version 5 | ||
; RUN: opt < %s -mtriple=nvptx64-unknown-unknown -O0 -S | FileCheck %s | ||
|
||
define i32 @foo(i32 %a, i32 %b) { | ||
; CHECK-LABEL: define i32 @foo( | ||
; CHECK-SAME: i32 alignstack(8) [[A:%.*]], i32 alignstack(16) [[B:%.*]]) { | ||
; CHECK-NEXT: ret i32 0 | ||
; | ||
ret i32 0 | ||
} | ||
|
||
define i32 @bar(i32 %a, i32 %b) { | ||
; CHECK-LABEL: define ptx_kernel i32 @bar( | ||
; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) { | ||
; CHECK-NEXT: ret i32 0 | ||
; | ||
ret i32 0 | ||
} | ||
|
||
!nvvm.annotations = !{!0, !1, !2} | ||
|
||
!0 = !{ptr @foo, !"align", i32 u0x00000008, !"align", i32 u0x00010008, !"align", i32 u0x00020010} | ||
!1 = !{null, !"align", i32 u0x00000008, !"align", i32 u0x00010008, !"align", i32 u0x00020008} | ||
!2 = !{ptr @bar, !"kernel", i32 1} | ||
|
||
;. | ||
; CHECK: [[META0:![0-9]+]] = !{ptr @foo, !"align", i32 8} | ||
;. |
Uh oh!
There was an error while loading. Please reload this page.