diff --git a/clang/include/clang/Basic/OpenCLExtensions.def b/clang/include/clang/Basic/OpenCLExtensions.def --- a/clang/include/clang/Basic/OpenCLExtensions.def +++ b/clang/include/clang/Basic/OpenCLExtensions.def @@ -64,7 +64,7 @@ OPENCL_EXTENSION(cl_khr_fp16, 100) OPENCL_EXTENSION(cl_khr_int64_base_atomics, 100) OPENCL_EXTENSION(cl_khr_int64_extended_atomics, 100) -OPENCL_GENERIC_EXTENSION(cl_khr_3d_image_writes, 100, OCL_C_20, OCL_C_30) +OPENCL_COREFEATURE(cl_khr_3d_image_writes, 100, OCL_C_20) // EMBEDDED_PROFILE OPENCL_EXTENSION(cles_khr_int64, 110) @@ -99,6 +99,18 @@ OPENCL_EXTENSION(cl_intel_subgroups_short, 120) OPENCL_EXTENSION(cl_intel_device_side_avc_motion_estimation, 120) +// OpenCL C 3.0 features (6.2.1. Features) +OPENCL_OPTIONALCOREFEATURE(__opencl_c_pipes, 300, OCL_C_30) +OPENCL_OPTIONALCOREFEATURE(__opencl_c_generic_address_space, 300, OCL_C_30) +OPENCL_OPTIONALCOREFEATURE(__opencl_c_atomic_order_acq_rel, 300, OCL_C_30) +OPENCL_OPTIONALCOREFEATURE(__opencl_c_atomic_order_seq_cst, 300, OCL_C_30) +OPENCL_OPTIONALCOREFEATURE(__opencl_c_subgroups, 300, OCL_C_30) +OPENCL_OPTIONALCOREFEATURE(__opencl_c_3d_image_writes, 300, OCL_C_30) +OPENCL_OPTIONALCOREFEATURE(__opencl_c_device_enqueue, 300, OCL_C_30) +OPENCL_OPTIONALCOREFEATURE(__opencl_c_read_write_images, 300, OCL_C_30) +OPENCL_OPTIONALCOREFEATURE(__opencl_c_program_scope_global_variables, 300, OCL_C_30) +OPENCL_OPTIONALCOREFEATURE(__opencl_c_fp64, 300, OCL_C_30) +OPENCL_OPTIONALCOREFEATURE(__opencl_c_images, 300, OCL_C_30) #undef OPENCL_OPTIONALCOREFEATURE #undef OPENCL_COREFEATURE diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -720,7 +720,9 @@ /// and language version void TargetInfo::getOpenCLFeatureDefines(const LangOptions &Opts, MacroBuilder &Builder) const { - + // FIXME: OpenCL options which affect language semantics/syntax + // should be moved into LangOptions, thus macro definitions of + // such options is better to be done in clang::InitializePreprocessor auto defineOpenCLExtMacro = [&](llvm::StringRef Name, unsigned AvailVer, unsigned CoreVersions, unsigned OptionalVersions) { @@ -737,7 +739,6 @@ defineOpenCLExtMacro(#Ext, Avail, Core, Opt); #include "clang/Basic/OpenCLExtensions.def" - // FIXME: OpenCL options which affect language semantics/syntax - // should be moved into LangOptions, thus macro definitions of - // such options is better to be done in clang::InitializePreprocessor + // Assume compiling for FULL profile + Builder.defineMacro("__opencl_c_int64"); } diff --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h --- a/clang/lib/Headers/opencl-c-base.h +++ b/clang/lib/Headers/opencl-c-base.h @@ -24,6 +24,21 @@ #endif // defined(__SPIR__) #endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200) +// Define feature macros for OpenCL C 2.0 +#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200) +#define __opencl_c_pipes 1 +#define __opencl_c_generic_address_space 1 +#define __opencl_c_work_group_collective_functions 1 +#define __opencl_c_atomic_order_acq_rel 1 +#define __opencl_c_atomic_order_seq_cst 1 +#define __opencl_c_atomic_scope_device 1 +#define __opencl_c_atomic_scope_all_devices 1 +#define __opencl_c_device_enqueue 1 +#define __opencl_c_read_write_images 1 +#define __opencl_c_program_scope_global_variables 1 +#define __opencl_c_images 1 +#endif + // built-in scalar data types: /** diff --git a/clang/test/SemaOpenCL/features.cl b/clang/test/SemaOpenCL/features.cl new file mode 100644 --- /dev/null +++ b/clang/test/SemaOpenCL/features.cl @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -triple spir-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL2.0 -cl-ext=-all \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=FEATURES +// RUN: %clang_cc1 -triple spir-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL2.0 -cl-ext=+all \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=FEATURES +// RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=CL3.0 -cl-ext=-all \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=NO-FEATURES +// RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=CL3.0 -cl-ext=+all \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=FEATURES +// RUN: %clang_cc1 -triple r600-unknown-unknown %s -E -dM -o - -x cl -cl-std=CL3.0 \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=NO-FEATURES + +// FULL OpenCL profile +#ifndef __opencl_c_int64 +#error "Macro __opencl_c_int64 should be defined" +#endif + +// Note that this test features which are both language related +// and defined in header for OpenCL C 2.0 + +// FEATURES: #define __opencl_c_atomic_order_acq_rel 1 +// FEATURES: #define __opencl_c_atomic_order_seq_cst 1 +// FEATURES: #define __opencl_c_device_enqueue 1 +// FEATURES: #define __opencl_c_generic_address_space 1 +// FEATURES: #define __opencl_c_images 1 +// FEATURES: #define __opencl_c_pipes 1 +// FEATURES: #define __opencl_c_program_scope_global_variables 1 +// FEATURES: #define __opencl_c_read_write_images 1 + +// NO-FEATURES-NOT: __opencl_c_atomic_order_acq_rel +// NO-FEATURES-NOT: __opencl_c_atomic_order_seq_cst +// NO-FEATURES-NOT: __opencl_c_device_enqueue +// NO-FEATURES-NOT: __opencl_c_generic_address_space +// NO-FEATURES-NOT: __opencl_c_images +// NO-FEATURES-NOT: __opencl_c_pipes +// NO-FEATURES-NOT: __opencl_c_program_scope_global_variables +// NO-FEATURES-NOT: __opencl_c_read_write_images