FMarno created this revision.
FMarno added a reviewer: Anastasia.
Herald added subscribers: Naghasan, ldrumm, yaxunl.
Herald added a project: All.
FMarno requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

A number of feature macros were being defined for OpenCL C 3.0 even though they 
are optional. I have removed these defines and updated the related tests. This 
should help users who are creating compilers for more limited environments.
This will also affect C++ for OpenCL 2021 since I believe its follows the same 
system of feature macros as OpenCL C 3.0.

This contribution is being made by Codeplay on behalf of Samsung.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137652

Files:
  clang/include/clang/Basic/OpenCLExtensions.def
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Headers/opencl-c-base.h
  clang/test/SemaOpenCL/extension-version.cl
  clang/test/SemaOpenCL/features.cl

Index: clang/test/SemaOpenCL/features.cl
===================================================================
--- clang/test/SemaOpenCL/features.cl
+++ clang/test/SemaOpenCL/features.cl
@@ -26,26 +26,28 @@
 // RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=clc++1.0 \
 // RUN:   | FileCheck -match-full-lines %s  --check-prefix=NO-FEATURES
 
-// Note that __opencl_c_int64 is always defined assuming
-// always compiling for FULL OpenCL profile
+// FEATURES-DAG: #define __opencl_c_3d_image_writes 1
+// FEATURES-DAG: #define __opencl_c_atomic_order_acq_rel 1
+// FEATURES-DAG: #define __opencl_c_atomic_order_seq_cst 1
+// FEATURES-DAG: #define __opencl_c_atomic_scope_device 1
+// FEATURES-DAG: #define __opencl_c_atomic_scope_all_devices 1
+// FEATURES-DAG: #define __opencl_c_device_enqueue 1
+// FEATURES-DAG: #define __opencl_c_fp64 1
+// FEATURES-DAG: #define __opencl_c_generic_address_space 1
+// FEATURES-DAG: #define __opencl_c_images 1
+// FEATURES-DAG: #define __opencl_c_int64 1
+// FEATURES-DAG: #define __opencl_c_pipes 1
+// FEATURES-DAG: #define __opencl_c_program_scope_global_variables 1
+// FEATURES-DAG: #define __opencl_c_read_write_images 1
+// FEATURES-DAG: #define __opencl_c_subgroups 1
+// FEATURES-DAG: #define __opencl_c_work_group_collective_functions 1
 
-// FEATURES: #define __opencl_c_3d_image_writes 1
-// 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_fp64 1
-// FEATURES: #define __opencl_c_generic_address_space 1
-// FEATURES: #define __opencl_c_images 1
-// FEATURES: #define __opencl_c_int64 1
-// FEATURES: #define __opencl_c_pipes 1
-// FEATURES: #define __opencl_c_program_scope_global_variables 1
-// FEATURES: #define __opencl_c_read_write_images 1
-// FEATURES: #define __opencl_c_subgroups 1
-
-// NO-FEATURES: #define __opencl_c_int64 1
+// NO-FEATURES-NOT: __opencl_c_int64
 // NO-FEATURES-NOT: __opencl_c_3d_image_writes
 // NO-FEATURES-NOT: __opencl_c_atomic_order_acq_rel
 // NO-FEATURES-NOT: __opencl_c_atomic_order_seq_cst
+// NO-FEATURES-NOT: __opencl_c_atomic_scope_device
+// NO-FEATURES-NOT: __opencl_c_atomic_scope_all_devices
 // NO-FEATURES-NOT: __opencl_c_device_enqueue
 // NO-FEATURES-NOT: __opencl_c_fp64
 // NO-FEATURES-NOT: __opencl_c_generic_address_space
@@ -54,3 +56,4 @@
 // NO-FEATURES-NOT: __opencl_c_program_scope_global_variables
 // NO-FEATURES-NOT: __opencl_c_read_write_images
 // NO-FEATURES-NOT: __opencl_c_subgroups
+// NO-FEATURES-NOT: __opencl_c_work_group_collective_functions
Index: clang/test/SemaOpenCL/extension-version.cl
===================================================================
--- clang/test/SemaOpenCL/extension-version.cl
+++ clang/test/SemaOpenCL/extension-version.cl
@@ -224,6 +224,10 @@
 //expected-warning@-1{{OpenCL extension '__opencl_c_atomic_order_acq_rel' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_atomic_order_seq_cst : disable
 //expected-warning@-1{{OpenCL extension '__opencl_c_atomic_order_seq_cst' unknown or does not require pragma - ignoring}}
+#pragma OPENCL EXTENSION __opencl_c_atomic_scope_device : disable
+//expected-warning@-1{{OpenCL extension '__opencl_c_atomic_scope_device' unknown or does not require pragma - ignoring}}
+#pragma OPENCL EXTENSION __opencl_c_atomic_scope_all_devices : disable
+//expected-warning@-1{{OpenCL extension '__opencl_c_atomic_scope_all_devices' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_device_enqueue : disable
 //expected-warning@-1{{OpenCL extension '__opencl_c_device_enqueue' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_fp64 : disable
