Skip to content

Commit e123cd6

Browse files
committed
[OpenCL] Refactor of targets OpenCL option settings
Currently, there is some refactoring needed in existing interface of OpenCL option settings to support OpenCL C 3.0. The problem is that OpenCL extensions and features are not only determined by the target platform but also by the OpenCL version. Also, there are core extensions/features which are supported unconditionally in specific OpenCL C version. In fact, these rules are not being followed for all targets. For example, there are some targets (as nvptx and r600) which don't support OpenCL C 2.0 core features (nvptx.languageOptsOpenCL.cl, r600.languageOptsOpenCL.cl). After the change there will be explicit differentiation between optional core and core OpenCL features which allows giving diagnostics if target doesn't support any of necessary core features for specific OpenCL version. This patch also eliminates `OpenCLOptions` instance duplication from `TargetOptions`. `OpenCLOptions` instance should take place in `Sema` as it's going to be modified during parsing. Removing this duplication will also allow to generally simplify `OpenCLOptions` class for parsing purposes. Reviewed By: Anastasia Differential Revision: https://reviews.llvm.org/D92277
1 parent 17c3538 commit e123cd6

File tree

18 files changed

+380
-238
lines changed

18 files changed

+380
-238
lines changed

clang/include/clang/Basic/OpenCLExtensions.def

Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,25 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
// Macro OPENCLEXT or OPENCLEXT_INTERNAL can be defined to enumerate the
13+
// Macro OPENCLEXTNAME or OPENCL_GENERIC_EXTENSION can be defined to enumerate all
1414
// OpenCL extensions listed in this file.
1515
//
16-
// If the extensions are to be enumerated without the supported OpenCL version,
17-
// define OPENCLEXT(ext) where ext is the name of the extension.
18-
//
19-
// If the extensions are to be enumerated with supported OpenCL version,
20-
// define OPENCLEXT_INTERNAL(ext, avail, core) where
16+
// If extensions are to be enumerated with information about whether
17+
// an extension is core or optional core and minimum OpenCL version
18+
// when an extension becomes available,
19+
// define OPENCL_GENERIC_EXTENSION(ext, avail, core, opt) where
2120
// ext - name of the extension or optional core feature.
2221
// avail - minimum OpenCL version supporting it.
23-
// core - minimum OpenCL version when the extension becomes optional core
24-
// feature or core feature. ~0U indicates not a core feature or an
25-
// optional core feature.
22+
// core - OpenCL versions mask when the extension becomes core feature.
23+
// 0U indicates not a core feature.
24+
// opt - OpenCL versions mask when the extension becomes optional core
25+
// feature. 0U indicates not a optional core feature.
26+
//
27+
// If extensions are to be enumerated without any information,
28+
// define OPENCLEXTNAME(ext) where ext is the name of the extension.
29+
//
30+
// Difference between optional core feature and core feature is that the
31+
// later is unconditionally supported in specific OpenCL version.
2632
//
2733
// As per The OpenCL Extension Specification, Section 1.2, in this file, an
2834
// extension is defined if and only it either:
@@ -32,63 +38,72 @@
3238
// For such an extension, a preprocessor #define that matches the extension
3339
// name must be created and a #pragma is required if and only if the
3440
// compilation flow is impacted, e.g. due to a difference of syntax or
35-
// semantics in the language compared to the core standard.
41+
// semantics in the language compared to the core standard. #pragma directive
42+
// has no effect for optional core and core features.
3643

37-
#ifndef OPENCLEXT_INTERNAL
38-
#ifndef OPENCLEXT
39-
#pragma error "macro OPENCLEXT or OPENCLEXT_INTERNAL is required"
44+
#ifndef OPENCL_GENERIC_EXTENSION
45+
#ifndef OPENCLEXTNAME
46+
#pragma error "macro OPENCLEXTNAME or OPENCL_GENERIC_EXTENSION is required"
4047
#else
41-
#define OPENCLEXT_INTERNAL(ext, ...) OPENCLEXT(ext)
42-
#endif // OPENCLEXT
43-
#endif // OPENCLEXT_INTERNAL
48+
#define OPENCL_GENERIC_EXTENSION(ext, ...) OPENCLEXTNAME(ext)
49+
#endif // OPENCLEXTNAME
50+
#endif // OPENCL_GENERIC_EXTENSION
51+
52+
// Declaration helpers
53+
#define OPENCL_EXTENSION(ext, avail) OPENCL_GENERIC_EXTENSION(ext, avail, 0U, 0U)
54+
#define OPENCL_COREFEATURE(ext, avail, core) OPENCL_GENERIC_EXTENSION(ext, avail, core, 0U)
55+
#define OPENCL_OPTIONALCOREFEATURE(ext, avail, opt) OPENCL_GENERIC_EXTENSION(ext, avail, 0U, opt)
4456

