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/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h --- a/clang/lib/Headers/opencl-c.h +++ b/clang/lib/Headers/opencl-c.h @@ -17157,6 +17157,20 @@ // Disable any extensions we may have enabled previously. #pragma OPENCL EXTENSION all : disable +#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200) +#undef __opencl_c_pipes +#undef __opencl_c_generic_address_space +#undef __opencl_c_work_group_collective_functions +#undef __opencl_c_atomic_order_acq_rel +#undef __opencl_c_atomic_order_seq_cst +#undef __opencl_c_atomic_scope_device +#undef __opencl_c_atomic_scope_all_devices +#undef __opencl_c_device_enqueue +#undef __opencl_c_read_write_images +#undef __opencl_c_program_scope_global_variables +#undef __opencl_c_images +#endif + #undef __cnfn #undef __ovld #endif //_OPENCL_H_ 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,26 @@ +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -cl-std=CL1.1 +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -cl-std=CL1.2 +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -cl-std=CL2.0 +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -cl-std=CL2.0 -finclude-default-header +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -cl-std=CL2.0 -cl-ext=+__opencl_c_pipes + +// All features are unsupported +// RUN: %clang_cc1 %s -triple r600-unknown-unknown -verify -cl-std=CL3.0 +// RUN: %clang_cc1 %s -triple r600-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_pipes -DPIPES + +// expected-no-diagnostics + +// FULL OpenCL profile +#ifndef __opencl_c_int64 +#pragma error "Macro __opencl_c_int64 should be defined" +#endif + +#ifdef PIPES + #ifndef __opencl_c_pipes + #pragma error "Macro __opencl_c_pipes should be defined" + #endif +#else + #ifdef __opencl_c_pipes + #pragma error "Macro __opencl_c_pipes should not be defined" + #endif +#endif