Skip to content

Commit def5289

Browse files
committed
[NVPTX] Fix tests after nvvm.annotations autoupgrade in de7438e (#17081)
de7438e Add a new AutoUpgrade function to convert some legacy nvvm.annotations metadata to function level attributes. These attributes are quicker to look-up so improve compile time and are more idiomatic than using metadata which should not include required information that changes the meaning of the program. Currently supported annotations are: - !"kernel" -> ptx_kernel calling convention - !"align" -> alignstack parameter attributes (return not yet supported) so remove "kernel" and "align" from CHEK lines. Also update DeadArgumentElimination to check calling convension instead of annotation for kernel.
1 parent f348a6a commit def5289

10 files changed

+39
-105
lines changed

llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -148,43 +148,9 @@ class DeadArgumentEliminationPass
148148

149149
void UpdateNVPTXMetadata(Module &M, Function *F, Function *NF,
150150
const SmallVectorImpl<bool> &ArgAlive);
151-
llvm::DenseSet<Function *> NVPTXKernelSet;
152-
153-
bool IsNVPTXKernel(const Function *F) { return NVPTXKernelSet.contains(F); };
154-
155-
void BuildNVPTXKernelSet(const Module &M) {
156-
157-
auto *NvvmMetadata = M.getNamedMetadata("nvvm.annotations");
158-
if (!NvvmMetadata)
159-
return;
160-
161-
for (auto *MetadataNode : NvvmMetadata->operands()) {
162-
if (MetadataNode->getNumOperands() != 3)
163-
continue;
164-
165-
// NVPTX identifies kernel entry points using metadata nodes of the form:
166-
// !X = !{<function>, !"kernel", i32 1}
167-
auto *Type = dyn_cast<MDString>(MetadataNode->getOperand(1));
168-
// Only process kernel entry points.
169-
if (!Type || Type->getString() != "kernel")
170-
continue;
171-
172-
// Get a pointer to the entry point function from the metadata.
173-
if (const auto &FuncOperand = MetadataNode->getOperand(0)) {
174-
if (auto *FuncConstant = dyn_cast<ConstantAsMetadata>(FuncOperand)) {
175-
if (auto *Func = dyn_cast<Function>(FuncConstant->getValue())) {
176-
if (auto *Val = mdconst::dyn_extract<ConstantInt>(
177-
MetadataNode->getOperand(2))) {
178-
if (Val->getValue() == 1) {
179-
NVPTXKernelSet.insert(Func);
180-
}
181-
}
182-
}
183-
}
184-
}
185-
}
186-
return;
187-
}
151+
152+
bool IsNVPTXKernel(const Function *F) { return F->getCallingConv() == CallingConv::PTX_Kernel; };
153+
188154
};
189155

190156
class DeadArgumentEliminationSYCLPass

llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,8 +1224,6 @@ PreservedAnalyses DeadArgumentEliminationPass::run(Module &M,
12241224
ModuleAnalysisManager &) {
12251225
bool Changed = false;
12261226

1227-
BuildNVPTXKernelSet(M);
1228-
12291227
// First pass: Do a simple check to see if any functions can have their "..."
12301228
// removed. We can do this if they never call va_start. This loop cannot be
12311229
// fused with the next loop, because deleting a function invalidates

llvm/test/CodeGen/NVPTX/global-offset-annotations.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ define i64 @_ZTS14other_function() {
1616
ret i64 %4
1717
}
1818

19-
define void @_ZTS14example_kernel() {
19+
define ptx_kernel void @_ZTS14example_kernel() {
2020
entry:
2121
%0 = call i64 @_ZTS14other_function()
2222
ret void
2323
}
2424

25-
; CHECK: !nvvm.annotations = !{![[OLDMD0:[0-9]+]], ![[OLDMD1:[0-9]+]], ![[OLDMD1]], ![[OLDMD0]]}
25+
; CHECK: !nvvm.annotations = !{![[OLDMD0:[0-9]+]], ![[OLDMD1:[0-9]+]]}
2626

2727
!llvm.module.flags = !{!0}
2828
!nvvm.annotations = !{!1, !2, !2, !1}
2929

30-
; CHECK: ![[OLDMD0]] = distinct !{ptr @_ZTS14example_kernel, !"maxnreg", i32 256, !"kernel", i32 1}
30+
; CHECK: ![[OLDMD0]] = !{ptr @_ZTS14example_kernel, !"maxnreg", i32 256}
3131
; CHECK: ![[OLDMD1]] = !{ptr @_ZTS14example_kernel, !"maxntidx", i32 8, !"maxntidy", i32 16, !"maxntidz", i32 32}
3232

3333
!0 = !{i32 1, !"sycl-device", i32 1}

llvm/test/CodeGen/NVPTX/global-offset-dbg.ll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ entry:
7777
; CHECK: [[META4:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3}
7878
; CHECK: [[META5:![0-9]+]] = !{i32 1, !"sycl-device", i32 1}
7979
; CHECK: [[META7:![0-9]+]] = !{i32 1, i32 4}
80-
; CHECK: [[META8:![0-9]+]] = !{null, !"align", i32 8, !"align", i32 65544, !"align", i32 131080}
81-
; CHECK: [[META9:![0-9]+]] = !{null, !"align", i32 16}
82-
; CHECK: [[META10:![0-9]+]] = !{null, !"align", i32 16, !"align", i32 65552, !"align", i32 131088}
8380
; CHECK: [[DBG12]] = distinct !DISubprogram(name: "other_function", scope: [[META1]], file: [[META1]], line: 3, type: [[META13:![0-9]+]], scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]], retainedNodes: [[META2]])
8481
; CHECK: [[META13]] = !DISubroutineType(types: [[META14:![0-9]+]])
8582
; CHECK: [[META14]] = !{null}

llvm/test/CodeGen/NVPTX/local-accessor-to-shared-memory-annotations.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ entry:
2727
; CHECK: @_ZTS14example_kernel_shared_mem = external addrspace(3) global [0 x i8], align 4
2828
;.
2929
; CHECK-LABEL: define ptx_kernel void @_ZTS14example_kernel(
30-
; CHECK-SAME: i32 [[TMP0:%.*]], ptr addrspace(1) [[B:%.*]], i32 [[C:%.*]]) {
30+
; CHECK-SAME: i32 [[TMP0:%.*]], ptr addrspace(1) alignstack(8) [[B:%.*]], i32 [[C:%.*]]) {
3131
; CHECK-NEXT: [[ENTRY:.*:]]
3232
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [0 x i8], ptr addrspace(3) @_ZTS14example_kernel_shared_mem, i32 0, i32 [[TMP0]]
3333
; CHECK-NEXT: [[A:%.*]] = bitcast ptr addrspace(3) [[TMP1]] to ptr addrspace(3)
@@ -39,7 +39,6 @@ entry:
3939
;.
4040
; CHECK: [[META0:![0-9]+]] = !{i32 1, !"sycl-device", i32 1}
4141
; CHECK: [[META1:![0-9]+]] = distinct !{ptr @_ZTS14example_kernel, !"maxntidx", i32 256, !"dummy", i32 1, !"maxntidy", i32 64}
42-
; CHECK: [[META2:![0-9]+]] = distinct !{ptr @_ZTS14example_kernel, !"align", i32 8, !"align", i32 65544, !"align", i32 131080}
4342
; CHECK: [[META3:![0-9]+]] = distinct !{ptr @_ZTS14example_kernel, !"maxntidz", i32 256}
4443
; CHECK: [[META4:![0-9]+]] = distinct !{ptr @_ZTS14example_kernel, !"dummy", i32 1}
4544
;.

llvm/test/CodeGen/NVPTX/local-accessor-to-shared-memory-basic-transformation.ll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ entry:
4545
;.
4646
; CHECK: [[META0:![0-9]+]] = !{i32 1, !"sycl-device", i32 1}
4747
; CHECK: [[META1:![0-9]+]] = distinct !{ptr @_ZTS14example_kernel, !"dummy", i32 1}
48-
; CHECK: [[META2:![0-9]+]] = !{null, !"align", i32 8}
49-
; CHECK: [[META3:![0-9]+]] = !{null, !"align", i32 8, !"align", i32 65544, !"align", i32 131080}
50-
; CHECK: [[META4:![0-9]+]] = !{null, !"align", i32 16}
51-
; CHECK: [[META5:![0-9]+]] = !{null, !"align", i32 16, !"align", i32 65552, !"align", i32 131088}
5248
; CHECK: [[META6:![0-9]+]] = distinct !{ptr @_ZTS14example_kernel, !"maxntidx", i32 256}
5349
; CHECK: [[META7:![0-9]+]] = !{i32 1, i32 4}
5450
;.

llvm/test/CodeGen/NVPTX/local-accessor-to-shared-memory-multiple-functions.ll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,5 @@ entry:
5353
;.
5454
; CHECK: [[META0:![0-9]+]] = !{i32 1, !"sycl-device", i32 1}
5555
; CHECK: [[META1:![0-9]+]] = distinct !{ptr @_ZTS14example_kernel, !"dummy", i32 1}
56-
; CHECK: [[META2:![0-9]+]] = !{null, !"align", i32 8}
57-
; CHECK: [[META3:![0-9]+]] = !{null, !"align", i32 8, !"align", i32 65544, !"align", i32 131080}
58-
; CHECK: [[META4:![0-9]+]] = !{null, !"align", i32 16}
59-
; CHECK: [[META5:![0-9]+]] = !{null, !"align", i32 16, !"align", i32 65552, !"align", i32 131088}
6056
; CHECK: [[META6:![0-9]+]] = !{i32 1, i32 4}
6157
;.

llvm/test/CodeGen/NVPTX/local-accessor-to-shared-memory-no-entry-points.ll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,5 @@ entry:
3434
!5 = !{i32 1, !"sycl-device", i32 1}
3535
;.
3636
; CHECK: [[META0:![0-9]+]] = !{i32 1, !"sycl-device", i32 1}
37-
; CHECK: [[META1:![0-9]+]] = !{null, !"align", i32 8}
38-
; CHECK: [[META2:![0-9]+]] = !{null, !"align", i32 8, !"align", i32 65544, !"align", i32 131080}
39-
; CHECK: [[META3:![0-9]+]] = !{null, !"align", i32 16}
40-
; CHECK: [[META4:![0-9]+]] = !{null, !"align", i32 16, !"align", i32 65552, !"align", i32 131088}
4137
; CHECK: [[META5:![0-9]+]] = !{i32 1, i32 4}
4238
;.

llvm/test/CodeGen/NVPTX/local-accessor-to-shared-memory-preserves-types.ll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,5 @@ entry:
5050
;.
5151
; CHECK: [[META0:![0-9]+]] = !{i32 1, !"sycl-device", i32 1}
5252
; CHECK: [[META1:![0-9]+]] = distinct !{ptr @_ZTS14example_kernel, !"dummy", i32 1}
53-
; CHECK: [[META2:![0-9]+]] = !{null, !"align", i32 8}
54-
; CHECK: [[META3:![0-9]+]] = !{null, !"align", i32 8, !"align", i32 65544, !"align", i32 131080}
55-
; CHECK: [[META4:![0-9]+]] = !{null, !"align", i32 16}
56-
; CHECK: [[META5:![0-9]+]] = !{null, !"align", i32 16, !"align", i32 65552, !"align", i32 131088}
5753
; CHECK: [[META6:![0-9]+]] = !{i32 1, i32 4}
5854
;.
Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 5
22
; RUN: opt < %s -passes=deadargelim -S | FileCheck %s
33

4-
define internal void @test1(i32 %v, ptr byval(i32) %DEADARG1, ptr %p) {
5-
; CHECK-LABEL: define internal void @test1(
4+
define internal ptx_kernel void @test1(i32 %v, ptr byval(i32) %DEADARG1, ptr %p) {
5+
; CHECK-LABEL: define internal ptx_kernel void @test1(
66
; CHECK-SAME: i32 [[V:%.*]], ptr [[P:%.*]]) {
77
; CHECK-NEXT: store i32 [[V]], ptr [[P]], align 4
88
; CHECK-NEXT: ret void
@@ -11,8 +11,8 @@ define internal void @test1(i32 %v, ptr byval(i32) %DEADARG1, ptr %p) {
1111
ret void
1212
}
1313

14-
define internal void @test2(ptr byval(i32) %DEADARG1, ptr byval(i32) %p) {
15-
; CHECK-LABEL: define internal void @test2(
14+
define internal ptx_kernel void @test2(ptr byval(i32) %DEADARG1, ptr byval(i32) %p) {
15+
; CHECK-LABEL: define internal ptx_kernel void @test2(
1616
; CHECK-SAME: ptr byval(i32) [[P:%.*]]) {
1717
; CHECK-NEXT: store i32 0, ptr [[P]], align 4
1818
; CHECK-NEXT: ret void
@@ -21,8 +21,8 @@ define internal void @test2(ptr byval(i32) %DEADARG1, ptr byval(i32) %p) {
2121
ret void
2222
}
2323

24-
define internal void @test3(ptr byval(i32) %DEADARG1, i32 %v, ptr byval(i32) %p) {
25-
; CHECK-LABEL: define internal void @test3(
24+
define internal ptx_kernel void @test3(ptr byval(i32) %DEADARG1, i32 %v, ptr byval(i32) %p) {
25+
; CHECK-LABEL: define internal ptx_kernel void @test3(
2626
; CHECK-SAME: i32 [[V:%.*]], ptr byval(i32) [[P:%.*]]) {
2727
; CHECK-NEXT: store i32 [[V]], ptr [[P]], align 4
2828
; CHECK-NEXT: ret void
@@ -31,8 +31,8 @@ define internal void @test3(ptr byval(i32) %DEADARG1, i32 %v, ptr byval(i32) %p)
3131
ret void
3232
}
3333

34-
define internal void @test4(ptr byval(i32) %p, i32 %v, ptr byval(i32) %DEADARG) {
35-
; CHECK-LABEL: define internal void @test4(
34+
define internal ptx_kernel void @test4(ptr byval(i32) %p, i32 %v, ptr byval(i32) %DEADARG) {
35+
; CHECK-LABEL: define internal ptx_kernel void @test4(
3636
; CHECK-SAME: ptr byval(i32) [[P:%.*]], i32 [[V:%.*]]) {
3737
; CHECK-NEXT: store i32 [[V]], ptr [[P]], align 4
3838
; CHECK-NEXT: ret void
@@ -41,8 +41,8 @@ define internal void @test4(ptr byval(i32) %p, i32 %v, ptr byval(i32) %DEADARG)
4141
ret void
4242
}
4343

44-
define internal void @test5(ptr byval(i32) %p, i32 %x, ptr byval(i32) %DEADARG1, ptr byval(i32) %DEADARG2, i32 %y, ptr byval(i32) %q) {
45-
; CHECK-LABEL: define internal void @test5(
44+
define internal ptx_kernel void @test5(ptr byval(i32) %p, i32 %x, ptr byval(i32) %DEADARG1, ptr byval(i32) %DEADARG2, i32 %y, ptr byval(i32) %q) {
45+
; CHECK-LABEL: define internal ptx_kernel void @test5(
4646
; CHECK-SAME: ptr byval(i32) [[P:%.*]], i32 [[X:%.*]], i32 [[Y:%.*]], ptr byval(i32) [[Q:%.*]]) {
4747
; CHECK-NEXT: [[T:%.*]] = add i32 [[X]], [[Y]]
4848
; CHECK-NEXT: store i32 [[T]], ptr [[P]], align 4
@@ -56,58 +56,48 @@ define internal void @test5(ptr byval(i32) %p, i32 %x, ptr byval(i32) %DEADARG1,
5656
}
5757

5858
!nvvm.annotations = !{
59-
!0, !1,
60-
!3, !4, !6,
61-
!8, !9, !11,
62-
!13, !14, !16,
63-
!18, !19
59+
!0,
60+
!2, !4,
61+
!6, !8,
62+
!10, !12,
63+
!14
6464
}
6565

6666
; Note - also test various permutations of the parameter lists, as they are not
6767
; specified to be in any particular order (e.g., consecutive).
68-
!0 = !{ptr @test1, !"kernel", i32 1}
69-
!1 = !{ptr @test1, !"grid_constant", !2}
70-
!2 = !{i32 2}
68+
!0 = !{ptr @test1, !"grid_constant", !1}
69+
!1 = !{i32 2}
7170

72-
!3 = !{ptr @test2, !"kernel", i32 1}
71+
!2 = !{ptr @test2, !"grid_constant", !3}
72+
!3 = !{i32 1, i32 2}
7373
!4 = !{ptr @test2, !"grid_constant", !5}
74-
!5 = !{i32 1, i32 2}
75-
!6 = !{ptr @test2, !"grid_constant", !7}
76-
!7 = !{i32 2, i32 1}
74+
!5 = !{i32 2, i32 1}
7775

78-
!8 = !{ptr @test3, !"kernel", i32 1}
79-
!9 = !{ptr @test3, !"grid_constant", !10}
80-
!10 = !{i32 1, i32 3}
81-
!11 = !{ptr @test3, !"grid_constant", !12}
82-
!12 = !{i32 3, i32 1}
76+
!6 = !{ptr @test3, !"grid_constant", !7}
77+
!7 = !{i32 1, i32 3}
78+
!8 = !{ptr @test3, !"grid_constant", !9}
79+
!9 = !{i32 3, i32 1}
8380

84-
!13 = !{ptr @test4, !"kernel", i32 1}
85-
!14 = !{ptr @test4, !"grid_constant", !15}
86-
!15 = !{i32 1, i32 3}
87-
!16 = !{ptr @test4, !"grid_constant", !17}
88-
!17 = !{i32 3, i32 1}
81+
!10 = !{ptr @test4, !"grid_constant", !11}
82+
!11 = !{i32 1, i32 3}
83+
!12 = !{ptr @test4, !"grid_constant", !13}
84+
!13 = !{i32 3, i32 1}
8985

90-
!18 = !{ptr @test5, !"kernel", i32 1}
91-
!19 = !{ptr @test5, !"grid_constant", !20, !"grid_constant", !21, !"grid_constant", !22}
92-
!20 = !{i32 1, i32 3, i32 4, i32 6}
93-
!21 = !{i32 3, i32 1, i32 4, i32 6}
94-
!22 = !{i32 3, i32 1, i32 6, i32 4}
86+
!14 = !{ptr @test5, !"grid_constant", !15, !"grid_constant", !16, !"grid_constant", !17}
87+
!15 = !{i32 1, i32 3, i32 4, i32 6}
88+
!16 = !{i32 3, i32 1, i32 4, i32 6}
89+
!17 = !{i32 3, i32 1, i32 6, i32 4}
9590
;.
96-
; CHECK: [[META0:![0-9]+]] = !{ptr @test1, !"kernel", i32 1}
9791
; CHECK: [[META1:![0-9]+]] = !{ptr @test1, !"grid_constant", [[META2:![0-9]+]]}
9892
; CHECK: [[META2]] = !{}
99-
; CHECK: [[META3:![0-9]+]] = !{ptr @test2, !"kernel", i32 1}
10093
; CHECK: [[META4:![0-9]+]] = !{ptr @test2, !"grid_constant", [[META5:![0-9]+]]}
10194
; CHECK: [[META5]] = !{i32 1}
10295
; CHECK: [[META6:![0-9]+]] = distinct !{ptr @test2, !"grid_constant", [[META5]]}
103-
; CHECK: [[META7:![0-9]+]] = !{ptr @test3, !"kernel", i32 1}
10496
; CHECK: [[META8:![0-9]+]] = !{ptr @test3, !"grid_constant", [[META9:![0-9]+]]}
10597
; CHECK: [[META9]] = !{i32 2}
10698
; CHECK: [[META10:![0-9]+]] = distinct !{ptr @test3, !"grid_constant", [[META9]]}
107-
; CHECK: [[META11:![0-9]+]] = !{ptr @test4, !"kernel", i32 1}
10899
; CHECK: [[META12:![0-9]+]] = !{ptr @test4, !"grid_constant", [[META5]]}
109100
; CHECK: [[META13:![0-9]+]] = distinct !{ptr @test4, !"grid_constant", [[META5]]}
110-
; CHECK: [[META14:![0-9]+]] = !{ptr @test5, !"kernel", i32 1}
111101
; CHECK: [[META15:![0-9]+]] = !{ptr @test5, !"grid_constant", [[META16:![0-9]+]], !"grid_constant", [[META16]], !"grid_constant", [[META16]]}
112102
; CHECK: [[META16]] = !{i32 1, i32 4}
113103
;.

0 commit comments

Comments
 (0)