4557
// OpenCL 1.0.
46-
OPENCLEXT_INTERNAL(cl_khr_3d_image_writes, 100, 200)
47-
OPENCLEXT_INTERNAL(cl_khr_byte_addressable_store, 100, 110)
48-
OPENCLEXT_INTERNAL(cl_khr_fp16, 100, ~0U)
49-
OPENCLEXT_INTERNAL(cl_khr_fp64, 100, 120)
50-
OPENCLEXT_INTERNAL(cl_khr_global_int32_base_atomics, 100, 110)
51-
OPENCLEXT_INTERNAL(cl_khr_global_int32_extended_atomics, 100, 110)
52-
OPENCLEXT_INTERNAL(cl_khr_local_int32_base_atomics, 100, 110)
53-
OPENCLEXT_INTERNAL(cl_khr_local_int32_extended_atomics, 100, 110)
54-
OPENCLEXT_INTERNAL(cl_khr_int64_base_atomics, 100, ~0U)
55-
OPENCLEXT_INTERNAL(cl_khr_int64_extended_atomics, 100, ~0U)
58+
OPENCL_COREFEATURE(cl_khr_byte_addressable_store, 100, OCL_C_11P)
59+
OPENCL_COREFEATURE(cl_khr_global_int32_base_atomics, 100, OCL_C_11P)
60+
OPENCL_COREFEATURE(cl_khr_global_int32_extended_atomics, 100, OCL_C_11P)
61+
OPENCL_COREFEATURE(cl_khr_local_int32_base_atomics, 100, OCL_C_11P)
62+
OPENCL_COREFEATURE(cl_khr_local_int32_extended_atomics, 100, OCL_C_11P)
63+
OPENCL_OPTIONALCOREFEATURE(cl_khr_fp64, 100, OCL_C_12P)
64+
OPENCL_EXTENSION(cl_khr_fp16, 100)
65+
OPENCL_EXTENSION(cl_khr_int64_base_atomics, 100)
66+
OPENCL_EXTENSION(cl_khr_int64_extended_atomics, 100)
67+
OPENCL_GENERIC_EXTENSION(cl_khr_3d_image_writes, 100, OCL_C_20, OCL_C_30)
5668

5769
// EMBEDDED_PROFILE
58-
OPENCLEXT_INTERNAL(cles_khr_int64, 110, ~0U)
70+
OPENCL_EXTENSION(cles_khr_int64, 110)
5971

6072
// OpenCL 1.2.
61-
OPENCLEXT_INTERNAL(cl_khr_depth_images, 120, ~0U)
62-
OPENCLEXT_INTERNAL(cl_khr_gl_msaa_sharing, 120, ~0U)
73+
OPENCL_EXTENSION(cl_khr_depth_images, 120)
74+
OPENCL_EXTENSION(cl_khr_gl_msaa_sharing, 120)
6375

6476
// OpenCL 2.0.
65-
OPENCLEXT_INTERNAL(cl_khr_mipmap_image, 200, ~0U)
66-
OPENCLEXT_INTERNAL(cl_khr_mipmap_image_writes, 200, ~0U)
67-
OPENCLEXT_INTERNAL(cl_khr_srgb_image_writes, 200, ~0U)
68-
OPENCLEXT_INTERNAL(cl_khr_subgroups, 200, ~0U)
77+
OPENCL_EXTENSION(cl_khr_mipmap_image, 200)
78+
OPENCL_EXTENSION(cl_khr_mipmap_image_writes, 200)
79+
OPENCL_EXTENSION(cl_khr_srgb_image_writes, 200)
80+
OPENCL_EXTENSION(cl_khr_subgroups, 200)
6981

7082
// Clang Extensions.
71-
OPENCLEXT_INTERNAL(cl_clang_storage_class_specifiers, 100, ~0U)
72-
OPENCLEXT_INTERNAL(__cl_clang_function_pointers, 100, ~0U)
73-
OPENCLEXT_INTERNAL(__cl_clang_variadic_functions, 100, ~0U)
83+
OPENCL_EXTENSION(cl_clang_storage_class_specifiers, 100)
84+
OPENCL_EXTENSION(__cl_clang_function_pointers, 100)
85+
OPENCL_EXTENSION(__cl_clang_variadic_functions, 100)
7486

7587
// AMD OpenCL extensions
76-
OPENCLEXT_INTERNAL(cl_amd_media_ops, 100, ~0U)
77-
OPENCLEXT_INTERNAL(cl_amd_media_ops2, 100, ~0U)
88+
OPENCL_EXTENSION(cl_amd_media_ops, 100)
89+
OPENCL_EXTENSION(cl_amd_media_ops2, 100)
7890

7991
// ARM OpenCL extensions
80-
OPENCLEXT_INTERNAL(cl_arm_integer_dot_product_int8, 120, ~0U)
81-
OPENCLEXT_INTERNAL(cl_arm_integer_dot_product_accumulate_int8, 120, ~0U)
82-
OPENCLEXT_INTERNAL(cl_arm_integer_dot_product_accumulate_int16, 120, ~0U)
83-
OPENCLEXT_INTERNAL(cl_arm_integer_dot_product_accumulate_saturate_int8, 120, ~0U)
92+
OPENCL_EXTENSION(cl_arm_integer_dot_product_int8, 120)
93+
OPENCL_EXTENSION(cl_arm_integer_dot_product_accumulate_int8, 120)
94+
OPENCL_EXTENSION(cl_arm_integer_dot_product_accumulate_int16, 120)
95+
OPENCL_EXTENSION(cl_arm_integer_dot_product_accumulate_saturate_int8, 120)
8496

8597
// Intel OpenCL extensions
86-
OPENCLEXT_INTERNAL(cl_intel_subgroups, 120, ~0U)
87-
OPENCLEXT_INTERNAL(cl_intel_subgroups_short, 120, ~0U)
88-
OPENCLEXT_INTERNAL(cl_intel_device_side_avc_motion_estimation, 120, ~0U)
98+
OPENCL_EXTENSION(cl_intel_subgroups, 120)
99+
OPENCL_EXTENSION(cl_intel_subgroups_short, 120)
100+
OPENCL_EXTENSION(cl_intel_device_side_avc_motion_estimation, 120)
101+
89102

90-
#undef OPENCLEXT_INTERNAL
103+
#undef OPENCL_OPTIONALCOREFEATURE
104+
#undef OPENCL_COREFEATURE
105+
#undef OPENCL_GENERIC_EXTENSION
91106

92-
#ifdef OPENCLEXT
93-
#undef OPENCLEXT
107+
#ifdef OPENCLEXTNAME
108+
#undef OPENCLEXTNAME
94109
#endif

0 commit comments

Comments
 (0)