[clang][lex] NFCI: Use DirectoryEntryRef in ModuleMap::inferFrameworkModule()
[llvm-project.git] / clang / test / Headers / opencl-c-header.cl
blob8242798106ac308522a58902be94cac6a8d4cf56
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
191 #else
193 #ifdef cl_khr_subgroup_extended_types
194 #error "Incorrect cl_khr_subgroup_extended_types define"
195 #endif
196 #ifdef cl_khr_subgroup_non_uniform_vote
197 #error "Incorrect cl_khr_subgroup_non_uniform_vote define"
198 #endif
199 #ifdef cl_khr_subgroup_ballot
200 #error "Incorrect cl_khr_subgroup_ballot define"
201 #endif
202 #ifdef cl_khr_subgroup_non_uniform_arithmetic
203 #error "Incorrect cl_khr_subgroup_non_uniform_arithmetic define"
204 #endif
205 #ifdef cl_khr_subgroup_shuffle
206 #error "Incorrect cl_khr_subgroup_shuffle define"
207 #endif
208 #ifdef cl_khr_subgroup_shuffle_relative
209 #error "Incorrect cl_khr_subgroup_shuffle_relative define"
210 #endif
211 #ifdef cl_khr_subgroup_clustered_reduce
212 #error "Incorrect cl_khr_subgroup_clustered_reduce define"
213 #endif
214 #ifdef cl_khr_subgroup_rotate
215 #error "Incorrect cl_khr_subgroup_rotate define"
216 #endif
217 #ifdef cl_khr_extended_bit_ops
218 #error "Incorrect cl_khr_extended_bit_ops define"
219 #endif
220 #ifdef cl_khr_integer_dot_product
221 #error "Incorrect cl_khr_integer_dot_product define"
222 #endif
223 #ifdef __opencl_c_integer_dot_product_input_4x8bit
224 #error "Incorrect __opencl_c_integer_dot_product_input_4x8bit define"
225 #endif
226 #ifdef __opencl_c_integer_dot_product_input_4x8bit_packed
227 #error "Incorrect __opencl_c_integer_dot_product_input_4x8bit_packed define"
228 #endif
229 #ifdef cl_ext_float_atomics
230 #error "Incorrect cl_ext_float_atomics define"
231 #endif
232 #ifdef __opencl_c_ext_fp16_global_atomic_load_store
233 #error "Incorrectly __opencl_c_ext_fp16_global_atomic_load_store defined"
234 #endif
235 #ifdef __opencl_c_ext_fp16_local_atomic_load_store
236 #error "Incorrectly __opencl_c_ext_fp16_local_atomic_load_store defined"
237 #endif
238 #ifdef __opencl_c_ext_fp16_global_atomic_add
239 #error "Incorrectly __opencl_c_ext_fp16_global_atomic_add defined"
240 #endif
241 #ifdef __opencl_c_ext_fp32_global_atomic_add
242 #error "Incorrectly __opencl_c_ext_fp32_global_atomic_add defined"
243 #endif
244 #ifdef __opencl_c_ext_fp64_global_atomic_add
245 #error "Incorrectly __opencl_c_ext_fp64_global_atomic_add defined"
246 #endif
247 #ifdef __opencl_c_ext_fp16_local_atomic_add
248 #error "Incorrectly __opencl_c_ext_fp16_local_atomic_add defined"
249 #endif
250 #ifdef __opencl_c_ext_fp32_local_atomic_add
251 #error "Incorrectly __opencl_c_ext_fp32_local_atomic_add defined"
252 #endif
253 #ifdef __opencl_c_ext_fp64_local_atomic_add
254 #error "Incorrectly __opencl_c_ext_fp64_local_atomic_add defined"
255 #endif
256 #ifdef __opencl_c_ext_fp16_global_atomic_min_max
257 #error "Incorrectly __opencl_c_ext_fp16_global_atomic_min_max defined"
258 #endif
259 #ifdef __opencl_c_ext_fp32_global_atomic_min_max
260 #error "Incorrectly __opencl_c_ext_fp32_global_atomic_min_max defined"
261 #endif
262 #ifdef __opencl_c_ext_fp64_global_atomic_min_max
263 #error "Incorrectly __opencl_c_ext_fp64_global_atomic_min_max defined"
264 #endif
265 #ifdef __opencl_c_ext_fp16_local_atomic_min_max
266 #error "Incorrectly __opencl_c_ext_fp16_local_atomic_min_max defined"
267 #endif
268 #ifdef __opencl_c_ext_fp32_local_atomic_min_max
269 #error "Incorrectly __opencl_c_ext_fp32_local_atomic_min_max defined"
270 #endif
271 #ifdef __opencl_c_ext_fp64_local_atomic_min_max
272 #error "Incorrectly __opencl_c_ext_fp64_local_atomic_min_max defined"
273 #endif
275 #endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
277 // OpenCL C features.
278 #if (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
280 #if __opencl_c_atomic_scope_all_devices != 1
281 #error "Incorrectly defined feature macro __opencl_c_atomic_scope_all_devices"
282 #endif
284 #elif (__OPENCL_CPP_VERSION__ == 100 || __OPENCL_C_VERSION__ == 200)
286 #ifndef __opencl_c_pipes
287 #error "Feature macro __opencl_c_pipes should be defined"
288 #endif
289 #ifndef __opencl_c_generic_address_space
290 #error "Feature macro __opencl_c_generic_address_space should be defined"
291 #endif
292 #ifndef __opencl_c_work_group_collective_functions
293 #error "Feature macro __opencl_c_work_group_collective_functions should be defined"
294 #endif
295 #ifndef __opencl_c_atomic_order_acq_rel
296 #error "Feature macro __opencl_c_atomic_order_acq_rel should be defined"
297 #endif
298 #ifndef __opencl_c_atomic_order_seq_cst
299 #error "Feature macro __opencl_c_atomic_order_seq_cst should be defined"
300 #endif
301 #ifndef __opencl_c_atomic_scope_device
302 #error "Feature macro __opencl_c_atomic_scope_device should be defined"
303 #endif
304 #ifndef __opencl_c_atomic_scope_all_devices
305 #error "Feature macro __opencl_c_atomic_scope_all_devices should be defined"
306 #endif
307 #ifndef __opencl_c_device_enqueue
308 #error "Feature macro __opencl_c_device_enqueue should be defined"
309 #endif
310 #ifndef __opencl_c_read_write_images
311 #error "Feature macro __opencl_c_read_write_images should be defined"
312 #endif
313 #ifndef __opencl_c_program_scope_global_variables
314 #error "Feature macro __opencl_c_program_scope_global_variables should be defined"
315 #endif
316 #ifndef __opencl_c_images
317 #error "Feature macro __opencl_c_images should be defined"
318 #endif
320 #elif (__OPENCL_C_VERSION__ < 200)
322 #ifdef __opencl_c_pipes
323 #error "Incorrect feature macro __opencl_c_pipes define"
324 #endif
325 #ifdef __opencl_c_generic_address_space
326 #error "Incorrect feature macro __opencl_c_generic_address_space define"
327 #endif
328 #ifdef __opencl_c_work_group_collective_functions
329 #error "Incorrect feature macro __opencl_c_work_group_collective_functions define"
330 #endif
331 #ifdef __opencl_c_atomic_order_acq_rel
332 #error "Incorrect feature macro __opencl_c_atomic_order_acq_rel define"
333 #endif
334 #ifdef __opencl_c_atomic_order_seq_cst
335 #error "Incorrect feature macro __opencl_c_atomic_order_seq_cst define"
336 #endif
337 #ifdef __opencl_c_atomic_scope_device
338 #error "Incorrect feature macro __opencl_c_atomic_scope_device define"
339 #endif
340 #ifdef __opencl_c_atomic_scope_all_devices
341 #error "Incorrect feature macro __opencl_c_atomic_scope_all_devices define"
342 #endif
343 #ifdef __opencl_c_device_enqueue
344 #error "Incorrect feature macro __opencl_c_device_enqueue define"
345 #endif
346 #ifdef __opencl_c_read_write_images
347 #error "Incorrect feature macro __opencl_c_read_write_images define"
348 #endif
349 #ifdef __opencl_c_program_scope_global_variables
350 #error "Incorrect feature macro __opencl_c_program_scope_global_variables define"
351 #endif
352 #ifdef __opencl_c_images
353 #error "Incorrect feature macro __opencl_c_images define"
354 #endif
355 #ifdef __opencl_c_3d_image_writes
356 #error "Incorrect feature macro __opencl_c_3d_image_writes define"
357 #endif
358 #ifdef __opencl_c_fp64
359 #error "Incorrect feature macro __opencl_c_fp64 define"
360 #endif
361 #ifdef __opencl_c_subgroups
362 #error "Incorrect feature macro __opencl_c_subgroups define"
363 #endif
365 #endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
367 #endif // defined(__SPIR__)