[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Headers / opencl-c-header.cl
blob7317ff0adaafb3c307d6c1174ef306e68d0e1e70
1 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify | FileCheck %s
2 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.1 | FileCheck %s
3 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.2 | FileCheck %s
4 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=clc++1.0 | FileCheck %s --check-prefix=CHECK20
5 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL3.0 | FileCheck %s
6 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=clc++2021 | FileCheck %s
8 // RUN: %clang_cc1 -O0 -triple spirv32-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify | FileCheck %s
11 // Test including the default header as a module.
12 // The module should be compiled only once and loaded from cache afterwards.
13 // Change the directory mode to read only to make sure no new modules are created.
14 // Check time report to make sure module is used.
15 // Check that some builtins occur in the generated IR when called.
17 // ===
18 // Clear current directory.
19 // RUN: rm -rf %t
20 // RUN: mkdir -p %t
22 // ===
23 // Compile for OpenCL 1.0 for the first time. A module should be generated.
24 // RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm -o - -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fdisable-module-hash -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=CHECK-MOD %s
25 // RUN: chmod u-w %t/opencl_c.pcm
27 // ===
28 // Compile for OpenCL 1.0 for the second time. The module should not be re-created.
29 // RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm -o - -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fdisable-module-hash -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=CHECK-MOD %s
30 // RUN: chmod u+w %t/opencl_c.pcm
31 // RUN: mv %t/opencl_c.pcm %t/1_0.pcm
33 // ===
34 // Compile for OpenCL 2.0 for the first time. The module should change.
35 // RUN: %clang_cc1 -triple spir-unknown-unknown -O0 -emit-llvm -o - -cl-std=CL2.0 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fdisable-module-hash -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK20 --check-prefix=CHECK-MOD %s
36 // RUN: not diff %t/1_0.pcm %t/opencl_c.pcm
37 // RUN: chmod u-w %t/opencl_c.pcm
39 // ===
40 // Compile for OpenCL 2.0 for the second time. The module should not change.
41 // RUN: %clang_cc1 -triple spir-unknown-unknown -O0 -emit-llvm -o - -cl-std=CL2.0 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fdisable-module-hash -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK20 --check-prefix=CHECK-MOD %s
43 // Check cached module works for different OpenCL versions.
44 // RUN: rm -rf %t
45 // RUN: mkdir -p %t
46 // RUN: %clang_cc1 -triple spir64-unknown-unknown -emit-llvm -o - -cl-std=CL1.2 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=CHECK-MOD %s
47 // RUN: %clang_cc1 -triple amdgcn--amdhsa -O0 -emit-llvm -o - -cl-std=CL2.0 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK20 --check-prefix=CHECK-MOD %s
48 // RUN: chmod u-w %t
49 // RUN: %clang_cc1 -triple spir64-unknown-unknown -emit-llvm -o - -cl-std=CL1.2 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=CHECK-MOD %s
50 // RUN: %clang_cc1 -triple amdgcn--amdhsa -O0 -emit-llvm -o - -cl-std=CL2.0 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK20 --check-prefix=CHECK-MOD %s
51 // RUN: chmod u+w %t
53 // Verify that called builtins occur in the generated IR.
55 // CHECK-NOT: intel_sub_group_avc_mce_get_default_inter_base_multi_reference_penalty
56 // CHECK-NOT: ndrange_t
57 // CHECK20: ndrange_t
58 // CHECK: _Z16convert_char_rtec
59 // CHECK-NOT: _Z3ctzc
60 // CHECK20: _Z3ctzc
61 // CHECK20: _Z16convert_char_rtec
62 char f(char x) {
63 // Check functionality from OpenCL 2.0 onwards
64 #if (__OPENCL_CPP_VERSION__ == 100) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
65 ndrange_t t;
66 x = ctz(x);
67 #endif //__OPENCL_C_VERSION__
68 return convert_char_rte(x);
71 // Verify that a builtin using a write_only image3d_t type is available
72 // from OpenCL 2.0 onwards.
74 // CHECK20: _Z12write_imagef14ocl_image3d_wo
75 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
76 void test_image3dwo(write_only image3d_t img) {
77 write_imagef(img, (0), (0.0f));
79 #endif //__OPENCL_C_VERSION__
81 #if defined(__OPENCL_CPP_VERSION__)
82 // Test old atomic overloaded with generic addr space.
83 void test_atomics(__generic volatile unsigned int* a) {
84 atomic_add(a, 1);
86 #endif
88 // Verify that ATOMIC_VAR_INIT is defined.
89 #if (__OPENCL_CPP_VERSION__ == 100) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
90 global atomic_int z = ATOMIC_VAR_INIT(99);
91 #endif //__OPENCL_C_VERSION__
92 // CHECK-MOD: Reading modules
94 // Check that extension macros are defined correctly.
96 // For SPIR all extensions are supported.
97 #if defined(__SPIR__) || defined(__SPIRV__)
99 // Verify that cl_intel_planar_yuv extension is defined from OpenCL 1.2 onwards.
100 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
101 // expected-no-diagnostics
102 #else //__OPENCL_C_VERSION__
103 // expected-warning@+2{{OpenCL extension 'cl_intel_planar_yuv' unknown or does not require pragma - ignoring}}
104 #endif //__OPENCL_C_VERSION__
105 #pragma OPENCL EXTENSION cl_intel_planar_yuv : enable
107 #if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
109 #if cl_khr_subgroup_extended_types != 1
110 #error "Incorrectly defined cl_khr_subgroup_extended_types"
111 #endif
112 #if cl_khr_subgroup_non_uniform_vote != 1
113 #error "Incorrectly defined cl_khr_subgroup_non_uniform_vote"
114 #endif
115 #if cl_khr_subgroup_ballot != 1
116 #error "Incorrectly defined cl_khr_subgroup_ballot"
117 #endif
118 #if cl_khr_subgroup_non_uniform_arithmetic != 1
119 #error "Incorrectly defined cl_khr_subgroup_non_uniform_arithmetic"
120 #endif
121 #if cl_khr_subgroup_shuffle != 1
122 #error "Incorrectly defined cl_khr_subgroup_shuffle"
123 #endif
124 #if cl_khr_subgroup_shuffle_relative != 1
125 #error "Incorrectly defined cl_khr_subgroup_shuffle_relative"
126 #endif
127 #if cl_khr_subgroup_clustered_reduce != 1
128 #error "Incorrectly defined cl_khr_subgroup_clustered_reduce"
129 #endif
130 #if cl_khr_subgroup_rotate != 1
131 #error "Incorrectly defined cl_khr_subgroup_rotate"
132 #endif
133 #if cl_khr_extended_bit_ops != 1
134 #error "Incorrectly defined cl_khr_extended_bit_ops"
135 #endif
136 #if cl_khr_integer_dot_product != 1
137 #error "Incorrectly defined cl_khr_integer_dot_product"
138 #endif
139 #if __opencl_c_integer_dot_product_input_4x8bit != 1
140 #error "Incorrectly defined __opencl_c_integer_dot_product_input_4x8bit"
141 #endif
142 #if __opencl_c_integer_dot_product_input_4x8bit_packed != 1
143 #error "Incorrectly defined __opencl_c_integer_dot_product_input_4x8bit_packed"
144 #endif
145 #if cl_ext_float_atomics != 1
146 #error "Incorrectly defined cl_ext_float_atomics"
147 #endif
148 #if __opencl_c_ext_fp16_global_atomic_load_store != 1
149 #error "Incorrectly defined __opencl_c_ext_fp16_global_atomic_load_store"
150 #endif
151 #if __opencl_c_ext_fp16_local_atomic_load_store != 1
152 #error "Incorrectly defined __opencl_c_ext_fp16_local_atomic_load_store"
153 #endif
154 #if __opencl_c_ext_fp16_global_atomic_add != 1
155 #error "Incorrectly defined __opencl_c_ext_fp16_global_atomic_add"
156 #endif
157 #if __opencl_c_ext_fp32_global_atomic_add != 1
158 #error "Incorrectly defined __opencl_c_ext_fp32_global_atomic_add"
159 #endif
160 #if __opencl_c_ext_fp64_global_atomic_add != 1
161 #error "Incorrectly defined __opencl_c_ext_fp64_global_atomic_add"
162 #endif
163 #if __opencl_c_ext_fp16_local_atomic_add != 1
164 #error "Incorrectly defined __opencl_c_ext_fp16_local_atomic_add"
165 #endif
166 #if __opencl_c_ext_fp32_local_atomic_add != 1
167 #error "Incorrectly defined __opencl_c_ext_fp32_local_atomic_add"
168 #endif
169 #if __opencl_c_ext_fp64_local_atomic_add != 1
170 #error "Incorrectly defined __opencl_c_ext_fp64_local_atomic_add"
171 #endif
172 #if __opencl_c_ext_fp16_global_atomic_min_max != 1
173 #error "Incorrectly defined __opencl_c_ext_fp16_global_atomic_min_max"
174 #endif
175 #if __opencl_c_ext_fp32_global_atomic_min_max != 1
176 #error "Incorrectly defined __opencl_c_ext_fp32_global_atomic_min_max"
177 #endif
178 #if __opencl_c_ext_fp64_global_atomic_min_max != 1
179 #error "Incorrectly defined __opencl_c_ext_fp64_global_atomic_min_max"
180 #endif
181 #if __opencl_c_ext_fp16_local_atomic_min_max != 1
182 #error "Incorrectly defined __opencl_c_ext_fp16_local_atomic_min_max"
183 #endif
184 #if __opencl_c_ext_fp32_local_atomic_min_max != 1
185 #error "Incorrectly defined __opencl_c_ext_fp32_local_atomic_min_max"
186 #endif
187 #if __opencl_c_ext_fp64_local_atomic_min_max != 1
188 #error "Incorrectly defined __opencl_c_ext_fp64_local_atomic_min_max"
189 #endif
190 #if __opencl_c_ext_image_raw10_raw12 != 1
191 #error "Incorrectly defined __opencl_c_ext_image_raw10_raw12"
192 #endif
193 #if __opencl_c_ext_image_unorm_int_2_101010 != 1
194 #error "Incorrectly defined __opencl_c_ext_image_unorm_int_2_101010"
195 #endif
197 #else
199 #ifdef cl_khr_subgroup_extended_types
200 #error "Incorrect cl_khr_subgroup_extended_types define"
201 #endif
202 #ifdef cl_khr_subgroup_non_uniform_vote
203 #error "Incorrect cl_khr_subgroup_non_uniform_vote define"
204 #endif
205 #ifdef cl_khr_subgroup_ballot
206 #error "Incorrect cl_khr_subgroup_ballot define"
207 #endif
208 #ifdef cl_khr_subgroup_non_uniform_arithmetic
209 #error "Incorrect cl_khr_subgroup_non_uniform_arithmetic define"
210 #endif
211 #ifdef cl_khr_subgroup_shuffle
212 #error "Incorrect cl_khr_subgroup_shuffle define"
213 #endif
214 #ifdef cl_khr_subgroup_shuffle_relative
215 #error "Incorrect cl_khr_subgroup_shuffle_relative define"
216 #endif
217 #ifdef cl_khr_subgroup_clustered_reduce
218 #error "Incorrect cl_khr_subgroup_clustered_reduce define"
219 #endif
220 #ifdef cl_khr_subgroup_rotate
221 #error "Incorrect cl_khr_subgroup_rotate define"
222 #endif
223 #ifdef cl_khr_extended_bit_ops
224 #error "Incorrect cl_khr_extended_bit_ops define"
225 #endif
226 #ifdef cl_khr_integer_dot_product
227 #error "Incorrect cl_khr_integer_dot_product define"
228 #endif
229 #ifdef __opencl_c_integer_dot_product_input_4x8bit
230 #error "Incorrect __opencl_c_integer_dot_product_input_4x8bit define"
231 #endif
232 #ifdef __opencl_c_integer_dot_product_input_4x8bit_packed
233 #error "Incorrect __opencl_c_integer_dot_product_input_4x8bit_packed define"
234 #endif
235 #ifdef cl_ext_float_atomics
236 #error "Incorrect cl_ext_float_atomics define"
237 #endif
238 #ifdef __opencl_c_ext_fp16_global_atomic_load_store
239 #error "Incorrect __opencl_c_ext_fp16_global_atomic_load_store define"
240 #endif
241 #ifdef __opencl_c_ext_fp16_local_atomic_load_store
242 #error "Incorrect __opencl_c_ext_fp16_local_atomic_load_store define"
243 #endif
244 #ifdef __opencl_c_ext_fp16_global_atomic_add
245 #error "Incorrect __opencl_c_ext_fp16_global_atomic_add define"
246 #endif
247 #ifdef __opencl_c_ext_fp32_global_atomic_add
248 #error "Incorrect __opencl_c_ext_fp32_global_atomic_add define"
249 #endif
250 #ifdef __opencl_c_ext_fp64_global_atomic_add
251 #error "Incorrect __opencl_c_ext_fp64_global_atomic_add define"
252 #endif
253 #ifdef __opencl_c_ext_fp16_local_atomic_add
254 #error "Incorrect __opencl_c_ext_fp16_local_atomic_add define"
255 #endif
256 #ifdef __opencl_c_ext_fp32_local_atomic_add
257 #error "Incorrect __opencl_c_ext_fp32_local_atomic_add define"
258 #endif
259 #ifdef __opencl_c_ext_fp64_local_atomic_add
260 #error "Incorrect __opencl_c_ext_fp64_local_atomic_add define"
261 #endif
262 #ifdef __opencl_c_ext_fp16_global_atomic_min_max
263 #error "Incorrect __opencl_c_ext_fp16_global_atomic_min_max define"
264 #endif
265 #ifdef __opencl_c_ext_fp32_global_atomic_min_max
266 #error "Incorrect __opencl_c_ext_fp32_global_atomic_min_max define"
267 #endif
268 #ifdef __opencl_c_ext_fp64_global_atomic_min_max
269 #error "Incorrect __opencl_c_ext_fp64_global_atomic_min_max define"
270 #endif
271 #ifdef __opencl_c_ext_fp16_local_atomic_min_max
272 #error "Incorrect __opencl_c_ext_fp16_local_atomic_min_max define"
273 #endif
274 #ifdef __opencl_c_ext_fp32_local_atomic_min_max
275 #error "Incorrect __opencl_c_ext_fp32_local_atomic_min_max define"
276 #endif
277 #ifdef __opencl_c_ext_fp64_local_atomic_min_max
278 #error "Incorrect __opencl_c_ext_fp64_local_atomic_min_max define"
279 #endif
280 #ifdef __opencl_c_ext_image_raw10_raw12
281 #error "Incorrect __opencl_c_ext_image_raw10_raw12 define"
282 #endif
283 #ifdef __opencl_c_ext_image_unorm_int_2_101010
284 #error "Incorrect __opencl_c_ext_image_unorm_int_2_101010 define"
285 #endif
287 #endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
289 // OpenCL C features.
290 #if (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
292 #if __opencl_c_atomic_scope_all_devices != 1
293 #error "Incorrectly defined feature macro __opencl_c_atomic_scope_all_devices"
294 #endif
296 #elif (__OPENCL_CPP_VERSION__ == 100 || __OPENCL_C_VERSION__ == 200)
298 #ifndef __opencl_c_pipes
299 #error "Feature macro __opencl_c_pipes should be defined"
300 #endif
301 #ifndef __opencl_c_generic_address_space
302 #error "Feature macro __opencl_c_generic_address_space should be defined"
303 #endif
304 #ifndef __opencl_c_work_group_collective_functions
305 #error "Feature macro __opencl_c_work_group_collective_functions should be defined"
306 #endif
307 #ifndef __opencl_c_atomic_order_acq_rel
308 #error "Feature macro __opencl_c_atomic_order_acq_rel should be defined"
309 #endif
310 #ifndef __opencl_c_atomic_order_seq_cst
311 #error "Feature macro __opencl_c_atomic_order_seq_cst should be defined"
312 #endif
313 #ifndef __opencl_c_atomic_scope_device
314 #error "Feature macro __opencl_c_atomic_scope_device should be defined"
315 #endif
316 #ifndef __opencl_c_atomic_scope_all_devices
317 #error "Feature macro __opencl_c_atomic_scope_all_devices should be defined"
318 #endif
319 #ifndef __opencl_c_device_enqueue
320 #error "Feature macro __opencl_c_device_enqueue should be defined"
321 #endif
322 #ifndef __opencl_c_read_write_images
323 #error "Feature macro __opencl_c_read_write_images should be defined"
324 #endif
325 #ifndef __opencl_c_program_scope_global_variables
326 #error "Feature macro __opencl_c_program_scope_global_variables should be defined"
327 #endif
328 #ifndef __opencl_c_images
329 #error "Feature macro __opencl_c_images should be defined"
330 #endif
332 #elif (__OPENCL_C_VERSION__ < 200)
334 #ifdef __opencl_c_pipes
335 #error "Incorrect feature macro __opencl_c_pipes define"
336 #endif
337 #ifdef __opencl_c_generic_address_space
338 #error "Incorrect feature macro __opencl_c_generic_address_space define"
339 #endif
340 #ifdef __opencl_c_work_group_collective_functions
341 #error "Incorrect feature macro __opencl_c_work_group_collective_functions define"
342 #endif
343 #ifdef __opencl_c_atomic_order_acq_rel
344 #error "Incorrect feature macro __opencl_c_atomic_order_acq_rel define"
345 #endif
346 #ifdef __opencl_c_atomic_order_seq_cst
347 #error "Incorrect feature macro __opencl_c_atomic_order_seq_cst define"
348 #endif
349 #ifdef __opencl_c_atomic_scope_device
350 #error "Incorrect feature macro __opencl_c_atomic_scope_device define"
351 #endif
352 #ifdef __opencl_c_atomic_scope_all_devices
353 #error "Incorrect feature macro __opencl_c_atomic_scope_all_devices define"
354 #endif
355 #ifdef __opencl_c_device_enqueue
356 #error "Incorrect feature macro __opencl_c_device_enqueue define"
357 #endif
358 #ifdef __opencl_c_read_write_images
359 #error "Incorrect feature macro __opencl_c_read_write_images define"
360 #endif
361 #ifdef __opencl_c_program_scope_global_variables
362 #error "Incorrect feature macro __opencl_c_program_scope_global_variables define"
363 #endif
364 #ifdef __opencl_c_images
365 #error "Incorrect feature macro __opencl_c_images define"
366 #endif
367 #ifdef __opencl_c_3d_image_writes
368 #error "Incorrect feature macro __opencl_c_3d_image_writes define"
369 #endif
370 #ifdef __opencl_c_fp64
371 #error "Incorrect feature macro __opencl_c_fp64 define"
372 #endif
373 #ifdef __opencl_c_subgroups
374 #error "Incorrect feature macro __opencl_c_subgroups define"
375 #endif
377 #endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
379 #endif // defined(__SPIR__)