Skip to content

Commit 950f8a8

Browse files
authored
[OpenCL] Re-enable corresponding __opencl_* feature macros for OpenCL 2.0 core extensions (#171529)
Commit 423bdb2 removed OpenCL 2.0 __opencl_* feature macros (https://github.com/llvm/llvm-project/blob/fd73bdd662da/clang/lib/Headers/opencl-c-base.h#L60-L72) from header and thus they are disabled by default for non-SPIR/SPIRV targets now. This PR re-enables them for OpenCL 2.0, and shall restore previous behavior that these features macros were always defined for OpenCL 2.0 core extensions. After this PR, targets that support OpenCL 2.0 must enable these feature macros via setSupportedOpenCLOpts API.
1 parent 680c20d commit 950f8a8

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

clang/include/clang/Basic/OpenCLExtensions.def

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ OPENCL_EXTENSION(cl_khr_subgroup_rotate, false, 200)
9494
OPENCL_EXTENSION(cl_khr_subgroup_shuffle_relative, false, 200)
9595
OPENCL_EXTENSION(cl_khr_subgroup_shuffle, false, 200)
9696
OPENCL_EXTENSION(cl_khr_subgroups, true, 200)
97-
OPENCL_OPTIONALCOREFEATURE(__opencl_c_atomic_order_acq_rel, false, 200, OCL_C_20)
98-
OPENCL_OPTIONALCOREFEATURE(__opencl_c_atomic_order_seq_cst, false, 200, OCL_C_20)
99-
OPENCL_OPTIONALCOREFEATURE(__opencl_c_atomic_scope_all_devices, false, 200, OCL_C_20)
100-
OPENCL_OPTIONALCOREFEATURE(__opencl_c_atomic_scope_device, false, 200, OCL_C_20)
101-
OPENCL_OPTIONALCOREFEATURE(__opencl_c_device_enqueue, false, 200, OCL_C_20)
97+
OPENCL_GENERIC_EXTENSION(__opencl_c_atomic_order_acq_rel, false, 200, OCL_C_20, OCL_C_30)
98+
OPENCL_GENERIC_EXTENSION(__opencl_c_atomic_order_seq_cst, false, 200, OCL_C_20, OCL_C_30)
99+
OPENCL_GENERIC_EXTENSION(__opencl_c_atomic_scope_all_devices, false, 200, OCL_C_20, OCL_C_30)
100+
OPENCL_GENERIC_EXTENSION(__opencl_c_atomic_scope_device, false, 200, OCL_C_20, OCL_C_30)
101+
OPENCL_GENERIC_EXTENSION(__opencl_c_device_enqueue, false, 200, OCL_C_20, OCL_C_30)
102102
OPENCL_OPTIONALCOREFEATURE(__opencl_c_ext_fp16_global_atomic_add, false, 200, OCL_C_20)
103103
OPENCL_OPTIONALCOREFEATURE(__opencl_c_ext_fp16_global_atomic_load_store, false, 200, OCL_C_20)
104104
OPENCL_OPTIONALCOREFEATURE(__opencl_c_ext_fp16_global_atomic_min_max, false, 200, OCL_C_20)
@@ -116,17 +116,17 @@ OPENCL_OPTIONALCOREFEATURE(__opencl_c_ext_fp64_local_atomic_min_max, false, 200,
116116
OPENCL_OPTIONALCOREFEATURE(__opencl_c_ext_image_raw10_raw12, false, 200, OCL_C_20)
117117
OPENCL_OPTIONALCOREFEATURE(__opencl_c_ext_image_unorm_int_2_101010, false, 200, OCL_C_20)
118118
OPENCL_OPTIONALCOREFEATURE(__opencl_c_ext_image_unsigned_10x6_12x4_14x2, false, 200, OCL_C_20)
119-
OPENCL_OPTIONALCOREFEATURE(__opencl_c_generic_address_space, false, 200, OCL_C_20)
120-
OPENCL_OPTIONALCOREFEATURE(__opencl_c_images, false, 200, OCL_C_20)
119+
OPENCL_GENERIC_EXTENSION(__opencl_c_generic_address_space, false, 200, OCL_C_20, OCL_C_30)
120+
OPENCL_GENERIC_EXTENSION(__opencl_c_images, false, 200, OCL_C_20, OCL_C_30)
121121
OPENCL_OPTIONALCOREFEATURE(__opencl_c_integer_dot_product_input_4x8bit, false, 200, OCL_C_20)
122122
OPENCL_OPTIONALCOREFEATURE(__opencl_c_integer_dot_product_input_4x8bit_packed, false, 200, OCL_C_20)
123123
OPENCL_OPTIONALCOREFEATURE(__opencl_c_kernel_clock_scope_device, false, 200, OCL_C_20)
124124
OPENCL_OPTIONALCOREFEATURE(__opencl_c_kernel_clock_scope_sub_group, false, 200, OCL_C_20)
125125
OPENCL_OPTIONALCOREFEATURE(__opencl_c_kernel_clock_scope_work_group, false, 200, OCL_C_20)
126-
OPENCL_OPTIONALCOREFEATURE(__opencl_c_pipes, false, 200, OCL_C_20)
127-
OPENCL_OPTIONALCOREFEATURE(__opencl_c_program_scope_global_variables, false, 200, OCL_C_20)
128-
OPENCL_OPTIONALCOREFEATURE(__opencl_c_read_write_images, false, 200, OCL_C_20)
129-
OPENCL_OPTIONALCOREFEATURE(__opencl_c_work_group_collective_functions, false, 200, OCL_C_20)
126+
OPENCL_GENERIC_EXTENSION(__opencl_c_pipes, false, 200, OCL_C_20, OCL_C_30)
127+
OPENCL_GENERIC_EXTENSION(__opencl_c_program_scope_global_variables, false, 200, OCL_C_20, OCL_C_30)
128+
OPENCL_GENERIC_EXTENSION(__opencl_c_read_write_images, false, 200, OCL_C_20, OCL_C_30)
129+
OPENCL_GENERIC_EXTENSION(__opencl_c_work_group_collective_functions, false, 200, OCL_C_20, OCL_C_30)
130130

131131
// Clang Extensions.
132132
OPENCL_EXTENSION(cl_clang_storage_class_specifiers, true, 100)

clang/lib/Basic/Targets/AMDGPU.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,16 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
334334
Opts["__opencl_c_read_write_images"] = true;
335335
Opts["cl_khr_3d_image_writes"] = true;
336336
Opts["__opencl_c_program_scope_global_variables"] = true;
337+
Opts["__opencl_c_atomic_order_acq_rel"] = true;
337338
Opts["__opencl_c_atomic_order_seq_cst"] = true;
339+
Opts["__opencl_c_atomic_scope_device"] = true;
338340
Opts["__opencl_c_atomic_scope_all_devices"] = true;
341+
Opts["__opencl_c_work_group_collective_functions"] = true;
339342

340343
if (hasFlatSupport()) {
341344
Opts["__opencl_c_generic_address_space"] = true;
342345
Opts["__opencl_c_device_enqueue"] = true;
346+
Opts["__opencl_c_pipes"] = true;
343347
}
344348
}
345349
}

clang/test/Misc/amdgcn.languageOptsOpenCL.cl

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple amdgcn-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
77
// RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple amdgcn-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
88
// RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple amdgcn-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
9-
// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple amdgcn-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
9+
// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple amdgcn-unknown-amdhsa -Wpedantic-core-features -DTEST_CORE_FEATURES -DFLAT_SUPPORT
1010

1111
// RUN: %clang_cc1 -x cl -cl-std=CL3.0 %s -verify -triple amdgcn-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
1212
// RUN: %clang_cc1 -x cl -cl-std=CL3.0 %s -verify -triple amdgcn-unknown-unknown -target-cpu gfx700 -Wpedantic-core-features -DTEST_CORE_FEATURES -DFLAT_SUPPORT
@@ -161,36 +161,56 @@
161161
#endif
162162
#pragma OPENCL EXTENSION cl_amd_media_ops2: enable
163163

164-
#if (__OPENCL_C_VERSION__ >= 300)
164+
#if (__OPENCL_C_VERSION__ >= 200)
165165
#ifndef __opencl_c_program_scope_global_variables
166166
#error "Missing __opencl_c_program_scope_global_variables define"
167167
#endif
168168

169169
#ifndef __opencl_c_read_write_images
170170
#error "Missing __opencl_c_read_write_images define"
171171
#endif
172+
173+
#ifndef __opencl_c_atomic_order_acq_rel
174+
#error "Missing __opencl_c_atomic_order_acq_rel define"
175+
#endif
176+
177+
#ifndef __opencl_c_atomic_order_seq_cst
178+
#error "Missing __opencl_c_atomic_order_seq_cst define"
179+
#endif
180+
181+
#ifndef __opencl_c_atomic_scope_device
182+
#error "Missing __opencl_c_atomic_scope_device define"
183+
#endif
184+
185+
#ifndef __opencl_c_atomic_scope_all_devices
186+
#error "Missing __opencl_c_atomic_scope_all_devices define"
187+
#endif
188+
189+
#ifndef __opencl_c_work_group_collective_functions
190+
#error "Missing __opencl_c_work_group_collective_functions define"
191+
#endif
172192
#endif
173193

174-
#if (__OPENCL_C_VERSION__ >= 300)
194+
#if (__OPENCL_C_VERSION__ >= 200)
175195
#ifdef FLAT_SUPPORT
176196
#ifndef __opencl_c_generic_address_space
177197
#error "Missing __opencl_c_generic_address_space define"
178198
#endif
179-
#else
180-
#ifdef __opencl_c_generic_address_space
181-
#error "Incorrect __opencl_c_generic_address_space define"
182-
#endif
183-
#endif
184-
#endif
185-
186-
#if (__OPENCL_C_VERSION__ >= 300)
187-
#ifdef FLAT_SUPPORT
188199
#ifndef __opencl_c_device_enqueue
189200
#error "Missing __opencl_c_device_enqueue define"
190201
#endif
202+
#ifndef __opencl_c_pipes
203+
#error "Missing __opencl_c_pipes define"
204+
#endif
191205
#else
206+
#ifdef __opencl_c_generic_address_space
207+
#error "Incorrect __opencl_c_generic_address_space define"
208+
#endif
192209
#ifdef __opencl_c_device_enqueue
193210
#error "Incorrect __opencl_c_device_enqueue define"
194211
#endif
212+
#ifdef __opencl_c_pipes
213+
#error "Incorrect __opencl_c_pipes define"
214+
#endif
195215
#endif
196216
#endif

0 commit comments

Comments
 (0)