1// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -triple spir-unknown-unknown | FileCheck %s
2// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -triple spir-unknown-unknown -cl-kernel-arg-info | FileCheck %s -check-prefix ARGINFO
3
4kernel void foo(global int * globalintp, global int * restrict globalintrestrictp,
5                global const int * globalconstintp,
6                global const int * restrict globalconstintrestrictp,
7                constant int * constantintp, constant int * restrict constantintrestrictp,
8                global const volatile int * globalconstvolatileintp,
9                global const volatile int * restrict globalconstvolatileintrestrictp,
10                global volatile int * globalvolatileintp,
11                global volatile int * restrict globalvolatileintrestrictp,
12                local int * localintp, local int * restrict localintrestrictp,
13                local const int * localconstintp,
14                local const int * restrict localconstintrestrictp,
15                local const volatile int * localconstvolatileintp,
16                local const volatile int * restrict localconstvolatileintrestrictp,
17                local volatile int * localvolatileintp,
18                local volatile int * restrict localvolatileintrestrictp,
19                int X, const int constint, const volatile int constvolatileint,
20                volatile int volatileint) {
21  *globalintrestrictp = constint + volatileint;
22}
23// CHECK: define{{.*}} spir_kernel void @foo{{[^!]+}}
24// CHECK: !kernel_arg_addr_space ![[MD11:[0-9]+]]
25// CHECK: !kernel_arg_access_qual ![[MD12:[0-9]+]]
26// CHECK: !kernel_arg_type ![[MD13:[0-9]+]]
27// CHECK: !kernel_arg_base_type ![[MD13]]
28// CHECK: !kernel_arg_type_qual ![[MD14:[0-9]+]]
29// CHECK-NOT: !kernel_arg_name
30// ARGINFO: !kernel_arg_name ![[MD15:[0-9]+]]
31
32kernel void foo2(read_only image1d_t img1, image2d_t img2, write_only image2d_array_t img3, read_write image1d_t img4) {
33}
34// CHECK: define{{.*}} spir_kernel void @foo2{{[^!]+}}
35// CHECK: !kernel_arg_addr_space ![[MD21:[0-9]+]]
36// CHECK: !kernel_arg_access_qual ![[MD22:[0-9]+]]
37// CHECK: !kernel_arg_type ![[MD23:[0-9]+]]
38// CHECK: !kernel_arg_base_type ![[MD23]]
39// CHECK: !kernel_arg_type_qual ![[MD24:[0-9]+]]
40// CHECK-NOT: !kernel_arg_name
41// ARGINFO: !kernel_arg_name ![[MD25:[0-9]+]]
42
43kernel void foo3(__global half * X) {
44}
45// CHECK: define{{.*}} spir_kernel void @foo3{{[^!]+}}
46// CHECK: !kernel_arg_addr_space ![[MD31:[0-9]+]]
47// CHECK: !kernel_arg_access_qual ![[MD32:[0-9]+]]
48// CHECK: !kernel_arg_type ![[MD33:[0-9]+]]
49// CHECK: !kernel_arg_base_type ![[MD33]]
50// CHECK: !kernel_arg_type_qual ![[MD34:[0-9]+]]
51// CHECK-NOT: !kernel_arg_name
52// ARGINFO: !kernel_arg_name ![[MD35:[0-9]+]]
53
54typedef unsigned int myunsignedint;
55kernel void foo4(__global unsigned int * X, __global myunsignedint * Y) {
56}
57// CHECK: define{{.*}} spir_kernel void @foo4{{[^!]+}}
58// CHECK: !kernel_arg_addr_space ![[MD41:[0-9]+]]
59// CHECK: !kernel_arg_access_qual ![[MD42:[0-9]+]]
60// CHECK: !kernel_arg_type ![[MD43:[0-9]+]]
61// CHECK: !kernel_arg_base_type ![[MD44:[0-9]+]]
62// CHECK: !kernel_arg_type_qual ![[MD45:[0-9]+]]
63// CHECK-NOT: !kernel_arg_name
64// ARGINFO: !kernel_arg_name ![[MD46:[0-9]+]]
65
66typedef image1d_t myImage;
67kernel void foo5(myImage img1, write_only image1d_t img2) {
68}
69// CHECK: define{{.*}} spir_kernel void @foo5{{[^!]+}}
70// CHECK: !kernel_arg_addr_space ![[MD41:[0-9]+]]
71// CHECK: !kernel_arg_access_qual ![[MD51:[0-9]+]]
72// CHECK: !kernel_arg_type ![[MD52:[0-9]+]]
73// CHECK: !kernel_arg_base_type ![[MD53:[0-9]+]]
74// CHECK: !kernel_arg_type_qual ![[MD45]]
75// CHECK-NOT: !kernel_arg_name
76// ARGINFO: !kernel_arg_name ![[MD54:[0-9]+]]
77
78typedef char char16 __attribute__((ext_vector_type(16)));
79__kernel void foo6(__global char16 arg[]) {}
80// CHECK: !kernel_arg_type ![[MD61:[0-9]+]]
81// ARGINFO: !kernel_arg_name ![[MD62:[0-9]+]]
82
83typedef read_only  image1d_t ROImage;
84typedef write_only image1d_t WOImage;
85typedef read_write image1d_t RWImage;
86kernel void foo7(ROImage ro, WOImage wo, RWImage rw) {
87}
88
89// CHECK: define{{.*}} spir_kernel void @foo7{{[^!]+}}
90// CHECK: !kernel_arg_addr_space ![[MD71:[0-9]+]]
91// CHECK: !kernel_arg_access_qual ![[MD72:[0-9]+]]
92// CHECK: !kernel_arg_type ![[MD73:[0-9]+]]
93// CHECK: !kernel_arg_base_type ![[MD74:[0-9]+]]
94// CHECK: !kernel_arg_type_qual ![[MD75:[0-9]+]]
95// CHECK-NOT: !kernel_arg_name
96// ARGINFO: !kernel_arg_name ![[MD76:[0-9]+]]
97
98typedef unsigned char uchar;
99typedef uchar uchar2 __attribute__((ext_vector_type(2)));
100kernel void foo8(pipe int p1, pipe uchar p2, pipe uchar2 p3, const pipe uchar p4, write_only pipe uchar p5) {}
101// CHECK: define{{.*}} spir_kernel void @foo8{{[^!]+}}
102// CHECK: !kernel_arg_addr_space ![[PIPE_AS_QUAL:[0-9]+]]
103// CHECK: !kernel_arg_access_qual ![[PIPE_ACCESS_QUAL:[0-9]+]]
104// CHECK: !kernel_arg_type ![[PIPE_TY:[0-9]+]]
105// CHECK: !kernel_arg_base_type ![[PIPE_BASE_TY:[0-9]+]]
106// CHECK: !kernel_arg_type_qual ![[PIPE_QUAL:[0-9]+]]
107// CHECK-NOT: !kernel_arg_name
108// ARGINFO: !kernel_arg_name ![[PIPE_ARG_NAMES:[0-9]+]]
109
110kernel void foo9(signed char sc1,  global const signed char* sc2) {}
111// CHECK: define{{.*}} spir_kernel void @foo9{{[^!]+}}
112// CHECK: !kernel_arg_addr_space ![[SCHAR_AS_QUAL:[0-9]+]]
113// CHECK: !kernel_arg_access_qual ![[MD42]]
114// CHECK: !kernel_arg_type ![[SCHAR_TY:[0-9]+]]
115// CHECK: !kernel_arg_base_type ![[SCHAR_TY]]
116// CHECK: !kernel_arg_type_qual ![[SCHAR_QUAL:[0-9]+]]
117// CHECK-NOT: !kernel_arg_name
118// ARGINFO: !kernel_arg_name ![[SCHAR_ARG_NAMES:[0-9]+]]
119
120// CHECK: ![[MD11]] = !{i32 1, i32 1, i32 1, i32 1, i32 2, i32 2, i32 1, i32 1, i32 1, i32 1, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 0, i32 0, i32 0, i32 0}
121// CHECK: ![[MD12]] = !{!"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none"}
122// CHECK: ![[MD13]] = !{!"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int", !"int", !"int", !"int"}
123// CHECK: ![[MD14]] = !{!"", !"restrict", !"const", !"restrict const", !"const", !"restrict const", !"const volatile", !"restrict const volatile", !"volatile", !"restrict volatile", !"", !"restrict", !"const", !"restrict const", !"const volatile", !"restrict const volatile", !"volatile", !"restrict volatile", !"", !"", !"", !""}
124// ARGINFO: ![[MD15]] = !{!"globalintp", !"globalintrestrictp", !"globalconstintp", !"globalconstintrestrictp", !"constantintp", !"constantintrestrictp", !"globalconstvolatileintp", !"globalconstvolatileintrestrictp", !"globalvolatileintp", !"globalvolatileintrestrictp", !"localintp", !"localintrestrictp", !"localconstintp", !"localconstintrestrictp", !"localconstvolatileintp", !"localconstvolatileintrestrictp", !"localvolatileintp", !"localvolatileintrestrictp", !"X", !"constint", !"constvolatileint", !"volatileint"}
125// CHECK: ![[MD21]] = !{i32 1, i32 1, i32 1, i32 1}
126// CHECK: ![[MD22]] = !{!"read_only", !"read_only", !"write_only", !"read_write"}
127// CHECK: ![[MD23]] = !{!"image1d_t", !"image2d_t", !"image2d_array_t", !"image1d_t"}
128// CHECK: ![[MD24]] = !{!"", !"", !"", !""}
129// ARGINFO: ![[MD25]] = !{!"img1", !"img2", !"img3", !"img4"}
130// CHECK: ![[MD31]] = !{i32 1}
131// CHECK: ![[MD32]] = !{!"none"}
132// CHECK: ![[MD33]] = !{!"half*"}
133// CHECK: ![[MD34]] = !{!""}
134// ARGINFO: ![[MD35]] = !{!"X"}
135// CHECK: ![[MD41]] = !{i32 1, i32 1}
136// CHECK: ![[MD42]] = !{!"none", !"none"}
137// CHECK: ![[MD43]] = !{!"uint*", !"myunsignedint*"}
138// CHECK: ![[MD44]] = !{!"uint*", !"uint*"}
139// CHECK: ![[MD45]] = !{!"", !""}
140// ARGINFO: ![[MD46]] = !{!"X", !"Y"}
141// CHECK: ![[MD51]] = !{!"read_only", !"write_only"}
142// CHECK: ![[MD52]] = !{!"myImage", !"image1d_t"}
143// CHECK: ![[MD53]] = !{!"image1d_t", !"image1d_t"}
144// ARGINFO: ![[MD54]] = !{!"img1", !"img2"}
145// CHECK: ![[MD61]] = !{!"char16*"}
146// ARGINFO: ![[MD62]] = !{!"arg"}
147// CHECK: ![[MD71]] = !{i32 1, i32 1, i32 1}
148// CHECK: ![[MD72]] = !{!"read_only", !"write_only", !"read_write"}
149// CHECK: ![[MD73]] = !{!"ROImage", !"WOImage", !"RWImage"}
150// CHECK: ![[MD74]] = !{!"image1d_t", !"image1d_t", !"image1d_t"}
151// CHECK: ![[MD75]] = !{!"", !"", !""}
152// ARGINFO: ![[MD76]] = !{!"ro", !"wo", !"rw"}
153// CHECK: ![[PIPE_AS_QUAL]] = !{i32 1, i32 1, i32 1, i32 1, i32 1}
154// CHECK: ![[PIPE_ACCESS_QUAL]] = !{!"read_only", !"read_only", !"read_only", !"read_only", !"write_only"}
155// CHECK: ![[PIPE_TY]] = !{!"int", !"uchar", !"uchar2", !"uchar", !"uchar"}
156// CHECK: ![[PIPE_BASE_TY]] = !{!"int", !"uchar", !"uchar __attribute__((ext_vector_type(2)))", !"uchar", !"uchar"}
157// CHECK: ![[PIPE_QUAL]] = !{!"pipe", !"pipe", !"pipe", !"pipe", !"pipe"}
158// ARGINFO: ![[PIPE_ARG_NAMES]] = !{!"p1", !"p2", !"p3", !"p4", !"p5"}
159// CHECK: ![[SCHAR_AS_QUAL]] = !{i32 0, i32 1}
160// CHECK: ![[SCHAR_TY]] = !{!"char", !"char*"}
161// CHECK: ![[SCHAR_QUAL]] = !{!"", !"const"}
162// ARGINFO: ![[SCHAR_ARG_NAMES]] = !{!"sc1", !"sc2"}
163