@@ -240,6 +244,8 @@
 //expected-warning@-1{{OpenCL extension '__opencl_c_read_write_images' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_subgroups : disable
 //expected-warning@-1{{OpenCL extension '__opencl_c_subgroups' unknown or does not require pragma - ignoring}}
+#pragma OPENCL EXTENSION __opencl_c_work_group_collective_functions : disable
+//expected-warning@-1{{OpenCL extension '__opencl_c_work_group_collective_functions' unknown or does not require pragma - ignoring}}
 
 #pragma OPENCL EXTENSION __opencl_c_int64 : enable
 //expected-warning@-1{{OpenCL extension '__opencl_c_int64' unknown or does not require pragma - ignoring}}
@@ -249,6 +255,10 @@
 //expected-warning@-1{{OpenCL extension '__opencl_c_atomic_order_acq_rel' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_atomic_order_seq_cst : enable
 //expected-warning@-1{{OpenCL extension '__opencl_c_atomic_order_seq_cst' unknown or does not require pragma - ignoring}}
+#pragma OPENCL EXTENSION __opencl_c_atomic_scope_device : enable
+//expected-warning@-1{{OpenCL extension '__opencl_c_atomic_scope_device' unknown or does not require pragma - ignoring}}
+#pragma OPENCL EXTENSION __opencl_c_atomic_scope_all_devices : enable
+//expected-warning@-1{{OpenCL extension '__opencl_c_atomic_scope_all_devices' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_device_enqueue : enable
 //expected-warning@-1{{OpenCL extension '__opencl_c_device_enqueue' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_fp64 : enable
@@ -265,3 +275,5 @@
 //expected-warning@-1{{OpenCL extension '__opencl_c_read_write_images' unknown or does not require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_subgroups : enable
 //expected-warning@-1{{OpenCL extension '__opencl_c_subgroups' unknown or does not require pragma - ignoring}}
+#pragma OPENCL EXTENSION __opencl_c_work_group_collective_functions : enable
+//expected-warning@-1{{OpenCL extension '__opencl_c_work_group_collective_functions' unknown or does not require pragma - ignoring}}
Index: clang/lib/Headers/opencl-c-base.h
===================================================================
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -64,18 +64,6 @@
 #define __opencl_c_images 1
 #endif
 
-// Define header-only feature macros for OpenCL C 3.0.
-#if (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
-// For the SPIR and SPIR-V target all features are supported.
-#if defined(__SPIR__) || defined(__SPIRV__)
-#define __opencl_c_work_group_collective_functions 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_read_write_images 1
-#endif // defined(__SPIR__)
-#endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
-
 #if !defined(__opencl_c_generic_address_space)
 // Internal feature macro to provide named (global, local, private) address
 // space overloads for builtin functions that take a pointer argument.
Index: clang/lib/Frontend/InitPreprocessor.cpp
===================================================================
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -731,9 +731,6 @@
 #define OPENCL_GENERIC_EXTENSION(Ext, ...)                                     \
   defineOpenCLExtMacro(#Ext, __VA_ARGS__);
 #include "clang/Basic/OpenCLExtensions.def"
-
-  // Assume compiling for FULL profile
-  Builder.defineMacro("__opencl_c_int64");
 }
 
 static void InitializePredefinedMacros(const TargetInfo &TI,
Index: clang/include/clang/Basic/OpenCLExtensions.def
===================================================================
--- clang/include/clang/Basic/OpenCLExtensions.def
+++ clang/include/clang/Basic/OpenCLExtensions.def
@@ -117,6 +117,10 @@
 OPENCL_OPTIONALCOREFEATURE(__opencl_c_program_scope_global_variables, false, 300, OCL_C_30)
 OPENCL_OPTIONALCOREFEATURE(__opencl_c_fp64, false, 300, OCL_C_30)
 OPENCL_OPTIONALCOREFEATURE(__opencl_c_images, false, 300, OCL_C_30)
+OPENCL_OPTIONALCOREFEATURE(__opencl_c_atomic_scope_device, false, 300, OCL_C_30)
+OPENCL_OPTIONALCOREFEATURE(__opencl_c_atomic_scope_all_devices, false, 300, OCL_C_30)
+OPENCL_OPTIONALCOREFEATURE(__opencl_c_work_group_collective_functions, false, 300, OCL_C_30)
+OPENCL_OPTIONALCOREFEATURE(__opencl_c_int64, false, 300, OCL_C_30)
 
 #undef OPENCL_OPTIONALCOREFEATURE
 #undef OPENCL_COREFEATURE
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to