[PATCH] D103191: [OpenCL] Add support of __opencl_c_program_scope_global_variables feature macro

2021-07-15 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 358909.
azabaznov added a comment.

Restructured test a little


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103191/new/

https://reviews.llvm.org/D103191

Files:
  clang/include/clang/Basic/OpenCLOptions.h
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenOpenCL/addr-space-struct-arg.cl
  clang/test/SemaOpenCL/storageclass.cl

Index: clang/test/SemaOpenCL/storageclass.cl
===
--- clang/test/SemaOpenCL/storageclass.cl
+++ clang/test/SemaOpenCL/storageclass.cl
@@ -1,28 +1,118 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
-
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
 static constant int G1 = 0;
 constant int G2 = 0;
-int G3 = 0;// expected-error{{program scope variable must reside in constant address space}}
-global int G4 = 0; // expected-error{{program scope variable must reside in constant address space}}
 
-static float g_implicit_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
+int G3 = 0;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#endif
+
+global int G4 = 0;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#endif
+
+static float g_implicit_static_var = 0;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#endif
+
 static constant float g_constant_static_var = 0;
-static global float g_global_static_var = 0;   // expected-error {{program scope variable must reside in constant address space}}
-static local float g_local_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
-static private float g_private_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
-static generic float g_generic_static_var = 0; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}}
 
-extern float g_implicit_extern_var; // expected-error {{extern variable must reside in constant address space}}
+static global float g_global_static_var = 0;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#endif
+
+static local float g_local_static_var = 0;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#else
+// expected-error@-4 {{program scope variable must reside in global or constant address space}}
+#endif
+
+static private float g_private_static_var = 0;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#else
+// expected-error@-4 {{program scope variable must reside in global or constant address space}}
+#endif
+
+static generic float g_generic_static_var = 0;
+#if (__OPENCL_C_VERSION__ < 300)
+// expected-error@-2 {{OpenCL C version 1.2 does not support the 'generic' type qualifier}}
+// expected-error@-3 {{program scope variable must reside in constant address space}}
+#elif (__OPENCL_C_VERSION__ == 300)
+ #if !defined(__opencl_c_generic_address_space)
+// expected-error@-6 {{OpenCL C version 3.0 does not support the 'generic' type qualifier}}
+ #endif
+ #if !defined(__opencl_c_program_scope_global_variables)
+// expected-error@-9 {{program scope variable must reside in constant address space}}
+ #endif
+ #if defined(__opencl_c_generic_address_space) && defined(__opencl_c_program_scope_global_variables)
+// expected-error@-12 {{program scope variable must reside in global or constant address space}}
+ #endif
+#endif
+
+extern float g_implicit_extern_var;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{extern variable must reside in constant address space}}
+#endif
+
 extern constant float g_constant_extern_var;
-extern global float g_global_extern_var;   // expected-error {{extern variable must reside in constant address space}}
-extern local float g_local_extern_var; 

[PATCH] D103191: [OpenCL] Add support of __opencl_c_program_scope_global_variables feature macro

2021-07-15 Thread Anton Zabaznov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG05eb59e1d0ea: [OpenCL] Add support of 
__opencl_c_program_scope_global_variables feature macro (authored by azabaznov).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103191/new/

https://reviews.llvm.org/D103191

Files:
  clang/include/clang/Basic/OpenCLOptions.h
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenOpenCL/addr-space-struct-arg.cl
  clang/test/SemaOpenCL/storageclass.cl

Index: clang/test/SemaOpenCL/storageclass.cl
===
--- clang/test/SemaOpenCL/storageclass.cl
+++ clang/test/SemaOpenCL/storageclass.cl
@@ -1,28 +1,118 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
-
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
 static constant int G1 = 0;
 constant int G2 = 0;
-int G3 = 0;// expected-error{{program scope variable must reside in constant address space}}
-global int G4 = 0; // expected-error{{program scope variable must reside in constant address space}}
 
-static float g_implicit_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
+int G3 = 0;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#endif
+
+global int G4 = 0;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#endif
+
+static float g_implicit_static_var = 0;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#endif
+
 static constant float g_constant_static_var = 0;
-static global float g_global_static_var = 0;   // expected-error {{program scope variable must reside in constant address space}}
-static local float g_local_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
-static private float g_private_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
-static generic float g_generic_static_var = 0; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}}
 
-extern float g_implicit_extern_var; // expected-error {{extern variable must reside in constant address space}}
+static global float g_global_static_var = 0;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#endif
+
+static local float g_local_static_var = 0;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#else
+// expected-error@-4 {{program scope variable must reside in global or constant address space}}
+#endif
+
+static private float g_private_static_var = 0;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{program scope variable must reside in constant address space}}
+#else
+// expected-error@-4 {{program scope variable must reside in global or constant address space}}
+#endif
+
+static generic float g_generic_static_var = 0;
+#if (__OPENCL_C_VERSION__ < 300)
+// expected-error@-2 {{OpenCL C version 1.2 does not support the 'generic' type qualifier}}
+// expected-error@-3 {{program scope variable must reside in constant address space}}
+#elif (__OPENCL_C_VERSION__ == 300)
+ #if !defined(__opencl_c_generic_address_space)
+// expected-error@-6 {{OpenCL C version 3.0 does not support the 'generic' type qualifier}}
+ #endif
+ #if !defined(__opencl_c_program_scope_global_variables)
+// expected-error@-9 {{program scope variable must reside in constant address space}}
+ #endif
+ #if defined(__opencl_c_generic_address_space) && defined(__opencl_c_program_scope_global_variables)
+// expected-error@-12 {{program scope variable must reside in global or constant address space}}
+ #endif
+#endif
+
+extern float g_implicit_extern_var;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-2 {{extern variable must reside in constant address space}}
+#endif
+
 extern constant float g_constant_extern_var;

[PATCH] D106260: [OpenCL] Add support of __opencl_c_3d_image_writes feature macro

2021-07-19 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov created this revision.
azabaznov added reviewers: Anastasia, svenvh.
Herald added subscribers: ldrumm, kerbowa, yaxunl, nhaehnle, jvesely.
azabaznov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This feature requires support of __opencl_c_images, so diagnostics for that is 
provided as well.
Also, ensure that cl_khr_3d_image_writes feature macro is set to the same value.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106260

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Sema/SemaType.cpp
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/access-qualifier.cl
  clang/test/SemaOpenCL/unsupported-image.cl

Index: clang/test/SemaOpenCL/unsupported-image.cl
===
--- clang/test/SemaOpenCL/unsupported-image.cl
+++ clang/test/SemaOpenCL/unsupported-image.cl
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images,-__opencl_c_read_write_images %s
-// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images,-__opencl_c_read_write_images,-cl_khr_3d_image_writes,-__opencl_c_3d_image_writes %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images,+__opencl_c_read_write_images,+cl_khr_3d_image_writes,+__opencl_c_3d_image_writes %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images,+__opencl_c_read_write_images,-cl_khr_3d_image_writes,-__opencl_c_3d_image_writes %s
 
-#ifdef __opencl_c_images
+#if defined(__opencl_c_images) && defined(__opencl_c_3d_image_writes)
 //expected-no-diagnostics
 #endif
 
@@ -59,3 +60,10 @@
 #if !defined(__opencl_c_images)
 // expected-error@-2{{use of type 'sampler_t' requires __opencl_c_images support}}
 #endif
+
+void test12(write_only image3d_t i) {}
+#if !defined(__opencl_c_images)
+// expected-error@-2{{use of type '__write_only image3d_t' requires __opencl_c_images support}}
+#elif !defined(__opencl_c_3d_image_writes)
+// expected-error@-4{{use of 3d image writes requires cl_khr_3d_image_writes and __opencl_c_3d_image_writes support}}
+#endif
Index: clang/test/SemaOpenCL/access-qualifier.cl
===
--- clang/test/SemaOpenCL/access-qualifier.cl
+++ clang/test/SemaOpenCL/access-qualifier.cl
@@ -71,7 +71,7 @@
 #endif
 
 #if __OPENCL_C_VERSION__ < 200
-kernel void test_image3d_wo(write_only image3d_t img) {} // expected-error {{use of type '__write_only image3d_t' requires cl_khr_3d_image_writes support}}
+kernel void test_image3d_wo(write_only image3d_t img) {} // expected-error {{use of 3d image writes requires cl_khr_3d_image_writes support}}
 #endif
 
 #if (__OPENCL_C_VERSION__ == 200) || (__OPENCL_C_VERSION__ == 300 && defined(__opencl_c_read_write_images))
Index: clang/test/Misc/opencl-c-3.0.incorrect_options.cl
===
--- clang/test/Misc/opencl-c-3.0.incorrect_options.cl
+++ clang/test/Misc/opencl-c-3.0.incorrect_options.cl
@@ -1,6 +1,14 @@
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=-__opencl_c_fp64,+cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_fp64,-cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
+
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_read_write_images,-__opencl_c_images %s 2>&1 | FileCheck -check-prefix=CHECK-READ-WRITE-IMAGES %s
 
+// RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_3d_image_writes,+__opencl_c_images,-cl_khr_3d_image_writes %s 2>&1 | FileCheck -check-prefix=CHECK-3D-WRITE-IMAGES-DIFF %s
+// RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_3d_image_writes,-__opencl_c_images %s 2>&1 | FileCheck -check-prefix=CHECK-3D-WRITE-IMAGES-DEPS %s
+
 // CHECK-FP64: error: options cl_khr_fp64 and __opencl_c_fp64 are set to different values
+
 // CHECK-READ-WRITE-IMAGES: error: feature __opencl_c_read_write_images requires support of __opencl_c_images feature
+
+// CHECK-3D-WRITE-IMAGES-DIFF: options cl_khr_3d_image_writes and __opencl_c_3d_image_writes are set to different values
+// CHECK-3D-WRITE-IMAGES-DEPS: error: feature __opencl_c_3d_image_writes requires support of __opencl_c_images feature
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1724,21 +1724,26 @@
 
   if (S.getLangOpts().OpenCL) {
 const auto &OpenCLOptions = 

[PATCH] D106260: [OpenCL] Add support of __opencl_c_3d_image_writes feature macro

2021-07-19 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:1732-1734
+// __opencl_c_3d_image_writes feature. OpenCL C v3.0 API s4.2 - For devices
+// that support OpenCL 3.0, cl_khr_3d_image_writes must be returned when 
and
+// only when the optional feature is supported

Note this. Is it OK to refer to API spec here?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106260/new/

https://reviews.llvm.org/D106260

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106260: [OpenCL] Add support of __opencl_c_3d_image_writes feature macro

2021-07-19 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 359734.
azabaznov added a comment.

Change diagnostic output


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106260/new/

https://reviews.llvm.org/D106260

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Sema/SemaType.cpp
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/unsupported-image.cl

Index: clang/test/SemaOpenCL/unsupported-image.cl
===
--- clang/test/SemaOpenCL/unsupported-image.cl
+++ clang/test/SemaOpenCL/unsupported-image.cl
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images,-__opencl_c_read_write_images %s
-// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images,-__opencl_c_read_write_images,-cl_khr_3d_image_writes,-__opencl_c_3d_image_writes %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images,+__opencl_c_read_write_images,+cl_khr_3d_image_writes,+__opencl_c_3d_image_writes %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images,+__opencl_c_read_write_images,-cl_khr_3d_image_writes,-__opencl_c_3d_image_writes %s
 
-#ifdef __opencl_c_images
+#if defined(__opencl_c_images) && defined(__opencl_c_3d_image_writes)
 //expected-no-diagnostics
 #endif
 
@@ -59,3 +60,10 @@
 #if !defined(__opencl_c_images)
 // expected-error@-2{{use of type 'sampler_t' requires __opencl_c_images support}}
 #endif
+
+void test12(write_only image3d_t i) {}
+#if !defined(__opencl_c_images)
+// expected-error@-2{{use of type '__write_only image3d_t' requires __opencl_c_images support}}
+#elif !defined(__opencl_c_3d_image_writes)
+// expected-error@-4{{use of type '__write_only image3d_t' requires cl_khr_3d_image_writes and __opencl_c_3d_image_writes support}}
+#endif
Index: clang/test/Misc/opencl-c-3.0.incorrect_options.cl
===
--- clang/test/Misc/opencl-c-3.0.incorrect_options.cl
+++ clang/test/Misc/opencl-c-3.0.incorrect_options.cl
@@ -1,6 +1,14 @@
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=-__opencl_c_fp64,+cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_fp64,-cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
+
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_read_write_images,-__opencl_c_images %s 2>&1 | FileCheck -check-prefix=CHECK-READ-WRITE-IMAGES %s
 
+// RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_3d_image_writes,+__opencl_c_images,-cl_khr_3d_image_writes %s 2>&1 | FileCheck -check-prefix=CHECK-3D-WRITE-IMAGES-DIFF %s
+// RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_3d_image_writes,-__opencl_c_images %s 2>&1 | FileCheck -check-prefix=CHECK-3D-WRITE-IMAGES-DEPS %s
+
 // CHECK-FP64: error: options cl_khr_fp64 and __opencl_c_fp64 are set to different values
+
 // CHECK-READ-WRITE-IMAGES: error: feature __opencl_c_read_write_images requires support of __opencl_c_images feature
+
+// CHECK-3D-WRITE-IMAGES-DIFF: options cl_khr_3d_image_writes and __opencl_c_3d_image_writes are set to different values
+// CHECK-3D-WRITE-IMAGES-DEPS: error: feature __opencl_c_3d_image_writes requires support of __opencl_c_images feature
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1724,21 +1724,26 @@
 
   if (S.getLangOpts().OpenCL) {
 const auto &OpenCLOptions = S.getOpenCLOptions();
-StringRef OptName;
+bool IsOpenCLC30 = (S.getLangOpts().OpenCLVersion == 300);
 // OpenCL C v3.0 s6.3.3 - OpenCL image types require __opencl_c_images
-// support
+// support.
+// OpenCL C v3.0 s6.2.1 - OpenCL 3d image write types requires support
+// for OpenCL C 2.0, or OpenCL C 3.0 or newer and the
+// __opencl_c_3d_image_writes feature. OpenCL C v3.0 API s4.2 - For devices
+// that support OpenCL 3.0, cl_khr_3d_image_writes must be returned when and
+// only when the optional feature is supported
 if ((Result->isImageType() || Result->isSamplerT()) &&
-(S.getLangOpts().OpenCLVersion >= 300 &&
- !OpenCLOptions.isSupported("__opencl_c_images", S.getLangOpts(
-  OptName = "__opencl_c_images";
-else if (Result->isOCLImage3dWOType() &&
- !OpenCLOptions.isSupported("cl_khr_3d_image_writes",
-S.getLangOpts()))
-  OptName = "cl_khr_3d_i

[PATCH] D106111: opencl-c.h: add initial CL 3.0 conditionals for atomic operations.

2021-07-20 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

You also need to guard //memory_order_seq_cst// enum entry. Note that 
//memory_order_acq_rel// is always defined as it can be used in 
//atomic_work_item_fence()// built-in function, AFAIR in all other cases if 
//memory_order_acq_rel// is used without //__opencl_c_atomic_order_acq_rel// 
feature it is undefined behavior.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106111/new/

https://reviews.llvm.org/D106111

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106504: [OpenCL] Change default standard version to CL1.2

2021-07-22 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/test/Parser/opencl-atomics-cl20.cl:7
 
-#if defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= CL_VERSION_1_2
+#if defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 #define LANG_VER_OK

As OpenCL C version defaults to 1.2, I think LANG_VER_OK should always be 
defined now (due to run lines). But OpenCL C 1.2 has never been tested in this 
test... Is it a mistake in current rest?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106504/new/

https://reviews.llvm.org/D106504

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106260: [OpenCL] Add support of __opencl_c_3d_image_writes feature macro

2021-07-23 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 361155.
azabaznov added a comment.

Unify with `err_opencl_requires_extension`. Infrastructure for getting aliased 
extensions seems to messy and doesn't seem worth it yet since there are only 
two cases of such functionality (fp64 and 3d image writes) :(


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106260/new/

https://reviews.llvm.org/D106260

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Sema/SemaType.cpp
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/unsupported-image.cl

Index: clang/test/SemaOpenCL/unsupported-image.cl
===
--- clang/test/SemaOpenCL/unsupported-image.cl
+++ clang/test/SemaOpenCL/unsupported-image.cl
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images,-__opencl_c_read_write_images %s
-// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images,-__opencl_c_read_write_images,-cl_khr_3d_image_writes,-__opencl_c_3d_image_writes %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images,+__opencl_c_read_write_images,+cl_khr_3d_image_writes,+__opencl_c_3d_image_writes %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images,+__opencl_c_read_write_images,-cl_khr_3d_image_writes,-__opencl_c_3d_image_writes %s
 
-#ifdef __opencl_c_images
+#if defined(__opencl_c_images) && defined(__opencl_c_3d_image_writes)
 //expected-no-diagnostics
 #endif
 
@@ -59,3 +60,10 @@
 #if !defined(__opencl_c_images)
 // expected-error@-2{{use of type 'sampler_t' requires __opencl_c_images support}}
 #endif
+
+void test12(write_only image3d_t i) {}
+#if !defined(__opencl_c_images)
+// expected-error@-2{{use of type '__write_only image3d_t' requires __opencl_c_images support}}
+#elif !defined(__opencl_c_3d_image_writes)
+// expected-error@-4{{use of type '__write_only image3d_t' requires cl_khr_3d_image_writes and __opencl_c_3d_image_writes support}}
+#endif
Index: clang/test/Misc/opencl-c-3.0.incorrect_options.cl
===
--- clang/test/Misc/opencl-c-3.0.incorrect_options.cl
+++ clang/test/Misc/opencl-c-3.0.incorrect_options.cl
@@ -1,6 +1,14 @@
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=-__opencl_c_fp64,+cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_fp64,-cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
+
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_read_write_images,-__opencl_c_images %s 2>&1 | FileCheck -check-prefix=CHECK-READ-WRITE-IMAGES %s
 
+// RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_3d_image_writes,+__opencl_c_images,-cl_khr_3d_image_writes %s 2>&1 | FileCheck -check-prefix=CHECK-3D-WRITE-IMAGES-DIFF %s
+// RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_3d_image_writes,-__opencl_c_images %s 2>&1 | FileCheck -check-prefix=CHECK-3D-WRITE-IMAGES-DEPS %s
+
 // CHECK-FP64: error: options cl_khr_fp64 and __opencl_c_fp64 are set to different values
+
 // CHECK-READ-WRITE-IMAGES: error: feature __opencl_c_read_write_images requires support of __opencl_c_images feature
+
+// CHECK-3D-WRITE-IMAGES-DIFF: options cl_khr_3d_image_writes and __opencl_c_3d_image_writes are set to different values
+// CHECK-3D-WRITE-IMAGES-DEPS: error: feature __opencl_c_3d_image_writes requires support of __opencl_c_images feature
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1525,18 +1525,20 @@
 break;
   case DeclSpec::TST_float:   Result = Context.FloatTy; break;
   case DeclSpec::TST_double:
+if (DS.getTypeSpecWidth() == TypeSpecifierWidth::Long)
+  Result = Context.LongDoubleTy;
+else
+  Result = Context.DoubleTy;
 if (S.getLangOpts().OpenCL) {
   if (!S.getOpenCLOptions().isSupported("cl_khr_fp64", S.getLangOpts()))
-S.Diag(DS.getTypeSpecTypeLoc(),
-   diag::err_opencl_double_requires_extension)
-<< (S.getLangOpts().OpenCLVersion >= 300);
+S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension)
+<< 0 << Result
+<< (S.getLangOpts().OpenCLVersion == 300
+? "cl_khr_fp64 and __opencl_c_fp64"
+: "cl_khr_fp64");
   else if (!S.getOpenCLOptions().isAvailableOption("cl_khr_fp64", S.getLangOpts()))
 

[PATCH] D106748: [OpenCL] Add support of __opencl_c_pipes feature macro.

2021-07-24 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov created this revision.
azabaznov added reviewers: Anastasia, svenvh.
Herald added subscribers: ldrumm, yaxunl.
azabaznov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

'pipe' keyword is introduced in OpenCL C 2.0: so do checks for OpenCL C version 
while
parsing and then later on check for language options to construct actual pipe. 
This feature
requires support of __opencl_c_generic_address_space, so diagnostics for that 
is provided as well.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106748

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/Sema.cpp
  clang/test/CodeGenOpenCL/address-spaces-mangling.cl
  clang/test/CodeGenOpenCL/address-spaces.cl
  clang/test/CodeGenOpenCL/pipe_builtin.cl
  clang/test/CodeGenOpenCL/pipe_types.cl
  clang/test/CodeGenOpenCL/pipe_types_mangling.cl
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/Parser/opencl-cl20.cl
  clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
  clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
  clang/test/SemaOpenCL/storageclass.cl

Index: clang/test/SemaOpenCL/storageclass.cl
===
--- clang/test/SemaOpenCL/storageclass.cl
+++ clang/test/SemaOpenCL/storageclass.cl
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
 static constant int G1 = 0;
@@ -44,11 +44,11 @@
 
 static generic float g_generic_static_var = 0;
 #if (__OPENCL_C_VERSION__ < 300)
-// expected-error@-2 {{OpenCL C version 1.2 does not support the 'generic' type qualifier}}
+// expected-error@-2 {{type qualifier 'generic' requires OpenCL C 2.0 or later and a feature support}}
 // expected-error@-3 {{program scope variable must reside in constant address space}}
 #elif (__OPENCL_C_VERSION__ == 300)
  #if !defined(__opencl_c_generic_address_space)
-// expected-error@-6 {{OpenCL C version 3.0 does not support the 'generic' type qualifier}}
+// expected-error@-6 {{type qualifier 'generic' requires OpenCL C 2.0 or later and a feature support}}
  #endif
  #if !defined(__opencl_c_program_scope_global_variables)
 // expected-error@-9 {{program scope variable must reside in constant address space}}
@@ -86,11 +86,11 @@
 
 extern generic float g_generic_extern_var;
 #if (__OPENCL_C_VERSION__ < 300)
-// expected-error@-2 {{OpenCL C version 1.2 does not support the 'generic' type qualifier}}
+// expected-error@-2 {{type qualifier 'generic' requires OpenCL C 2.0 or later and a feature support}}
 // expected-error@-3 {{extern variable must reside in constant address space}}
 #elif (__OPENCL_C_VERSION__ == 300)
  #if !defined(__opencl_c_generic_address_space)
-// expected-error@-6 {{OpenCL C version 3.0 does not support the 'generic' type qualifier}}
+// expected-error@-6 {{type qualifier 'generic' requires OpenCL C 2.0 or later and a feature support}}
  #endif
  #if !defined(__opencl_c_program_scope_global_variables)
 // expected-error@-9 {{extern variable must reside in constant address space}}
@@ -189,11 +189,11 @@
 
   static generic float l_generic_static_var = 0;
 #if (__OPENCL_C_VERSION__ < 300)
-// expected-error@-2 {{OpenCL C version 1.2 does not support the 'generic' type qualifier}}
+// expected-error@-2 {{type qualifier 'generic' requires OpenCL C 2.0 or later and a feature support}}
 // expected-error@-3 {{variables in function scope cannot be declared static}}
 #elif (__OPENCL_C_VERSION__ == 300)
  #if !defined(__opencl_c_generic_address_space)
-// expected-error@-6 {{OpenCL C version 3.0 does not support the 'generic' type qualifier}}
+// expected-error@-6 {{type qualifier 'generic' requires OpenCL C 2.0 or later and a feature support}}
  #endif
  #if !defined(__opencl_c_program_scope_global_variables)
 // expected-error@-9 {{static local variable must reside in constant address space}}
@@ -239,11 +239,11 @@
 
   extern generi

[PATCH] D106748: [OpenCL] Add support of __opencl_c_pipes feature macro.

2021-07-26 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticCommonKinds.td:154
   "'%2' %select{type qualifier|storage class specifier}3">;
+def err_opencl_type_specifier_requires : Error<
+  "%select{type qualifier|storage class specifier}0 '%1' requires "

Anastasia wrote:
> If possible I would prefer to unify the diagnostics. How about something like:
> 
> ```
> '%2' %select{type qualifier|storage class specifier}3 is unsupported in 
> %select{OpenCL C|C++ for OpenCL}0 version %1
> ```
> 
> then where we print the diagnostic we can special case OpenCL 3.0 to also 
> print additionally the feature information. FYI we could add the special case 
> for OpenCL 3.0 later on in a separate patch and for now just reuse the 
> diagnostic as is. Then this patch could still go into release 13 although a 
> bit tight but doable.
This is actually the way how clang provides diagnostic now 
(https://godbolt.org/z/9P6PWdE5M):

```
OpenCL C version 3.0 does not support the 'generic' type qualifier
```
Here I just wanted to unify cases for `pipe` and `generic` since they both 
require OpenCL C 2.0 or later with a feature. Do you think it makes sense?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106748/new/

https://reviews.llvm.org/D106748

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106748: [OpenCL] Add support of __opencl_c_pipes feature macro.

2021-07-27 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 362018.
azabaznov added a comment.
Herald added a subscriber: dexonsmith.

Preserve existing diagnostic with `err_opencl_unknown_type_specifier`, fix 
comments for language option


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106748/new/

https://reviews.llvm.org/D106748

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/Sema.cpp
  clang/test/CodeGenOpenCL/address-spaces-mangling.cl
  clang/test/CodeGenOpenCL/address-spaces.cl
  clang/test/CodeGenOpenCL/pipe_builtin.cl
  clang/test/CodeGenOpenCL/pipe_types.cl
  clang/test/CodeGenOpenCL/pipe_types_mangling.cl
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
  clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
  clang/test/SemaOpenCL/storageclass.cl

Index: clang/test/SemaOpenCL/storageclass.cl
===
--- clang/test/SemaOpenCL/storageclass.cl
+++ clang/test/SemaOpenCL/storageclass.cl
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
 static constant int G1 = 0;
Index: clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
===
--- clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
+++ clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_pipes,+__opencl_c_generic_address_space
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++
 
 global pipe int gp;// expected-error {{type '__global read_only pipe int' can only be used as a function parameter in OpenCL}}
Index: clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
===
--- clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
+++ clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
@@ -1,9 +1,23 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_pipes,-__opencl_c_generic_address_space
 
 void foo(read_only pipe int p);
-// expected-warning@-1 {{type specifier missing, defaults to 'int'}}
-// expected-error@-2 {{access qualifier can only be used for pipe and image type}}
-// expected-error@-3 {{expected ')'}} expected-note@-3 {{to match this '('}}
+#if __OPENCL_C_VERSION__ > 120
+// expected-error@-2 {{OpenCL C version 3.0 does not support the 'pipe' type qualifier}}
+// expected-error@-3 {{access qualifier can only be used for pipe and image type}}
+#else
+// expected-warning@-5 {{type specifier missing, defaults to 'int'}}
+// expected-error@-6 {{access qualifier can only be used for pipe and image type}}
+// expected-error@-7 {{expected ')'}} expected-note@-7 {{to match this '('}}
+#endif
 
 // 'pipe' should be accepted as an identifier.
 typedef int pipe;
+#if __OPENCL_C_VERSION__ > 120
+// expected-error@-2 {{OpenCL C version 3.0 does not support the 'pipe' type qualifier}}
+// expected-warning@-3 {{typedef requires a name}}
+#endif
+
+void bar() {
+ reserve_id_t r; // expected-error {{use of undeclared identifier 'reserve_id_t'}}
+}
Index: clang/test/Misc/opencl-c-3.0.incorrect_options.cl
===
--- clang/test/Misc/opencl-c-3.0.incorrect_options.cl
+++ clang/test/Misc/opencl-c-3.0.incorrect_options.cl
@@ -1,6 +1,8 @@
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=-__opencl_c_fp64,+cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_fp64,-cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
 // RUN: not %clang

[PATCH] D106778: [OpenCL] opencl-c.h: add CL 3.0 non-generic address space atomics

2021-07-28 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/lib/Headers/opencl-c.h:13304
+#else
+void __ovld atomic_init(volatile __global atomic_int *object, int value);
+void __ovld atomic_init(volatile __local atomic_int *object, int value);

These new atomics with global and local pointer as argument were introduced 
only in OpenCL C 3.0 and have never been exposed in earlier versions, so I 
think you should guard them with //#if (__OPENCL_C_VERSION__ >= 
CL_VERSION_3_0)//


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106778/new/

https://reviews.llvm.org/D106778

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106260: [OpenCL] Add support of __opencl_c_3d_image_writes feature macro

2021-07-29 Thread Anton Zabaznov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf16a4fcbe510: [OpenCL] Add support of 
__opencl_c_3d_image_writes feature macro (authored by azabaznov).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106260/new/

https://reviews.llvm.org/D106260

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Sema/SemaType.cpp
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/unsupported-image.cl

Index: clang/test/SemaOpenCL/unsupported-image.cl
===
--- clang/test/SemaOpenCL/unsupported-image.cl
+++ clang/test/SemaOpenCL/unsupported-image.cl
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images,-__opencl_c_read_write_images %s
-// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images,-__opencl_c_read_write_images,-cl_khr_3d_image_writes,-__opencl_c_3d_image_writes %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images,+__opencl_c_read_write_images,+cl_khr_3d_image_writes,+__opencl_c_3d_image_writes %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images,+__opencl_c_read_write_images,-cl_khr_3d_image_writes,-__opencl_c_3d_image_writes %s
 
-#ifdef __opencl_c_images
+#if defined(__opencl_c_images) && defined(__opencl_c_3d_image_writes)
 //expected-no-diagnostics
 #endif
 
@@ -59,3 +60,10 @@
 #if !defined(__opencl_c_images)
 // expected-error@-2{{use of type 'sampler_t' requires __opencl_c_images support}}
 #endif
+
+void test12(write_only image3d_t i) {}
+#if !defined(__opencl_c_images)
+// expected-error@-2{{use of type '__write_only image3d_t' requires __opencl_c_images support}}
+#elif !defined(__opencl_c_3d_image_writes)
+// expected-error@-4{{use of type '__write_only image3d_t' requires cl_khr_3d_image_writes and __opencl_c_3d_image_writes support}}
+#endif
Index: clang/test/Misc/opencl-c-3.0.incorrect_options.cl
===
--- clang/test/Misc/opencl-c-3.0.incorrect_options.cl
+++ clang/test/Misc/opencl-c-3.0.incorrect_options.cl
@@ -1,6 +1,14 @@
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=-__opencl_c_fp64,+cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_fp64,-cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
+
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_read_write_images,-__opencl_c_images %s 2>&1 | FileCheck -check-prefix=CHECK-READ-WRITE-IMAGES %s
 
+// RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_3d_image_writes,+__opencl_c_images,-cl_khr_3d_image_writes %s 2>&1 | FileCheck -check-prefix=CHECK-3D-WRITE-IMAGES-DIFF %s
+// RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_3d_image_writes,-__opencl_c_images %s 2>&1 | FileCheck -check-prefix=CHECK-3D-WRITE-IMAGES-DEPS %s
+
 // CHECK-FP64: error: options cl_khr_fp64 and __opencl_c_fp64 are set to different values
+
 // CHECK-READ-WRITE-IMAGES: error: feature __opencl_c_read_write_images requires support of __opencl_c_images feature
+
+// CHECK-3D-WRITE-IMAGES-DIFF: options cl_khr_3d_image_writes and __opencl_c_3d_image_writes are set to different values
+// CHECK-3D-WRITE-IMAGES-DEPS: error: feature __opencl_c_3d_image_writes requires support of __opencl_c_images feature
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1525,18 +1525,20 @@
 break;
   case DeclSpec::TST_float:   Result = Context.FloatTy; break;
   case DeclSpec::TST_double:
+if (DS.getTypeSpecWidth() == TypeSpecifierWidth::Long)
+  Result = Context.LongDoubleTy;
+else
+  Result = Context.DoubleTy;
 if (S.getLangOpts().OpenCL) {
   if (!S.getOpenCLOptions().isSupported("cl_khr_fp64", S.getLangOpts()))
-S.Diag(DS.getTypeSpecTypeLoc(),
-   diag::err_opencl_double_requires_extension)
-<< (S.getLangOpts().OpenCLVersion >= 300);
+S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension)
+<< 0 << Result
+<< (S.getLangOpts().OpenCLVersion == 300
+? "cl_khr_fp64 and __opencl_c_fp64"
+: "cl_khr_fp64");
   else if (!S.getOpenCLOptions().isAvailableOption("cl_khr_fp64", S.getLangOpts()))
 S.Diag(DS.getTypeSpecTypeLoc(), diag::e

[PATCH] D106748: [OpenCL] Add support of __opencl_c_pipes feature macro.

2021-07-29 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 362955.
azabaznov added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106748/new/

https://reviews.llvm.org/D106748

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/Sema.cpp
  clang/test/CodeGenOpenCL/address-spaces-mangling.cl
  clang/test/CodeGenOpenCL/address-spaces.cl
  clang/test/CodeGenOpenCL/pipe_builtin.cl
  clang/test/CodeGenOpenCL/pipe_types.cl
  clang/test/CodeGenOpenCL/pipe_types_mangling.cl
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
  clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
  clang/test/SemaOpenCL/storageclass.cl

Index: clang/test/SemaOpenCL/storageclass.cl
===
--- clang/test/SemaOpenCL/storageclass.cl
+++ clang/test/SemaOpenCL/storageclass.cl
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
 static constant int G1 = 0;
Index: clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
===
--- clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
+++ clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_pipes,+__opencl_c_generic_address_space
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++
 
 global pipe int gp;// expected-error {{type '__global read_only pipe int' can only be used as a function parameter in OpenCL}}
Index: clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
===
--- clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
+++ clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
@@ -1,9 +1,23 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_pipes,-__opencl_c_generic_address_space
 
 void foo(read_only pipe int p);
-// expected-warning@-1 {{type specifier missing, defaults to 'int'}}
-// expected-error@-2 {{access qualifier can only be used for pipe and image type}}
-// expected-error@-3 {{expected ')'}} expected-note@-3 {{to match this '('}}
+#if __OPENCL_C_VERSION__ > 120
+// expected-error@-2 {{OpenCL C version 3.0 does not support the 'pipe' type qualifier}}
+// expected-error@-3 {{access qualifier can only be used for pipe and image type}}
+#else
+// expected-warning@-5 {{type specifier missing, defaults to 'int'}}
+// expected-error@-6 {{access qualifier can only be used for pipe and image type}}
+// expected-error@-7 {{expected ')'}} expected-note@-7 {{to match this '('}}
+#endif
 
 // 'pipe' should be accepted as an identifier.
 typedef int pipe;
+#if __OPENCL_C_VERSION__ > 120
+// expected-error@-2 {{OpenCL C version 3.0 does not support the 'pipe' type qualifier}}
+// expected-warning@-3 {{typedef requires a name}}
+#endif
+
+void bar() {
+ reserve_id_t r; // expected-error {{use of undeclared identifier 'reserve_id_t'}}
+}
Index: clang/test/Misc/opencl-c-3.0.incorrect_options.cl
===
--- clang/test/Misc/opencl-c-3.0.incorrect_options.cl
+++ clang/test/Misc/opencl-c-3.0.incorrect_options.cl
@@ -1,8 +1,7 @@
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=-__opencl_c_fp64,+cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_fp64,-cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
-
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_read_write_images,-__opencl_c_images %s 2>&1 | FileCheck -check-pre

[PATCH] D106748: [OpenCL] Add support of __opencl_c_pipes feature macro.

2021-07-29 Thread Anton Zabaznov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd1e4b2575673: [OpenCL] Add support of __opencl_c_pipes 
feature macro. (authored by azabaznov).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106748/new/

https://reviews.llvm.org/D106748

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/Sema.cpp
  clang/test/CodeGenOpenCL/address-spaces-mangling.cl
  clang/test/CodeGenOpenCL/address-spaces.cl
  clang/test/CodeGenOpenCL/pipe_builtin.cl
  clang/test/CodeGenOpenCL/pipe_types.cl
  clang/test/CodeGenOpenCL/pipe_types_mangling.cl
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
  clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
  clang/test/SemaOpenCL/storageclass.cl

Index: clang/test/SemaOpenCL/storageclass.cl
===
--- clang/test/SemaOpenCL/storageclass.cl
+++ clang/test/SemaOpenCL/storageclass.cl
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
 static constant int G1 = 0;
Index: clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
===
--- clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
+++ clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_pipes,+__opencl_c_generic_address_space
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++
 
 global pipe int gp;// expected-error {{type '__global read_only pipe int' can only be used as a function parameter in OpenCL}}
Index: clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
===
--- clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
+++ clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
@@ -1,9 +1,23 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_pipes,-__opencl_c_generic_address_space
 
 void foo(read_only pipe int p);
-// expected-warning@-1 {{type specifier missing, defaults to 'int'}}
-// expected-error@-2 {{access qualifier can only be used for pipe and image type}}
-// expected-error@-3 {{expected ')'}} expected-note@-3 {{to match this '('}}
+#if __OPENCL_C_VERSION__ > 120
+// expected-error@-2 {{OpenCL C version 3.0 does not support the 'pipe' type qualifier}}
+// expected-error@-3 {{access qualifier can only be used for pipe and image type}}
+#else
+// expected-warning@-5 {{type specifier missing, defaults to 'int'}}
+// expected-error@-6 {{access qualifier can only be used for pipe and image type}}
+// expected-error@-7 {{expected ')'}} expected-note@-7 {{to match this '('}}
+#endif
 
 // 'pipe' should be accepted as an identifier.
 typedef int pipe;
+#if __OPENCL_C_VERSION__ > 120
+// expected-error@-2 {{OpenCL C version 3.0 does not support the 'pipe' type qualifier}}
+// expected-warning@-3 {{typedef requires a name}}
+#endif
+
+void bar() {
+ reserve_id_t r; // expected-error {{use of undeclared identifier 'reserve_id_t'}}
+}
Index: clang/test/Misc/opencl-c-3.0.incorrect_options.cl
===
--- clang/test/Misc/opencl-c-3.0.incorrect_options.cl
+++ clang/test/Misc/opencl-c-3.0.incorrect_options.cl
@@ -1,8 +1,7 @@
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=-__opencl_c_fp64,+cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_fp64,-cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP6

[PATCH] D106778: [OpenCL] opencl-c.h: add CL 3.0 non-generic address space atomics

2021-07-29 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/lib/Headers/opencl-c.h:13303
 #endif
+#elif __OPENCL_C_VERSION__ >= CL_VERSION_3_0
+void __ovld atomic_init(volatile __global atomic_int *object, int value);

Sorry, I overlooked that. Not //elif//, just //if// as these are available in 
3.0 even with generic address space feature 
(https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_C.html#the-atomic_init-function):

```
// Requires OpenCL C 3.0 or newer.
void atomic_init(volatile __global A *obj, C value)
void atomic_init(volatile __local A *obj, C value)

// Requires OpenCL C 2.0, or OpenCL C 3.0 or newer and the
// __opencl_c_generic_address_space feature.
void atomic_init(volatile A *obj, C value)
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106778/new/

https://reviews.llvm.org/D106778

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106748: [OpenCL] Add support of __opencl_c_pipes feature macro.

2021-07-29 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

Reverted it due too suspicious failing:

  error: 'error' diagnostics expected but not seen: 
File 
/home/tcwg-buildslave/worker/clang-armv7-2stage/llvm/clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
 Line 8: type '__global write_only pipe int ({{(void)?}})' can only be used as 
a function parameter in OpenCL
  error: 'error' diagnostics seen but not expected: 
File 
/home/tcwg-buildslave/worker/clang-armv7-2stage/llvm/clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
 Line 8: type '__private write_only pipe int (void)' can only be used as a 
function parameter in OpenCL
  2 errors generated.

I don't think that's because of triple was unset, I think the main reason was 
that program scope variables were not supported, but need to have a look closely


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106748/new/

https://reviews.llvm.org/D106748

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118605: [OpenCL] Add support of language builtins for OpenCL C 3.0

2022-02-04 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 405921.
azabaznov added a comment.

Reimplement with checking language options only.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118605/new/

https://reviews.llvm.org/D118605

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/Builtins.h
  clang/lib/Basic/Builtins.cpp
  clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
  clang/test/CodeGenOpenCL/pipe_types.cl
  clang/test/CodeGenOpenCL/to_addr_builtin.cl
  clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
  clang/test/SemaOpenCL/clang-builtin-version.cl
  clang/test/SemaOpenCL/to_addr_builtin.cl

Index: clang/test/SemaOpenCL/to_addr_builtin.cl
===
--- clang/test/SemaOpenCL/to_addr_builtin.cl
+++ clang/test/SemaOpenCL/to_addr_builtin.cl
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -verify -fsyntax-only %s
 // RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL2.0 %s
+// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL3.0 -cl-ext=-all %s
+// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL3.0 %s
 
 void test(void) {
   global int *glob;
@@ -11,7 +13,7 @@
   const_int_ty *con_typedef;
 
   glob = to_global(glob, loc);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_global' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
@@ -20,28 +22,28 @@
 
   int x;
   glob = to_global(x);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument x to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument con to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con_typedef);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument con_typedef to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   loc = to_global(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
 #else
   // expected-error@-4{{assigning '__global int *' to '__local int *__private' changes address space of pointer}}
@@ -49,7 +51,7 @@
 #endif
 
   loc = to_private(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_private' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
 #else
@@ -58,17 +60,17 @@
 #endif
 
   loc = to_local(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_local' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
   // expected-note@-4{{did you mean 'to_global'}}
-  // expected-note@13{{'to_global' declared here}}
+  // expected-note@15{{'to_global' declared here}}
 #else
   // expected-warning@-7{{passing non-generic address space pointer to to_local may cause dynamic conversion affecting performance}}
 #endif
 
   priv = to_global(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible in

[PATCH] D118999: [OpenCL] Adjust diagnostic for subgroup support.

2022-02-04 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov created this revision.
azabaznov added reviewers: Anastasia, svenvh.
Herald added subscribers: Naghasan, ldrumm, yaxunl.
azabaznov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

OpenCL C 3.0 __opencl_c_subgroups feature is slightly different
then other equivalent features and extensions (fp64 and 3d image writes):
OpenCL C 3.0 device can support the extension but not the feature.
cl_khr_subgroups requires subgroup independent forward progress.

This patch adjusts the check which is used when translating language
builtins to check either the extension or feature is supported.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118999

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaOpenCL/cl20-device-side-enqueue.cl


Index: clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
===
--- clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -236,12 +236,12 @@
 kernel void foo1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // 
expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' 
requires cl_khr_subgroups support}}
+  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // 
expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' 
requires support of cl_khr_subgroups extension or __opencl_c_subgroups OpenCL C 
3.0 feature}}
 }
 
 kernel void bar1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error 
{{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires 
cl_khr_subgroups support}}
+  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error 
{{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires support 
of cl_khr_subgroups extension or __opencl_c_subgroups OpenCL C 3.0 feature}}
 }
 #endif // ifdef cl_khr_subgroups
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1042,9 +1042,11 @@
 }
 
 static bool checkOpenCLSubgroupExt(Sema &S, CallExpr *Call) {
-  if (!S.getOpenCLOptions().isSupported("cl_khr_subgroups", S.getLangOpts())) {
-S.Diag(Call->getBeginLoc(), diag::err_opencl_requires_extension)
-<< 1 << Call->getDirectCallee() << "cl_khr_subgroups";
+  if (!S.getOpenCLOptions().isSupported("cl_khr_subgroups", S.getLangOpts()) &&
+  !S.getOpenCLOptions().isSupported("__opencl_c_subgroups",
+S.getLangOpts())) {
+S.Diag(Call->getBeginLoc(), diag::err_opencl_requires_subgroups)
+<< 1 << Call->getDirectCallee();
 return true;
   }
   return false;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10175,6 +10175,9 @@
   "invalid prototype, variadic arguments are not allowed in OpenCL">;
 def err_opencl_requires_extension : Error<
   "use of %select{type|declaration}0 %1 requires %2 support">;
+def err_opencl_requires_subgroups : Error<
+  "use of %select{type|declaration}0 %1 requires support of cl_khr_subgroups 
extension "
+  "or __opencl_c_subgroups OpenCL C 3.0 feature">;
 def ext_opencl_double_without_pragma : Extension<
   "Clang permits use of type 'double' regardless pragma if 'cl_khr_fp64' is"
   " supported">;


Index: clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
===
--- clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -236,12 +236,12 @@
 kernel void foo1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' requires cl_khr_subgroups support}}
+  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' requires support of cl_khr_subgroups extension or __opencl_c_subgroups OpenCL C 3.0 feature}}
 }
 
 kernel void bar1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error {{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires cl_khr_subgroups support}}
+  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error {{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires support of cl_khr_subgroups extension or __opencl_c_subgroups OpenCL C 3.0 feature}}
 }
 #endif // i

[PATCH] D118999: [OpenCL] Adjust diagnostic for subgroup support.

2022-02-04 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

It seems hard to find a direct mention in the spec, but in the API spec:

//CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS: Is CL_TRUE if this device 
supports independent forward progress of sub-groups, CL_FALSE otherwise. This 
query must return CL_TRUE for devices that support the cl_khr_subgroups 
extension, and must return CL_FALSE for devices that do not support subgroups.//


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118999/new/

https://reviews.llvm.org/D118999

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118605: [OpenCL] Add support of language builtins for OpenCL C 3.0

2022-02-07 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 406434.
azabaznov added a comment.

Check only against specific language option, remove unused LanguageIDs


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118605/new/

https://reviews.llvm.org/D118605

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/Builtins.h
  clang/lib/Basic/Builtins.cpp
  clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
  clang/test/CodeGenOpenCL/pipe_types.cl
  clang/test/CodeGenOpenCL/to_addr_builtin.cl
  clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
  clang/test/SemaOpenCL/clang-builtin-version.cl
  clang/test/SemaOpenCL/to_addr_builtin.cl

Index: clang/test/SemaOpenCL/to_addr_builtin.cl
===
--- clang/test/SemaOpenCL/to_addr_builtin.cl
+++ clang/test/SemaOpenCL/to_addr_builtin.cl
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -verify -fsyntax-only %s
 // RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL2.0 %s
+// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL3.0 -cl-ext=-all %s
+// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL3.0 %s
 
 void test(void) {
   global int *glob;
@@ -11,7 +13,7 @@
   const_int_ty *con_typedef;
 
   glob = to_global(glob, loc);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_global' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
@@ -20,28 +22,28 @@
 
   int x;
   glob = to_global(x);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument x to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument con to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con_typedef);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument con_typedef to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   loc = to_global(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
 #else
   // expected-error@-4{{assigning '__global int *' to '__local int *__private' changes address space of pointer}}
@@ -49,7 +51,7 @@
 #endif
 
   loc = to_private(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_private' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
 #else
@@ -58,17 +60,17 @@
 #endif
 
   loc = to_local(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_local' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
   // expected-note@-4{{did you mean 'to_global'}}
-  // expected-note@13{{'to_global' declared here}}
+  // expected-note@15{{'to_global' declared here}}
 #else
   // expected-warning@-7{{passing non-generic address space pointer to to_local may cause dynamic conversion affecting performance}}
 #endif
 
   priv = to_global(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warni

[PATCH] D118605: [OpenCL] Add support of language builtins for OpenCL C 3.0

2022-02-07 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov marked 4 inline comments as done.
azabaznov added inline comments.



Comment at: clang/lib/Basic/Builtins.cpp:79
+  bool OclBlocksUnsupported =
+  (LangOpts.getOpenCLCompatibleVersion() < 200 || !LangOpts.Blocks) &&
+  (BuiltinInfo.Langs & OCL_BLOCKS);

This check is needed as //-cl-std=CL1.2// can be used together with 
//-fblocks//. But in 3.0 block support requires //__opencl_c_device_enqueue// 
feature.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118605/new/

https://reviews.llvm.org/D118605

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118605: [OpenCL] Add support of language builtins for OpenCL C 3.0

2022-02-09 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

@Anastasia @svenvh ping. Just a kind reminder.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118605/new/

https://reviews.llvm.org/D118605

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118605: [OpenCL] Add support of language builtins for OpenCL C 3.0

2022-02-11 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 407823.
azabaznov added a comment.

Rename language mode for device side enqueue builtins; add the comment that 
device side enqueue builtins are not supported until OpenCL 2.0.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118605/new/

https://reviews.llvm.org/D118605

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/Builtins.h
  clang/lib/Basic/Builtins.cpp
  clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
  clang/test/CodeGenOpenCL/pipe_types.cl
  clang/test/CodeGenOpenCL/to_addr_builtin.cl
  clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
  clang/test/SemaOpenCL/clang-builtin-version.cl
  clang/test/SemaOpenCL/to_addr_builtin.cl

Index: clang/test/SemaOpenCL/to_addr_builtin.cl
===
--- clang/test/SemaOpenCL/to_addr_builtin.cl
+++ clang/test/SemaOpenCL/to_addr_builtin.cl
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -verify -fsyntax-only %s
 // RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL2.0 %s
+// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL3.0 -cl-ext=-all %s
+// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL3.0 %s
 
 void test(void) {
   global int *glob;
@@ -11,7 +13,7 @@
   const_int_ty *con_typedef;
 
   glob = to_global(glob, loc);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_global' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
@@ -20,28 +22,28 @@
 
   int x;
   glob = to_global(x);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument x to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument con to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con_typedef);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument con_typedef to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   loc = to_global(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
 #else
   // expected-error@-4{{assigning '__global int *' to '__local int *__private' changes address space of pointer}}
@@ -49,7 +51,7 @@
 #endif
 
   loc = to_private(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_private' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
 #else
@@ -58,17 +60,17 @@
 #endif
 
   loc = to_local(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_local' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
   // expected-note@-4{{did you mean 'to_global'}}
-  // expected-note@13{{'to_global' declared here}}
+  // expected-note@15{{'to_global' declared here}}
 #else
   // expected-warning@-7{{passing non-generic address space pointer to to_local may cause dynamic conversion affecting performance}}
 #endif
 
   priv = to_global(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_

[PATCH] D118605: [OpenCL] Add support of language builtins for OpenCL C 3.0

2022-02-11 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

> There are tests checking for this (e.g. clang/test/Frontend/opencl.cl), so we 
> need this check to preserve the existing behavior indeed.

Thanks. The other test is `SemaOpenCL/clang-builtin-version.cl`.

> But it might be worth asking someone outside of the OpenCL community whether 
> it's desirable to use the LanguageID enum in this way.

I personally think this looks good now, for OpenCL in particularly, as it 
became version-agnostic (except for DSE). But we still are querying language 
options only, and we expect language options for generic AS, pipes and DSE to 
be immutable at this point.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118605/new/

https://reviews.llvm.org/D118605

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118605: [OpenCL] Add support of language builtins for OpenCL C 3.0

2022-02-11 Thread Anton Zabaznov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbee4bd70f769: [OpenCL] Add support of language builtins for 
OpenCL C 3.0 (authored by azabaznov).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118605/new/

https://reviews.llvm.org/D118605

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/Builtins.h
  clang/lib/Basic/Builtins.cpp
  clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
  clang/test/CodeGenOpenCL/pipe_types.cl
  clang/test/CodeGenOpenCL/to_addr_builtin.cl
  clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
  clang/test/SemaOpenCL/clang-builtin-version.cl
  clang/test/SemaOpenCL/to_addr_builtin.cl

Index: clang/test/SemaOpenCL/to_addr_builtin.cl
===
--- clang/test/SemaOpenCL/to_addr_builtin.cl
+++ clang/test/SemaOpenCL/to_addr_builtin.cl
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -verify -fsyntax-only %s
 // RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL2.0 %s
+// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL3.0 -cl-ext=-all %s
+// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL3.0 %s
 
 void test(void) {
   global int *glob;
@@ -11,7 +13,7 @@
   const_int_ty *con_typedef;
 
   glob = to_global(glob, loc);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_global' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
@@ -20,28 +22,28 @@
 
   int x;
   glob = to_global(x);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument x to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument con to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con_typedef);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument con_typedef to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   loc = to_global(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
 #else
   // expected-error@-4{{assigning '__global int *' to '__local int *__private' changes address space of pointer}}
@@ -49,7 +51,7 @@
 #endif
 
   loc = to_private(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_private' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
 #else
@@ -58,17 +60,17 @@
 #endif
 
   loc = to_local(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_local' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
   // expected-note@-4{{did you mean 'to_global'}}
-  // expected-note@13{{'to_global' declared here}}
+  // expected-note@15{{'to_global' declared here}}
 #else
   // expected-warning@-7{{passing non-generic address space pointer to to_local may cause dynamic conversion affecting performance}}
 #endif
 
   priv = to_global(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_

[PATCH] D118999: [OpenCL] Adjust diagnostic for subgroup support.

2022-02-11 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 407856.
azabaznov added a comment.

Use existing diagnostics; add the comment that device can support extension but 
not the feature. Will follow up if we need explicit mention in the language 
spec.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118999/new/

https://reviews.llvm.org/D118999

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaOpenCL/cl20-device-side-enqueue.cl


Index: clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
===
--- clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS=
-// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS= -cl-ext=-cl_khr_subgroups
+// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS= 
-cl-ext=-cl_khr_subgroups,-__opencl_c_subgroups
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"
@@ -241,12 +241,12 @@
 kernel void foo1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // 
expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' 
requires cl_khr_subgroups support}}
+  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // 
expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' 
requires cl_khr_subgroups or __opencl_c_subgroups support}}
 }
 
 kernel void bar1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error 
{{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires 
cl_khr_subgroups support}}
+  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error 
{{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires 
cl_khr_subgroups or __opencl_c_subgroups support}}
 }
 #endif // ifdef cl_khr_subgroups
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1042,9 +1042,15 @@
 }
 
 static bool checkOpenCLSubgroupExt(Sema &S, CallExpr *Call) {
-  if (!S.getOpenCLOptions().isSupported("cl_khr_subgroups", S.getLangOpts())) {
+  // OpenCL device can support extension but not the feature as extension
+  // requires subgroup independent forward progress, but subgroup independent
+  // forward progress is optional in OpenCL C 3.0 __opencl_c_subgroups feature.
+  if (!S.getOpenCLOptions().isSupported("cl_khr_subgroups", S.getLangOpts()) &&
+  !S.getOpenCLOptions().isSupported("__opencl_c_subgroups",
+S.getLangOpts())) {
 S.Diag(Call->getBeginLoc(), diag::err_opencl_requires_extension)
-<< 1 << Call->getDirectCallee() << "cl_khr_subgroups";
+<< 1 << Call->getDirectCallee()
+<< "cl_khr_subgroups or __opencl_c_subgroups";
 return true;
   }
   return false;


Index: clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
===
--- clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS=
-// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS= -cl-ext=-cl_khr_subgroups
+// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS= -cl-ext=-cl_khr_subgroups,-__opencl_c_subgroups
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -t

[PATCH] D118999: [OpenCL] Adjust diagnostic for subgroup support.

2022-02-11 Thread Anton Zabaznov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbfb1a33bec7c: [OpenCL] Adjust diagnostic for subgroup 
support. (authored by azabaznov).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118999/new/

https://reviews.llvm.org/D118999

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaOpenCL/cl20-device-side-enqueue.cl


Index: clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
===
--- clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS=
-// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS= -cl-ext=-cl_khr_subgroups
+// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS= 
-cl-ext=-cl_khr_subgroups,-__opencl_c_subgroups
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"
@@ -241,12 +241,12 @@
 kernel void foo1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // 
expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' 
requires cl_khr_subgroups support}}
+  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // 
expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' 
requires cl_khr_subgroups or __opencl_c_subgroups support}}
 }
 
 kernel void bar1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error 
{{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires 
cl_khr_subgroups support}}
+  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error 
{{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires 
cl_khr_subgroups or __opencl_c_subgroups support}}
 }
 #endif // ifdef cl_khr_subgroups
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1042,9 +1042,15 @@
 }
 
 static bool checkOpenCLSubgroupExt(Sema &S, CallExpr *Call) {
-  if (!S.getOpenCLOptions().isSupported("cl_khr_subgroups", S.getLangOpts())) {
+  // OpenCL device can support extension but not the feature as extension
+  // requires subgroup independent forward progress, but subgroup independent
+  // forward progress is optional in OpenCL C 3.0 __opencl_c_subgroups feature.
+  if (!S.getOpenCLOptions().isSupported("cl_khr_subgroups", S.getLangOpts()) &&
+  !S.getOpenCLOptions().isSupported("__opencl_c_subgroups",
+S.getLangOpts())) {
 S.Diag(Call->getBeginLoc(), diag::err_opencl_requires_extension)
-<< 1 << Call->getDirectCallee() << "cl_khr_subgroups";
+<< 1 << Call->getDirectCallee()
+<< "cl_khr_subgroups or __opencl_c_subgroups";
 return true;
   }
   return false;


Index: clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
===
--- clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS=
-// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS= -cl-ext=-cl_khr_subgroups
+// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS= -cl-ext=-cl_khr_subgroups,-__opencl_c_subgroups
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-o

[PATCH] D119719: [Docs][OpenCL] Update OpenCL 3.0 status on release 14

2022-02-15 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/docs/OpenCLSupport.rst:395
++--+-+-+--++
+| Feature optionality  | Blocks and Device-side kernel enqueue 
including builtin functions | :part:`worked on`| 
https://reviews.llvm.org/D115640, https://reviews.llvm.org/D118605  
   |
++--+-+-+--++

These two patches are merged. So can blocks and DSE be considered as done?



Comment at: clang/docs/OpenCLSupport.rst:407
++--+-+-+--++
+| New functionality| Subgroup functions
| :part:`worked on`| https://reviews.llvm.org/D105858, 
https://reviews.llvm.org/D118999
 |
++--+-+-+--++

Can this be considered as done as well? These patches were merged as well.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119719/new/

https://reviews.llvm.org/D119719

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119719: [Docs][OpenCL] Update OpenCL 3.0 status

2022-02-16 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov accepted this revision.
azabaznov added a comment.

LGTM. Thanks!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119719/new/

https://reviews.llvm.org/D119719

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92277: [OpenCL] Refactor of targets OpenCL option settings

2020-12-13 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/include/clang/Basic/OpenCLOptions.h:22
 
-/// OpenCL supported extensions and optional core features
-class OpenCLOptions {
-  struct Info {
-bool Supported; // Is this option supported
-bool Enabled;   // Is this option enabled
-unsigned Avail; // Option starts to be available in this OpenCL version
-unsigned Core;  // Option becomes (optional) core feature in this OpenCL
-// version
-Info(bool S = false, bool E = false, unsigned A = 100, unsigned C = ~0U)
-  :Supported(S), Enabled(E), Avail(A), Core(C){}
-  };
-  llvm::StringMap OptMap;
-public:
-  /// Check if \c Ext is a recognized OpenCL extension.
-  ///
-  /// \param Ext - Extension to look up.
-  /// \returns \c true if \c Ext is known, \c false otherwise.
-  bool isKnown(llvm::StringRef Ext) const {
-return OptMap.find(Ext) != OptMap.end();
-  }
+enum OpenCLVersionID : unsigned int {
+  OCL_C_10 = 0x1,

Anastasia wrote:
> Let's add a comment to document this new enum.
I'm going to change comments all over the place in the next patch. Thanks!



Comment at: clang/include/clang/Basic/OpenCLOptions.h:36
+// OpenCL C version mask
+class OpenCLVersionEncoderHelper {
+private:

Anastasia wrote:
> Looking at the uses, it might be better to just have a helper function that 
> takes `OpenCLVersion` and `LangOpts` instead of introducing a class that is 
> only used as temporary.
Ok, that is reasonable. Will change.



Comment at: clang/include/clang/Basic/TargetInfo.h:1442
+  virtual void supportAllOpenCLOpts(bool V = true) {
+#define OPENCLEXTNAME(Ext) getTargetOpts().OpenCLFeaturesMap[#Ext] = V;
+#include "clang/Basic/OpenCLExtensions.def"

Anastasia wrote:
> Btw here you could just iterate over the elements in the map? This could be 
> faster than multiple independent look ups into the map. But mainly I think it 
> makes the flow a bit cleaneras it indicated that you only set elements and 
> not add them...
> Btw here you could just iterate over the elements in the map

Map is empty at this point. `::supportAllOpenCLOpts` adds all elements which 
are declared in `OpenCLExtensions.def` into the map.



Comment at: clang/lib/Basic/OpenCLOptions.cpp:116
+if (F.getValue().IsCoreIn(Opts))
+  support(F.getKey());
+}

Anastasia wrote:
> Btw what if the target doesn't support the feature? Do you think we could 
> provide an error?
I think that if a feature is //core// than a target //must// support it, do I 
miss something?

However, there is a place for such diagnostics for non-core features already: 
something similar to `TargetInfo::handleTargetFeatures(std::vector 
&Features, DiagnosticsEngine &Diags)` could be used



Comment at: clang/lib/Basic/Targets.cpp:725
+if ((It != OpenCLFeaturesMap.end() && It->getValue()) ||
+OpenCLOptionInfo(AvailVer, CoreVersions, OptionalVersions)
+.IsCoreIn(Opts))

Anastasia wrote:
> I think we should find different place for those now.
> 
> Ideally, we should iterate though the map in `OpenCLOptions` and set the 
> define for the supported ones.
> 
> I suggest we move this into `clang::InitializePreprocessor` which means 
> `Preprocessor` might need a reference to `OpenCLOptions` which is the right 
> thing to do because it needs to know the features that require the macro, the 
> same as for `LangOpts`. This means we will need to change the initialization 
> time of `OpenCLOptions` member in Sema or potentially even reparent it 
> elsewhere... perhaps to `CompilerInstance` where `LangOpts` and `TargetInfo` 
> seems to be created already?
> I suggest we move this into clang::InitializePreprocessor which means

I think I'm going to introduce `InitializeOpenCLFeatureTestMacros(TargetInfo, 
LangOptions)` in `InitPreprocessor.cpp`.

> This means we will need to change the initialization time of OpenCLOptions 
> member in Sema or potentially even reparent it elsewhere... perhaps to 
> CompilerInstance where LangOpts and TargetInfo seems to be created already

This seems too invasive for me since `CompilerInstance` is a different purpose 
class; and it already holds `Sema` and `TargetInfo`. `OpenCLOptions` should 
mainly be used for parsing, so I would like to suggest avoiding using it 
elsewhere. Furthermore, with the proposed flow `OpenCLOptions.h` can be removed 
later  and some simple helpers can be used to check the availability of 
features/extensions.

However, I see your point: we have two identical pieces of code in 
`TargetInfo::getOpenCLFeatureDefines` and `OpenCLOptions::addSupport`. I think 
I'll try to get rid of this duplication by transferring setting of core 
features into `TargetInfo::adjust` which seems pretty right thing to do. What 
do you think?



Comment at: clang/test/Misc/r600.languageOptsOpenCL.cl:26

[PATCH] D89869: [OpenCL] Define OpenCL feature macros for all versions

2020-11-06 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

> I guess targets like SPIR will be supporting all features by default?

It sounds confusing for me: can you please elaborate about why does SPIR-V 
target should support all features/extension by default? If we are compiling 
OpenCL C 3.0 with optional functionality we most likely want to get an error in 
FE level if some functionality is not supported by the target, but not in BE 
after SPIR-V translation.




Comment at: clang/include/clang/Basic/OpenCLExtensions.def:110
+OPENCLFEAT_INTERNAL(__opencl_c_generic_address_space, 200, ~0U)
+OPENCLFEAT_INTERNAL(__opencl_c_work_group_collective_functions, 200, ~0U)
+OPENCLFEAT_INTERNAL(__opencl_c_atomic_order_acq_rel, 200, ~0U)

Anastasia wrote:
> Does this need to be in the frontend?
I can remove features which affect only header from this file. But in this case 
we need to extend '-cl-ext' to register unknown features/extensions 
(http://lists.llvm.org/pipermail/cfe-dev/2020-October/066932.html). I think 
this option functionality extending should be done in a separate commit, so we 
can keep this kind of features here at least for now. What do you think?



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:121
+OPENCLFEAT_INTERNAL(__opencl_c_fp64, 120, ~0U)
+OPENCLFEAT_INTERNAL(__opencl_c_int64, 100, ~0U)
+OPENCLFEAT_INTERNAL(__opencl_c_images, 100, ~0U)

Anastasia wrote:
> if we are not going to change clang to make int64 conditional I would suggest 
> we don't add this here for now.
Yes, that sounds reasonable to be.



Comment at: clang/include/clang/Basic/OpenCLOptions.h:105
 }
 OptMap[Ext].Supported = V;
   }

Anastasia wrote:
> I guess we need to make sure that targets can't conditionally support 
> features in OpenCL 2.0 or earlier standards.
This can be done by adding a new method 
//TargetInfo::setSupportedOpenCL30Features()// which can be called in 
//::adjust//, does this make sense? I believe now current  options setting 
(//TargetInfo::setSupportedOpenCLOpts()//) knows nothing about OpenCL version 
which.



Comment at: clang/lib/Frontend/CompilerInstance.cpp:950
+  if (getLangOpts().OpenCL)
+getTarget().getSupportedOpenCLOpts().adjustFeatures(getLangOpts());
+

Anastasia wrote:
> Would it be possible to move this into `getTarget().adjust(getLangOpts())` 
> just below. There is a FIXME that explains that we should be doing such 
> adjustment differently but we haven't solved it with time so let's keep the 
> flow as is for now. 
Yeah, this can be moved there. Btw a lot of OpenCL C 3.0 options setting will 
take place in //::adjust//...



Comment at: clang/test/Preprocessor/opencl-feature-extension-simult.cl:15
+
+// RUN: %clang_cc1 %s -E -cl-std=CL3.0 -cl-ext=-all__opencl_c_fp64
+// RUN: %clang_cc1 %s -E -cl-std=CL3.0 -cl-ext=+__opencl_c_fp64

Anastasia wrote:
> Is this a typo?
> 
> `all__opencl_c_fp64`
Ah, yeah, thanks, Will definitely change that.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89869/new/

https://reviews.llvm.org/D89869

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89869: [OpenCL] Define OpenCL feature macros for all versions

2020-11-11 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 304493.
azabaznov added a comment.

Addressed all concerns except replacing //__opencl_c_int64 //definition into 
header. The reason for this as follows: this macro should be predefined 
regardless if clang includes default header or not.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89869/new/

https://reviews.llvm.org/D89869

Files:
  clang/include/clang/Basic/OpenCLExtensions.def
  clang/include/clang/Basic/OpenCLOptions.h
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Headers/opencl-c-base.h
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/SemaOpenCL/opencl-feature-extension-simult.cl
  clang/test/SemaOpenCL/opencl-features.cl

Index: clang/test/SemaOpenCL/opencl-features.cl
===
--- /dev/null
+++ clang/test/SemaOpenCL/opencl-features.cl
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL2.0 \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CL20
+// RUN: %clang_cc1 -triple amdgcn-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=CL20
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CLC++ \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL20
+// RUN: %clang_cc1 -triple r600-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL2.0 \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL20
+// RUN: %clang_cc1 -triple r600-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=CL20
+// RUN: %clang_cc1 -triple r600-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CLC++ \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL20
+// RUN: %clang_cc1 -triple nvptx-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL2.0 \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL20
+// RUN: %clang_cc1 -triple nvptx-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=CL20
+// RUN: %clang_cc1 -triple nvptx-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CLC++ \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL20
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL2.0 \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL20
+// RUN: %clang_cc1 -triple x86_64-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=CL20
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CLC++ \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL20
+// RUN: %clang_cc1 -triple spir-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL2.0 \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL20
+// RUN: %clang_cc1 -triple r600-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=CL20
+// RUN: %clang_cc1 -triple spir-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CLC++ \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL20
+
+// x86_64 and spir support all features by default
+
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL3.0 \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL30
+// RUN: %clang_cc1 -triple r600-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL3.0 \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL30
+// RUN: %clang_cc1 -triple nvptx-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL3.0 \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL30
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL3.0 -cl-ext=-all \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL30
+// RUN: %clang_cc1 -triple spir-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL3.0 -cl-ext=-all \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL30
+
+// CL20: #define __opencl_c_atomic_order_acq_rel 1
+// CL20: #define __opencl_c_atomic_order_seq_cst 1
+// CL20: #define __opencl_c_atomic_scope_all_devices 1
+// CL20: #define __opencl_c_atomic_scope_device 1
+

[PATCH] D89869: [OpenCL] Define OpenCL feature macros for all versions

2020-11-11 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

> What did you think in mind regarding activation of features for SPIR?

I don't see any difference between extensions and features in that case (at 
least for now), so in the latest patch x86 and spir targets will define all the 
features.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89869/new/

https://reviews.llvm.org/D89869

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89869: [OpenCL] Define OpenCL feature macros for all versions

2020-11-17 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:100
+// OpenCL features
+OPENCLFEAT_INTERNAL(__opencl_c_pipes, 200, ~0U)
+OPENCLFEAT_INTERNAL(__opencl_c_generic_address_space, 200, ~0U)

Anastasia wrote:
> Btw I guess we don't need the last parameter for the features since it's 
> always 0?
This need to be restructured at all, now I just wanted to be consistent. I 
think there was wrong interpretation of "core extension" concept. //Core 
//means nothing more than it was just promoted to core specification, not 
supported by default starting from specific OpenCL version. Am I missing 
something in the spec? However, I'm not sure if we need to reimplement this to 
maintain backward compatibility... Anyway, I'll try to remove it from features.



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:109
+OPENCLFEAT_INTERNAL(__opencl_c_program_scope_global_variables, 200, ~0U)
+OPENCLFEAT_INTERNAL(__opencl_c_fp64, 120, ~0U)
+OPENCLFEAT_INTERNAL(__opencl_c_images, 100, ~0U)

Anastasia wrote:
> I am thinking maybe we could add an extra parameter where we can specify the 
> extension it is aliased to:
> 
> ```
> OPENCLFEAT_INTERNAL(__opencl_c_fp64, 120, ~0U, cl_khr_fp64)
> ```
> 
> Then it makes clearer which features correspond to which extensions and you 
> can populate `EquivalentFeaturesExtensions` from this field? Moreover, you 
> can then even make a map of references to `OpenCLOptions::Info` so you don't 
> need to look them up from the name every time.
> 
> 
> The drawback is that we need an extra parameter that is mainly empty... 
> however we could recycle the last parameter that is always 0 right now.
> 
> OPENCLFEAT_INTERNAL(__opencl_c_fp64, 120, ~0U, cl_khr_fp64)
Yes, that's sound reasonable to me

> The drawback is that we need an extra parameter that is mainly empty
I don't think we need to keep it `OpenCLOptions::Info`, we can always this from 
`OpenCLOptions`. 



Comment at: clang/include/clang/Basic/OpenCLOptions.h:37
+  // OpenCL Version
+  unsigned CLVer = 120;
+  bool IsOpenCLCPlusPlus = false;

Anastasia wrote:
> Ok, I see why you are adding this field but I am not very happy with it. 
> However, if you prefer to keep it I suggest to add a comment otherwise it is 
> mislediang because ideally in Clang we should be using versions from the 
> LangOpts everywhere. Alternatively we could consider a helper function to 
> calculate the version although it doesn't eliminate the need to the comment.
> However, if you prefer to keep it I suggest to add a comment otherwise it is 
> mislediang because ideally in Clang we should be using versions from the 
> LangOpts everywhere

The reason for this is that `LangOptions` is not always available for proper 
settings. So this just needed internally. Also, we could add 
`TargetInfo::setOpenCLOptions(const LangOptions &Opts)` where we can set all 
extensions/features in one step (invoke `::setSupportedOpenCLOpts` and 
`::setOpenCLExtensionOpts`) to make sure `OpenCLOptions` will get proper OpenCL 
version. What do you think of that?



Comment at: clang/include/clang/Basic/OpenCLOptions.h:42
+
+  // Note that __opencl_c_subgroups and cl_khr_subgroups are not equivalent
+  // because extension requires sub-group independent forward progress

Anastasia wrote:
> I feel I missed that. Can you explain why it is not the same. Any spec 
> reference would be help.
Ah, yeah. This one is confusing.

You can check [[ 
https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_API.html#platform-querying-devices|
 4.2. Querying Devices ]], the CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS 
entry:

//This query must return CL_TRUE for devices that support the cl_khr_subgroups 
extension, and must return CL_FALSE for devices that do not support subgroup//.

It was missing before OpenCL C 2.1 and subgroup independent forward progress is 
optional in 2.1 and 3.0. Agree that spec is not clear here though. This is just 
the case when feature describes more functionality than the extension.



Comment at: clang/include/clang/Basic/OpenCLOptions.h:51
+  // check specific version of feature)
+  void supportFeatureForPreOCL30(StringRef Feat, bool On = true) {
+assert(CLVer < 300 && "Can'be called for OpenCL C higher 3.0");

Anastasia wrote:
> I find the name of this function very confusing but I can't think of any 
> better one. Also the flow is becoming harder to understand to be honest. This 
> function is not as straight forward as `support` because it might not 
> actually do what is expected from it. I wonder if the name with something 
> like `adjust` would be more appropriate. At the same time `adjustFeatures` is 
> the only place where we need to check for the version. Perhaps you can just 
> do the language version check straight in `adjustFeatu

[PATCH] D89869: [OpenCL] Define OpenCL feature macros for all versions

2020-11-18 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/include/clang/Basic/OpenCLOptions.h:51
+  // check specific version of feature)
+  void supportFeatureForPreOCL30(StringRef Feat, bool On = true) {
+assert(CLVer < 300 && "Can'be called for OpenCL C higher 3.0");

Anastasia wrote:
> azabaznov wrote:
> > Anastasia wrote:
> > > I find the name of this function very confusing but I can't think of any 
> > > better one. Also the flow is becoming harder to understand to be honest. 
> > > This function is not as straight forward as `support` because it might 
> > > not actually do what is expected from it. I wonder if the name with 
> > > something like `adjust` would be more appropriate. At the same time 
> > > `adjustFeatures` is the only place where we need to check for the 
> > > version. Perhaps you can just do the language version check straight in 
> > > `adjustFeatures`?
> > > 
> > > Overall, let's just get clear about the flow of setting the features and 
> > > extensions. If in `adjustFeatures` we set default features supported in a 
> > > certain language version then targets can set the other features. Now 
> > > let's examine what should happen with the features and extensions on the 
> > > following use cases:
> > > - Do we always set the equivalent extension when the feature is being set 
> > > by the target?
> > > - Do we always set the equivalent feature when the extension is being set 
> > > by the target?
> > > - What happens when equivalent features and extensions are set but to 
> > > different values?
> > > - What if targets set core feature/extension to unsupported?
> > > - How does `-cl-ext` modify core features/extensions and equivalent 
> > > features+extensions?
> > > 
> > > I am a bit worried about the fact that we have different items for the 
> > > same optional functionality in `OpenCLOptions` as it might be a nightmare 
> > > to keep them consistent. We can however also choose a path of not keeping 
> > > them consistent in the common code and rely on targets to set them up 
> > > correctly.
> > > 
> > > Initially, when we discussed adding feature macros to earlier standards I 
> > > was thinking of simplifying the design. For example instead of checking 
> > > for extension macros and feature macros in the header when declaring 
> > > certain functions we could only check for one of those. The question 
> > > whether we can really achieve the simplifications and at what cost.
> > Ok.
> > 
> > Now I think that defining features for pre-OpenCL C 3.0 if they have 
> > equivalent extension indeed brings up some complexities. The check for the 
> > support of features in header will still look like follows:
> > 
> > ```
> > #if defined(cl_khr_fp64) || defined(__opencl_c_fp64)
> > ...
> > #endif
> > ```
> > 
> > so there is no need to add a feature macro for pre-OpenCL C 3.0 if there is 
> > a same extension to check. Are you agree with that?
> > 
> > However, I still see a reason for defining  equivalent extension for OpenCL 
> > C 3.0 if feature is supported (backward compatibility with earlier OpenCL C 
> > kernels).
> > 
> > > Overall, let's just get clear about the flow of setting the features and 
> > > extensions
> > IMO the main thing which we need to try to follow here is that features are 
> > stronger concept than extensions in OpenCL C 3.0. The reason for this is 
> > that API won't report extension support if the feature is not supported ([[ 
> > https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_API.html#_3d_image_writes
> >  | 3d image writes example]]. To be clear, if users need to support 
> > functionality in OpenCL C 3.0 they should use features, for earlier 
> > versions they should use extensions.
> > 
> > Answering your questions:
> > 
> > > Do we always set the equivalent extension when the feature is being set 
> > > by the target?
> > I think we should do it for OpenCL C 3.0 only to maintain backward 
> > compatibility with OpenCL C 1.2 applications.
> > 
> > > Do we always set the equivalent feature when the extension is being set 
> > > by the target
> > I think we shouldn't set equivalent feature for pre-OpenCL C 3.0 since 
> > there is no need in that. This brings up some complexities, and we can 
> > check an extension presence.
> > 
> > > What happens when equivalent features and extensions are set but to 
> > > different values
> > We need to avoid that case for OpenCL C 3.0 since implementation could not 
> > report extension support if equivalent feature is not supported.
> > 
> > > How does -cl-ext modify core features/extensions and equivalent 
> > > features+extensions
> > '-сl-ext' should not affect feature support in pre-OpenCL 3.0. In OpenCL C 
> > 3.0 it's more likely to use features instead of extensions since it's a 
> > stronger concept; and equivalent feature+extension will be supported 
> > simultaneously if feature is turned on.
> > 
> > And a question:
> > 
> > > What if targets se

[PATCH] D91531: [RFC][OpenCL] Provide mechanisms for defining extension macros

2020-11-19 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

Yes, in general this approach looks good to me conceptually. I have two 
suggestions:

1. As we discussed, the term //core functionality// should be revisited here. 
There's no clear meaning about that in the spec and I think interpreting it as 
//supported by default// is a little dangerous. So //core// (AFAIK) means that 
it was just promoted to a core specification thus is still remains optional by 
targets.
2. Sort of a implementation suggestion. I understand that double-scored 
identifiers are reserved for any use, but still, can defining such macro as 
`__undef_cl_khr_depth_images ` be avoided? We could use `Preproceccor` class 
for the things that you are proposing to do. I was trying to do something 
similar when implementing features and I tried something like 
(`Preprocessor::appendDefMacroDirective` already exists):



  UndefMacroDirective *Preprocessor::appendUndefMacroDirective(IdentifierInfo 
*II,
 SourceLocation Loc) {
 if (!II->hasMacroDefinition())
   return nullptr;
 UndefMacroDirective *UD = AllocateUndefMacroDirective(Loc);
 appendMacroDirective(II, UD);
 return UD;
  }

I tried to handle some special pragma in this way and it worked. So maybe this 
can be reused without binding to any specific `SourceLocation`? But maybe there 
is an other strong concern why `Preprocessor::appendUndefMacroDirective` still 
doesn't exist...


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91531/new/

https://reviews.llvm.org/D91531

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88300: [OpenCL] Initial patch for OpenCL C 3.0 support

2020-09-30 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

In D88300#2302796 , @svenvh wrote:

> LGTM!  I'd suggest waiting a bit before committing this though, to give 
> people time to catch up on the RFC.

Thanks! Sure, I'm agree with that, let's wait.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88300/new/

https://reviews.llvm.org/D88300

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88300: [OpenCL] Initial patch for OpenCL C 3.0 support

2020-10-09 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

Anastasia, Sven, thanks for the review! Anastasia, it seems that I don't have 
write access yet. Would you mind landing this change on behalf of me? Thanks!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88300/new/

https://reviews.llvm.org/D88300

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89143: [OpenCL][Docs] Improved description of the supported language functionality.

2020-10-14 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov accepted this revision.
azabaznov added a comment.
This revision is now accepted and ready to land.

Looks good to me, thanks for the note.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89143/new/

https://reviews.llvm.org/D89143

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89372: [OpenCL] Remove unused extensions

2020-10-14 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov requested changes to this revision.
azabaznov added inline comments.
This revision now requires changes to proceed.



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:74
 OPENCLEXT_INTERNAL(cl_khr_mipmap_image_writes, 200, ~0U)
-OPENCLEXT_INTERNAL(cl_khr_srgb_image_writes, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_subgroups, 200, ~0U)

cl_khr_srgb_image_writes - Extension allowing writes to sRGB images from a 
kernel. This extension enables write_imagef built-in function as it described 
[[ 
https://www.khronos.org/registry/OpenCL/specs/2.2/html/OpenCL_Ext.html#cl_khr_srgb_image_writes
 | here]]. So I think we shouldn't remove it. Do I miss something?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89372/new/

https://reviews.llvm.org/D89372

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89372: [OpenCL] Remove unused extensions

2020-10-14 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:74
 OPENCLEXT_INTERNAL(cl_khr_mipmap_image_writes, 200, ~0U)
-OPENCLEXT_INTERNAL(cl_khr_srgb_image_writes, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_subgroups, 200, ~0U)

mantognini wrote:
> azabaznov wrote:
> > cl_khr_srgb_image_writes - Extension allowing writes to sRGB images from a 
> > kernel. This extension enables write_imagef built-in function as it 
> > described [[ 
> > https://www.khronos.org/registry/OpenCL/specs/2.2/html/OpenCL_Ext.html#cl_khr_srgb_image_writes
> >  | here]]. So I think we shouldn't remove it. Do I miss something?
> On second reading, this one is slightly ambiguous. On the language side, the 
> extension doesn't add an overload; it only specifies that existing overload 
> can be used with a different kind of image. On the API side, it does extend 
> the set of features. But at the same time if the extended API is not 
> supported, it's not possible to create an image in the first place and 
> therefore impossible to call write_imagef. So I question the usefulness of 
> such macro on the device side. Does this argument convince you it should be 
> removed?
> it's not possible to create an image in the first place and therefore 
> impossible
Not quite that right. Referring to [[ 
https://www.khronos.org/registry/OpenCL/specs/2.2/html/OpenCL_C.html#conversion-rules-for-srgba-and-sbgra-images
 | this ]]:

read_imagef built-in functions for OpenCL C 2.0 devices do implicit conversions 
to RGB for sRGB images. However, implicit conversion from sRGB to RGB is done 
on write_imagef only if corresponding extension is supported. Otherwise, 
explicit conversions inside a kernel may be required.

I'm agree that this one is kind of confusing and requires some extra 
investigation. But I think now we should remove only those extensions which are 
only API related for sure.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89372/new/

https://reviews.llvm.org/D89372

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D91531: [RFC][OpenCL] Provide mechanisms for defining extension macros

2020-11-23 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

> Perhaps if you give me an example it would help to understand

I was meant that this can potentially be used to undefine macros inside clang 
directly. In this case there will no need to add a lot of conditional 
preprocessor directives in the header, also the existing interface 
(`-cl-ext=-cl_khr_depth_images`) will be preserved. So for example in the 
header there was specified an extension definition. Can undef directive be 
allocated and bound to a specific source location right after extension 
definition if `-cl-ext=-cl_khr_depth_images` was specifed:

  #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ == 
CL_VERSION_2_0) || \
  (__OPENCL_C_VERSION__ >= CL_VERSION_1_2  && defined(__SPIR__) )
  #define cl_khr_depth_images 1
  #endif
  
  // Bind undef directive here

I understand that this sounds tricky, but preserving interface sound reasonable 
for me.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91531/new/

https://reviews.llvm.org/D91531

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D91531: [RFC][OpenCL] Provide mechanisms for defining extension macros

2020-11-23 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

> So if I understand it well you are suggesting to perform a check for every 
> parsed macro definition that would identify whether the macro has a name 
> matching what is provided in -cl-ext=? Then if the name matches it would 
> check whether the macro should be defined or not?

No, sorry for confusing. There is no need to check every parsed macro. For 
example an internal pragma can be used for these purposes (`#pragma OPENCL 
EXTENSION all : undef` in example below). So imagine if we can differentiate 
header-only extensions and features and all of them are defined in header. 
After the list of definitions the special pragma is used and is a processed in 
a way that it inserts undef for each macro definition which relates to 
header-only extension/feature and was turned off with the option 
(`-cl-ext=-cl_khr_depth_images`):

  #define cl_khr_depth_images 1
  #define cl_khr_fp64 1
  #define cl_khr_mipmap_image  1
  ...
  #pragma OPENCL EXTENSION all : undef

However, this might be hard to maintain and I'm not sure yet that this is even 
legally to do in current `Preprocessor` design, but this is at least more 
scalable than adding `#if defined(__undef_` for each extension in the end of 
the header.  Nevertheless, that's what I meant about preserving the current 
interface.

Also, I didn't quite get how the proposing hook will allow users to declare own 
extensions outside the codebase. Are you expecting them to use existing 
`-cl-ext` or `-Dcl_khr_depth_images`? In the later case they won't able to use 
`#pragma OPENCL EXTESNION cl_khr_depth_images : enable` (while the 
specification does not describe for which extensions pragma is exactly needed 
or not, but still)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91531/new/

https://reviews.llvm.org/D91531

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92004: [OpenCL] add CL 3.0 optional feature support to opencl-c.h

2020-11-24 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

Hi! Great to see the interest in OpenCL C 3.0!

I'm being working already at a proper feature macros definition to unify both 
clang and header OpenCL C 3.0 related changes, here is the change: 
https://reviews.llvm.org/D89869. So as this patch will be merged then the check 
for supported feature can be done uniformly in all OpenCL versions:

Use:

  #ifdef __opencl_c_pipes

instead of

  #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0 && __OPENCL_C_VERSION__ < CL_VERSION_3_0) || 
(__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && defined(__opencl_c_pipes))

The main concepts are described in RFC thread here: 
https://lists.llvm.org/pipermail/cfe-dev/2020-September/066883.html. Will be 
glad to discuss any technical details and concerns. Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92004/new/

https://reviews.llvm.org/D92004

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89869: [OpenCL] Define OpenCL feature macros for all versions

2020-11-24 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 307436.
azabaznov marked 24 inline comments as done.
azabaznov added a comment.

Addressed almost all technical and cosmetic concerns concerns. Except putting 
reference of `OpenCLOptions` in `Sema` due to const of `TargetInfo`. I think 
I'll think about that later. Also:

1. Added new target hook to define extensions/features macros in one step 
(target settings + option)
2. Define generic address space macro if pipes or device enqueue is supported.
3. Did some minor refactoring of `OpenCLOptions.h` and `OpenCLExtensions.def`.




CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89869/new/

https://reviews.llvm.org/D89869

Files:
  clang/include/clang/Basic/OpenCLExtensions.def
  clang/include/clang/Basic/OpenCLOptions.h
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Headers/opencl-c-base.h
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/SemaOpenCL/opencl-feature-extension-simult.cl
  clang/test/SemaOpenCL/opencl-feature-generic-as-req.cl
  clang/test/SemaOpenCL/opencl-features.cl

Index: clang/test/SemaOpenCL/opencl-features.cl
===
--- /dev/null
+++ clang/test/SemaOpenCL/opencl-features.cl
@@ -0,0 +1,75 @@
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL2.0 \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CL20
+// RUN: %clang_cc1 -triple amdgcn-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=CL20
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CLC++ \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL20
+// RUN: %clang_cc1 -triple r600-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL2.0 \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL20
+// RUN: %clang_cc1 -triple r600-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=CL20
+// RUN: %clang_cc1 -triple r600-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CLC++ \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL20
+// RUN: %clang_cc1 -triple nvptx-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL2.0 \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL20
+// RUN: %clang_cc1 -triple nvptx-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=CL20
+// RUN: %clang_cc1 -triple nvptx-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CLC++ \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL20
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL2.0 \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL20
+// RUN: %clang_cc1 -triple x86_64-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=CL20
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CLC++ \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL20
+// RUN: %clang_cc1 -triple spir-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL2.0 \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL20
+// RUN: %clang_cc1 -triple r600-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=CL20
+// RUN: %clang_cc1 -triple spir-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CLC++ \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL20
+
+// x86_64 and spir support all features by default
+
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL3.0 \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL30
+// RUN: %clang_cc1 -triple r600-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL3.0 \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL30
+// RUN: %clang_cc1 -triple nvptx-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL3.0 \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL30
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -finclude-default-header %s -E -dM -o - -x cl -cl-std=CL3.0 -cl-ext=-all \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=CL30
+// RUN: %clang_cc1 -triple spir-unknown-unknown -

[PATCH] D89869: [OpenCL] Define OpenCL feature macros for all versions

2020-11-29 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

> I didn't want to end up with a big refactoring from this patch but now I 
> start to think that considering the situation it might be unavoidable. :(

Well, it was expected. However, I didn't want to mess this refactoring with 
OpenCL C 3.0 support at first.

I already do have some progress in this direction: 
https://reviews.llvm.org/D92277. We can differentiate between core and optional 
features by the defining them appropriately in `OpenCLExtensions.def`. Note 
that this also removes duplication of `OpenCLOptions` so we can query all 
features/extensions from `TargetInfo` directly. This will also allow 
simplifying `OpenCLOptions` in future


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89869/new/

https://reviews.llvm.org/D89869

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89869: [OpenCL] Define OpenCL feature macros for all versions

2020-10-21 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov created this revision.
azabaznov added reviewers: Anastasia, svenvh.
Herald added subscribers: dexonsmith, jfb.
azabaznov requested review of this revision.

This change relates to OpenCL C 3.0 support. RFC thread: 
https://lists.llvm.org/pipermail/cfe-dev/2020-September/066883.html

The same interface  ('-cl-ext' option) is being used to indicate that feature 
or extension is supported. OpenCL C 3.0 by default doesn't provide any features 
which are core in OpenCL C 2.0.  The idea is to define feature test macros for 
all OpenCL versions and provide simultaneous macro presence if there exist 
equivalent extension.


https://reviews.llvm.org/D89869

Files:
  clang/include/clang/Basic/OpenCLExtensions.def
  clang/include/clang/Basic/OpenCLOptions.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Preprocessor/opencl-feature-extension-simult.cl
  clang/test/Preprocessor/opencl-features.cl

Index: clang/test/Preprocessor/opencl-features.cl
===
--- /dev/null
+++ clang/test/Preprocessor/opencl-features.cl
@@ -0,0 +1,129 @@
+// RUN: %clang_cc1 %s -E -cl-std=CL2.0
+// RUN: %clang_cc1 %s -E -cl-std=CL2.0 -cl-ext=-__opencl_c_device_enqueue,-__opencl_c_pipes,-__opencl_c_read_write_images
+// RUN: %clang_cc1 %s -E -cl-std=CLC++
+// RUN: %clang_cc1 %s -E -cl-std=CL3.0
+
+// expected-no-diagnostics
+
+#ifndef __opencl_c_int64
+  #error Feature __opencl_c_int64 should be defined
+#endif
+
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
+  #ifndef __opencl_c_3d_image_writes
+   #error Feature __opencl_c_3d_image_writes should be defined
+  #endif
+
+  #ifndef __opencl_c_atomic_order_acq_rel
+   #error Feature __opencl_c_atomic_order_acq_rel should be defined
+  #endif
+
+  #ifndef __opencl_c_atomic_order_seq_cst
+   #error Feature __opencl_c_atomic_order_seq_cst should be defined
+  #endif
+
+  #ifndef __opencl_c_atomic_scope_device
+   #error Feature __opencl_c_atomic_scope_device should be defined
+  #endif
+
+  #ifndef __opencl_c_atomic_scope_all_devices
+   #error Feature __opencl_c_atomic_scope_all_devices should be defined
+  #endif
+
+  #ifndef __opencl_c_device_enqueue
+ #error Feature __opencl_c_device_enqueue should be defined
+  #endif
+
+  #ifndef __opencl_c_generic_address_space
+   #error Feature __opencl_c_generic_address_space should be defined
+  #endif
+
+  #ifndef __opencl_c_pipes
+   #error Feature __opencl_c_pipes should be defined
+  #endif
+
+  #ifndef __opencl_c_program_scope_global_variables
+   #error Feature __opencl_c_program_scope_global_variables should be defined
+  #endif
+
+  #ifndef __opencl_c_read_write_images
+   #error Feature __opencl_c_read_write_images should be defined
+  #endif
+
+  #ifndef __opencl_c_subgroups
+   #error Feature __opencl_c_subgroups should be defined
+  #endif
+
+  #ifndef __opencl_c_work_group_collective_functions
+   #error Feature __opencl_c_work_group_collective_functions should be defined
+  #endif
+
+  #ifndef __opencl_c_fp64
+   #error Feature __opencl_c_fp64 should be defined
+  #endif
+
+  #ifndef __opencl_c_images
+   #error Feature __opencl_c_images should be defined
+  #endif
+#endif // defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+
+
+#if __OPENCL_C_VERSION__ == CL_VERSION_3_0
+  #ifdef __opencl_c_3d_image_writes
+   #error Feature __opencl_c_3d_image_writes shouldn't be defined
+  #endif
+
+  #ifdef __opencl_c_atomic_order_acq_rel
+   #error Feature __opencl_c_atomic_order_acq_rel shouldn't be defined
+  #endif
+
+  #ifdef __opencl_c_atomic_order_seq_cst
+   #error Feature __opencl_c_atomic_order_seq_cst shouldn't be defined
+  #endif
+
+  #ifdef __opencl_c_atomic_scope_device
+   #error Feature __opencl_c_atomic_scope_device shouldn't be defined
+  #endif
+
+  #ifdef __opencl_c_atomic_scope_all_devices
+   #error Feature __opencl_c_atomic_scope_all_devices shouldn't be defined
+  #endif
+
+  #ifdef __opencl_c_device_enqueue
+   #error Feature __opencl_c_device_enqueue shouldn't be defined
+  #endif
+
+  #ifdef __opencl_c_generic_address_space
+   #error Feature __opencl_c_generic_address_space shouldn't be defined
+  #endif
+
+  #ifdef __opencl_c_pipes
+   #error Feature __opencl_c_pipes shouldn't be defined
+  #endif
+
+  #ifdef __opencl_c_program_scope_global_variables
+   #error Feature __opencl_c_program_scope_global_variables shouldn't be defined
+  #endif
+
+  #ifdef __opencl_c_read_write_images
+   #error Feature __opencl_c_read_write_images shouldn't be defined
+  #endif
+
+  #ifdef __opencl_c_subgroups
+   #error Feature __opencl_c_subgroups shouldn't be defined
+  #endif
+
+  #ifdef __opencl_c_work_group_collective_functions
+   #error Feature __opencl_c_work_group_collective_functions shouldn't be defined
+  #endif

[PATCH] D96524: [OpenCL] Add support of OpenCL C 3.0 __opencl_c_fp64

2021-05-14 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/lib/Sema/Sema.cpp:306
+// Set conditionally to provide correct diagnostics for 'double' type
+llvm::StringRef FP64Feature(
+getLangOpts().OpenCLVersion >= 300 ? "__opencl_c_fp64" : 
"cl_khr_fp64");

Anastasia wrote:
> Technically both "__opencl_c_fp64" and "cl_khr_fp64" are required in OpenCL, 
> perhaps we should report both in OpenCL 3?
Even better, can we merge this first https://reviews.llvm.org/D100976? This is 
needed to completely remove such check for fp64.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96524/new/

https://reviews.llvm.org/D96524

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96524: [OpenCL] Add support of OpenCL C 3.0 __opencl_c_fp64

2021-05-17 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 345846.
azabaznov edited the summary of this revision.
azabaznov added a comment.

Rebase after https://reviews.llvm.org/D100976; addressed review comments and 
updated docs.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96524/new/

https://reviews.llvm.org/D96524

Files:
  clang/docs/OpenCLSupport.rst
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenOpenCL/printf.cl
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/extensions.cl
  clang/test/SemaOpenCL/fp64-fp16-options.cl

Index: clang/test/SemaOpenCL/fp64-fp16-options.cl
===
--- clang/test/SemaOpenCL/fp64-fp16-options.cl
+++ clang/test/SemaOpenCL/fp64-fp16-options.cl
@@ -5,6 +5,7 @@
 
 // Test with a target not supporting fp64.
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
 
 // Test with some extensions enabled or disabled by cmd-line args
 //
@@ -16,12 +17,18 @@
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-cl_khr_fp64 -DNOFP64
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=-all,+cl_khr_fp64 -DNOFP16
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -DNOFP64 -DNOFP16
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all -DFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-__opencl_c_fp64,-cl_khr_fp64 -DNOFP64
 //
 // Concatenating
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64 -cl-ext=+cl_khr_fp64
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64,+cl_khr_fp64
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64 -cl-ext=+cl_khr_fp16 -cl-ext=-cl_khr_fp64 -DNOFP64
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64,-cl_khr_fp64,+cl_khr_fp16 -DNOFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,-cl_khr_fp64 -cl-ext=+__opencl_c_fp64,+cl_khr_fp64 -DFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,+__opencl_c_fp64,+cl_khr_fp64 -DFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,-cl_khr_fp64 -DNOFP64
 
 // Test with -finclude-default-header, which includes opencl-c.h. opencl-c.h
 // disables all extensions by default, but supported core extensions for a
@@ -85,18 +92,30 @@
 void f2(void) {
   double d;
 #ifdef NOFP64
-// expected-error@-2{{use of type 'double' requires cl_khr_fp64 support}}
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 300)
+// expected-error@-3{{use of type 'double' requires cl_khr_fp64 and __opencl_c_fp64 support}}
+#else
+// expected-error@-5{{use of type 'double' requires cl_khr_fp64 support}}
+#endif
 #endif
 
   typedef double double4 __attribute__((ext_vector_type(4)));
   double4 d4 = {0.0f, 2.0f, 3.0f, 1.0f};
 #ifdef NOFP64
-// expected-error@-3 {{use of type 'double' requires cl_khr_fp64 support}}
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 300)
+// expected-error@-4 {{use of type 'double' requires cl_khr_fp64 and __opencl_c_fp64 support}}
+#else
+// expected-error@-6 {{use of type 'double' requires cl_khr_fp64 support}}
+#endif
 #endif
 
   (void) 1.0;
 #ifdef NOFP64
-// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}}
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 300)
+// expected-warning@-3{{double precision constant requires cl_khr_fp64 and __opencl_c_fp64, casting to single precision}}
+#else
+// expected-warning@-5{{double precision constant requires cl_khr_fp64, casting to single precision}}
+#endif
 #endif
 }
 
Index: clang/test/Misc/opencl-c-3.0.incorrect_options.cl

[PATCH] D96524: [OpenCL] Add support of OpenCL C 3.0 __opencl_c_fp64

2021-05-19 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 346379.
azabaznov added a comment.

Drop formatting changes from Sema.cpp


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96524/new/

https://reviews.llvm.org/D96524

Files:
  clang/docs/OpenCLSupport.rst
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenOpenCL/printf.cl
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/extensions.cl
  clang/test/SemaOpenCL/fp64-fp16-options.cl

Index: clang/test/SemaOpenCL/fp64-fp16-options.cl
===
--- clang/test/SemaOpenCL/fp64-fp16-options.cl
+++ clang/test/SemaOpenCL/fp64-fp16-options.cl
@@ -5,6 +5,7 @@
 
 // Test with a target not supporting fp64.
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
 
 // Test with some extensions enabled or disabled by cmd-line args
 //
@@ -16,12 +17,18 @@
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-cl_khr_fp64 -DNOFP64
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=-all,+cl_khr_fp64 -DNOFP16
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -DNOFP64 -DNOFP16
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all -DFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-__opencl_c_fp64,-cl_khr_fp64 -DNOFP64
 //
 // Concatenating
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64 -cl-ext=+cl_khr_fp64
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64,+cl_khr_fp64
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64 -cl-ext=+cl_khr_fp16 -cl-ext=-cl_khr_fp64 -DNOFP64
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64,-cl_khr_fp64,+cl_khr_fp16 -DNOFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,-cl_khr_fp64 -cl-ext=+__opencl_c_fp64,+cl_khr_fp64 -DFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,+__opencl_c_fp64,+cl_khr_fp64 -DFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,-cl_khr_fp64 -DNOFP64
 
 // Test with -finclude-default-header, which includes opencl-c.h. opencl-c.h
 // disables all extensions by default, but supported core extensions for a
@@ -85,18 +92,30 @@
 void f2(void) {
   double d;
 #ifdef NOFP64
-// expected-error@-2{{use of type 'double' requires cl_khr_fp64 support}}
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 300)
+// expected-error@-3{{use of type 'double' requires cl_khr_fp64 and __opencl_c_fp64 support}}
+#else
+// expected-error@-5{{use of type 'double' requires cl_khr_fp64 support}}
+#endif
 #endif
 
   typedef double double4 __attribute__((ext_vector_type(4)));
   double4 d4 = {0.0f, 2.0f, 3.0f, 1.0f};
 #ifdef NOFP64
-// expected-error@-3 {{use of type 'double' requires cl_khr_fp64 support}}
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 300)
+// expected-error@-4 {{use of type 'double' requires cl_khr_fp64 and __opencl_c_fp64 support}}
+#else
+// expected-error@-6 {{use of type 'double' requires cl_khr_fp64 support}}
+#endif
 #endif
 
   (void) 1.0;
 #ifdef NOFP64
-// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}}
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 300)
+// expected-warning@-3{{double precision constant requires cl_khr_fp64 and __opencl_c_fp64, casting to single precision}}
+#else
+// expected-warning@-5{{double precision constant requires cl_khr_fp64, casting to single precision}}
+#endif
 #endif
 }
 
Index: clang/test/Misc/opencl-c-3.0.incorrect_options.cl
===
--- /dev/null
+++ clang/test/Misc/opencl-c-3.0.incorrect_options.cl
@@ -0,0 +1,4 @@
+// RUN: 

[PATCH] D96524: [OpenCL] Add support of OpenCL C 3.0 __opencl_c_fp64

2021-05-19 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 346380.
azabaznov added a comment.

Drop one more formatting change from Sema.cpp


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96524/new/

https://reviews.llvm.org/D96524

Files:
  clang/docs/OpenCLSupport.rst
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenOpenCL/printf.cl
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/extensions.cl
  clang/test/SemaOpenCL/fp64-fp16-options.cl

Index: clang/test/SemaOpenCL/fp64-fp16-options.cl
===
--- clang/test/SemaOpenCL/fp64-fp16-options.cl
+++ clang/test/SemaOpenCL/fp64-fp16-options.cl
@@ -5,6 +5,7 @@
 
 // Test with a target not supporting fp64.
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
 
 // Test with some extensions enabled or disabled by cmd-line args
 //
@@ -16,12 +17,18 @@
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-cl_khr_fp64 -DNOFP64
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=-all,+cl_khr_fp64 -DNOFP16
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -DNOFP64 -DNOFP16
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all -DFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-__opencl_c_fp64,-cl_khr_fp64 -DNOFP64
 //
 // Concatenating
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64 -cl-ext=+cl_khr_fp64
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64,+cl_khr_fp64
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64 -cl-ext=+cl_khr_fp16 -cl-ext=-cl_khr_fp64 -DNOFP64
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64,-cl_khr_fp64,+cl_khr_fp16 -DNOFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,-cl_khr_fp64 -cl-ext=+__opencl_c_fp64,+cl_khr_fp64 -DFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,+__opencl_c_fp64,+cl_khr_fp64 -DFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,-cl_khr_fp64 -DNOFP64
 
 // Test with -finclude-default-header, which includes opencl-c.h. opencl-c.h
 // disables all extensions by default, but supported core extensions for a
@@ -85,18 +92,30 @@
 void f2(void) {
   double d;
 #ifdef NOFP64
-// expected-error@-2{{use of type 'double' requires cl_khr_fp64 support}}
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 300)
+// expected-error@-3{{use of type 'double' requires cl_khr_fp64 and __opencl_c_fp64 support}}
+#else
+// expected-error@-5{{use of type 'double' requires cl_khr_fp64 support}}
+#endif
 #endif
 
   typedef double double4 __attribute__((ext_vector_type(4)));
   double4 d4 = {0.0f, 2.0f, 3.0f, 1.0f};
 #ifdef NOFP64
-// expected-error@-3 {{use of type 'double' requires cl_khr_fp64 support}}
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 300)
+// expected-error@-4 {{use of type 'double' requires cl_khr_fp64 and __opencl_c_fp64 support}}
+#else
+// expected-error@-6 {{use of type 'double' requires cl_khr_fp64 support}}
+#endif
 #endif
 
   (void) 1.0;
 #ifdef NOFP64
-// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}}
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 300)
+// expected-warning@-3{{double precision constant requires cl_khr_fp64 and __opencl_c_fp64, casting to single precision}}
+#else
+// expected-warning@-5{{double precision constant requires cl_khr_fp64, casting to single precision}}
+#endif
 #endif
 }
 
Index: clang/test/Misc/opencl-c-3.0.incorrect_options.cl
===
--- /dev/null
+++ clang/test/Misc/opencl-c-3.0.incorrect_options.cl
@@ -0,0 +1,4 @@
+// RUN: not %clang_cc1 -cl

[PATCH] D96524: [OpenCL] Add support of OpenCL C 3.0 __opencl_c_fp64

2021-05-19 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov marked an inline comment as done.
azabaznov added inline comments.



Comment at: clang/test/CodeGenOpenCL/printf.cl:9
 
-#ifdef cl_khr_fp64
+#if defined(cl_khr_fp64) || defined(__opencl_c_fp64)
 typedef __attribute__((ext_vector_type(2))) double double2;

Anastasia wrote:
> I think we don't technically need this change?
To be honest I am not sure. I think per OpenCL C spec extension feature macros 
should be used exactly as follows:

```
...
if defined(cl_khr_fp64) || defined(__opencl_c_fp64)
...
```

So I think this is OK to have such checks in tests as soon as we have 
functionality for simultaneous support (`opencl-c-3.0.incorrect_options.cl`). 
If we decide to change that behaviour - this test will fail.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96524/new/

https://reviews.llvm.org/D96524

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102853: [OpenCL] Align definition of __IMAGE_SUPPORT__ feature macro with OpenCL version and __opencl_c_images feature macro definition

2021-05-20 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov created this revision.
azabaznov added reviewers: Anastasia, svenvh.
Herald added subscribers: ldrumm, yaxunl.
azabaznov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102853

Files:
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Preprocessor/predefined-macros.c
  clang/test/SemaOpenCL/features.cl


Index: clang/test/SemaOpenCL/features.cl
===
--- clang/test/SemaOpenCL/features.cl
+++ clang/test/SemaOpenCL/features.cl
@@ -1,9 +1,9 @@
 // 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:   | FileCheck -match-full-lines %s  
--check-prefixes=NO-FEATURES,NO-FEATURES-CL30
 // 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
+// RUN:   | FileCheck -match-full-lines %s  
--check-prefixes=NO-FEATURES,NO-FEATURES-CL30
 // RUN: %clang_cc1 -triple r600-unknown-unknown %s -E -dM -o - -x cl 
-cl-std=CL3.0 -cl-ext=+all \
 // RUN:   | FileCheck -match-full-lines %s  --check-prefix=FEATURES
 
@@ -21,6 +21,7 @@
 // Note that __opencl_c_int64 is always defined assuming
 // always compiling for FULL OpenCL profile
 
+// FEATURES: #define __IMAGE_SUPPORT__ 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
@@ -46,3 +47,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-CL30-NOT: __IMAGE_SUPPORT__
Index: clang/test/Preprocessor/predefined-macros.c
===
--- clang/test/Preprocessor/predefined-macros.c
+++ clang/test/Preprocessor/predefined-macros.c
@@ -188,14 +188,12 @@
 
 // RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir-unknown-unknown \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR
-// CHECK-SPIR-DAG: #define __IMAGE_SUPPORT__ 1
 // CHECK-SPIR-DAG: #define __SPIR__ 1
 // CHECK-SPIR-DAG: #define __SPIR32__ 1
 // CHECK-SPIR-NOT: #define __SPIR64__ 1
 
 // RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir64-unknown-unknown \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR64
-// CHECK-SPIR64-DAG: #define __IMAGE_SUPPORT__ 1
 // CHECK-SPIR64-DAG: #define __SPIR__ 1
 // CHECK-SPIR64-DAG: #define __SPIR64__ 1
 // CHECK-SPIR64-NOT: #define __SPIR32__ 1
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -603,9 +603,9 @@
 
 /// InitializeOpenCLFeatureTestMacros - Define OpenCL macros based on target
 /// settings and language version
-void InitializeOpenCLFeatureTestMacros(const TargetInfo &TI,
-   const LangOptions &Opts,
-   MacroBuilder &Builder) {
+static void InitializeOpenCLFeatureTestMacros(const TargetInfo &TI,
+  const LangOptions &Opts,
+  MacroBuilder &Builder) {
   const llvm::StringMap &OpenCLFeaturesMap = TI.getSupportedOpenCLOpts();
   // FIXME: OpenCL options which affect language semantics/syntax
   // should be moved into LangOptions.
@@ -622,6 +622,10 @@
 
   // Assume compiling for FULL profile
   Builder.defineMacro("__opencl_c_int64");
+
+  if (Opts.OpenCLCPlusPlus || Opts.OpenCLVersion < 300 ||
+  TI.hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_images"))
+Builder.defineMacro("__IMAGE_SUPPORT__");
 }
 
 static void InitializePredefinedMacros(const TargetInfo &TI,
@@ -1159,13 +1163,9 @@
   }
 
   // OpenCL definitions.
-  if (LangOpts.OpenCL) {
+  if (LangOpts.OpenCL)
 InitializeOpenCLFeatureTestMacros(TI, LangOpts, Builder);
 
-if (TI.getTriple().isSPIR())
-  Builder.defineMacro("__IMAGE_SUPPORT__");
-  }
-
   if (TI.hasInt128Type() && LangOpts.CPlusPlus && LangOpts.GNUMode) {
 // For each extended integer type, g++ defines a macro mapping the
 // index of the type (0 in this case) in some list of extended types


Index: clang/test/SemaOpenCL/features.cl
===
--- clang/test/SemaOpenCL/features.cl
+++ clang/test/SemaOpenCL/features.cl
@@ -1,9 +1,9 @@
 // RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=CL3.0 -cl-ext=-all \
-// RUN:   | FileCheck 

[PATCH] D96524: [OpenCL] Add support of OpenCL C 3.0 __opencl_c_fp64

2021-05-21 Thread Anton Zabaznov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG826905787ae4: [OpenCL] Add support of OpenCL C 3.0 
__opencl_c_fp64 (authored by azabaznov).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96524/new/

https://reviews.llvm.org/D96524

Files:
  clang/docs/OpenCLSupport.rst
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenOpenCL/printf.cl
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/extensions.cl
  clang/test/SemaOpenCL/fp64-fp16-options.cl

Index: clang/test/SemaOpenCL/fp64-fp16-options.cl
===
--- clang/test/SemaOpenCL/fp64-fp16-options.cl
+++ clang/test/SemaOpenCL/fp64-fp16-options.cl
@@ -5,6 +5,7 @@
 
 // Test with a target not supporting fp64.
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
 
 // Test with some extensions enabled or disabled by cmd-line args
 //
@@ -16,12 +17,18 @@
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-cl_khr_fp64 -DNOFP64
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=-all,+cl_khr_fp64 -DNOFP16
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -DNOFP64 -DNOFP16
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all -DFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-__opencl_c_fp64,-cl_khr_fp64 -DNOFP64
 //
 // Concatenating
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64 -cl-ext=+cl_khr_fp64
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64,+cl_khr_fp64
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64 -cl-ext=+cl_khr_fp16 -cl-ext=-cl_khr_fp64 -DNOFP64
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64,-cl_khr_fp64,+cl_khr_fp16 -DNOFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,-cl_khr_fp64 -cl-ext=+__opencl_c_fp64,+cl_khr_fp64 -DFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,+__opencl_c_fp64,+cl_khr_fp64 -DFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,-cl_khr_fp64 -DNOFP64
 
 // Test with -finclude-default-header, which includes opencl-c.h. opencl-c.h
 // disables all extensions by default, but supported core extensions for a
@@ -85,18 +92,30 @@
 void f2(void) {
   double d;
 #ifdef NOFP64
-// expected-error@-2{{use of type 'double' requires cl_khr_fp64 support}}
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 300)
+// expected-error@-3{{use of type 'double' requires cl_khr_fp64 and __opencl_c_fp64 support}}
+#else
+// expected-error@-5{{use of type 'double' requires cl_khr_fp64 support}}
+#endif
 #endif
 
   typedef double double4 __attribute__((ext_vector_type(4)));
   double4 d4 = {0.0f, 2.0f, 3.0f, 1.0f};
 #ifdef NOFP64
-// expected-error@-3 {{use of type 'double' requires cl_khr_fp64 support}}
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 300)
+// expected-error@-4 {{use of type 'double' requires cl_khr_fp64 and __opencl_c_fp64 support}}
+#else
+// expected-error@-6 {{use of type 'double' requires cl_khr_fp64 support}}
+#endif
 #endif
 
   (void) 1.0;
 #ifdef NOFP64
-// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}}
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 300)
+// expected-warning@-3{{double precision constant requires cl_khr_fp64 and __opencl_c_fp64, casting to single precision}}
+#else
+// expected-warning@-5{{double precision constant requires cl_khr_fp64, casting to single precision}}
+#endif
 #endif
 }
 
Index: clang/test/Misc/opencl-c-3.0.incorrect_options.cl

[PATCH] D103191: [OpenCL] Add support of __opencl_c_program_scope_global_variables feature macro

2021-05-26 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov created this revision.
azabaznov added reviewers: Anastasia, svenvh.
Herald added subscribers: ldrumm, yaxunl.
azabaznov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103191

Files:
  clang/include/clang/Basic/OpenCLOptions.h
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenOpenCL/addr-space-struct-arg.cl
  clang/test/SemaOpenCL/storageclass.cl

Index: clang/test/SemaOpenCL/storageclass.cl
===
--- clang/test/SemaOpenCL/storageclass.cl
+++ clang/test/SemaOpenCL/storageclass.cl
@@ -1,46 +1,77 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
-
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables -DNO_GENERIC_AS
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables -DNO_GENERIC_AS
 static constant int G1 = 0;
 constant int G2 = 0;
-int G3 = 0;// expected-error{{program scope variable must reside in constant address space}}
-global int G4 = 0; // expected-error{{program scope variable must reside in constant address space}}
+int G3 = 0;
+global int G4 = 0;
 
-static float g_implicit_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
+static float g_implicit_static_var = 0;
 static constant float g_constant_static_var = 0;
-static global float g_global_static_var = 0;   // expected-error {{program scope variable must reside in constant address space}}
-static local float g_local_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
-static private float g_private_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
-static generic float g_generic_static_var = 0; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}}
+static global float g_global_static_var = 0;
+static local float g_local_static_var = 0;
+static private float g_private_static_var = 0;
+static generic float g_generic_static_var = 0;
 
-extern float g_implicit_extern_var; // expected-error {{extern variable must reside in constant address space}}
+extern float g_implicit_extern_var;
 extern constant float g_constant_extern_var;
-extern global float g_global_extern_var;   // expected-error {{extern variable must reside in constant address space}}
-extern local float g_local_extern_var; // expected-error {{extern variable must reside in constant address space}}
-extern private float g_private_extern_var; // expected-error {{extern variable must reside in constant address space}}
-extern generic float g_generic_extern_var; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{extern variable must reside in constant address space}}
+extern global float g_global_extern_var;
+extern local float g_local_extern_var;
+extern private float g_private_extern_var;
+extern generic float g_generic_extern_var;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-17 {{program scope variable must reside in constant address space}}
+// expected-error@-17 {{program scope variable must reside in constant address space}}
+// expected-error@-16 {{program scope variable must reside in constant address space}}
+// expected-error@-15 {{program scope variable must reside in constant address space}}
+// expected-error@-15 {{program scope variable must reside in constant address space}}
+// expected-error@-15 {{program scope variable must reside in constant address space}}
+// expected-error-re@-15 {{OpenCL C version {{1.2|3.0}} does not support the 'generic' type qualifier}}
+// expected-error@-16 {{program scope variable must reside in constant address space}}
+// expected-error@-15 {{extern variable must reside in constant address space}}
+// expected-error@-14 {{extern variable must reside in constant address space}}
+// expected-error@-14 {{extern variable must reside in constant address space}}
+// expected-error@-14 {{extern variable must reside in constant address space}}
+// expected-error-re@-14 {{OpenCL C version {{1.2|3.0}} does not support the 'generic' type qualifier}}
+// expected-error@-15 {{extern variable must reside in constant address space}}
+#else
+// expected-error@-26 {{program scope variable must reside in global or constant address space}}
+// expected-error@-26 {{program scope variable must reside in global or constant address space}}
+// expected-error@-26 {{OpenCL C version 3.0 does not support the 'generic' type qualifier}}
+// expected-error@-22 {{extern variable must reside in global or constant address space}}
+// expected-error@-22 {{extern variable must r

[PATCH] D103241: [OpenCL] Add memory_scope_all_devices

2021-05-27 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:113
 OPENCL_OPTIONALCOREFEATURE(__opencl_c_atomic_order_seq_cst, false, 300, 
OCL_C_30)
+OPENCL_OPTIONALCOREFEATURE(__opencl_c_atomic_scope_all_devices, false, 300, 
OCL_C_30)
 OPENCL_OPTIONALCOREFEATURE(__opencl_c_subgroups, false, 300, OCL_C_30)

This feature is header only. We had a lot of discussions on that and the main 
idea was not to declare header only features/extensions in 
`OpenCLExtensions.def` and use `-D__opencl_c_atomic_scope_all_devices=1` 
instead, @Anastasia can comment on this.

I personally would like to introduce new flag for OpenCL options in 
`OpenCLExtensions.def` which will indicate that feature/extension is 
header-only, and thus all of such options can be declared in 
`OpenCLExtensions.def`: if flag is set to true it can be stripped out from the 
parser. What do you think about this?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103241/new/

https://reviews.llvm.org/D103241

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103241: [OpenCL] Add memory_scope_all_devices

2021-05-27 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:113
 OPENCL_OPTIONALCOREFEATURE(__opencl_c_atomic_order_seq_cst, false, 300, 
OCL_C_30)
+OPENCL_OPTIONALCOREFEATURE(__opencl_c_atomic_scope_all_devices, false, 300, 
OCL_C_30)
 OPENCL_OPTIONALCOREFEATURE(__opencl_c_subgroups, false, 300, OCL_C_30)

Anastasia wrote:
> svenvh wrote:
> > Anastasia wrote:
> > > azabaznov wrote:
> > > > This feature is header only. We had a lot of discussions on that and 
> > > > the main idea was not to declare header only features/extensions in 
> > > > `OpenCLExtensions.def` and use 
> > > > `-D__opencl_c_atomic_scope_all_devices=1` instead, @Anastasia can 
> > > > comment on this.
> > > > 
> > > > I personally would like to introduce new flag for OpenCL options in 
> > > > `OpenCLExtensions.def` which will indicate that feature/extension is 
> > > > header-only, and thus all of such options can be declared in 
> > > > `OpenCLExtensions.def`: if flag is set to true it can be stripped out 
> > > > from the parser. What do you think about this?
> > > Yes, I agree the idea is to align with C/C++ directions for scalability 
> > > i.e. we should only add what is absolutely necessary to the compiler and 
> > > implement the rest using libraries - just like regular C and C++. We 
> > > won't be able to scale if we keep adding everything in the compiler. In 
> > > fact, we already have a huge scalability issue with our builtin 
> > > functions. If we look at modern C++ - more than 70% of features are not 
> > > in the compiler at all.
> > > 
> > > Would it be possible to do something like suggested here: 
> > > https://reviews.llvm.org/D91531#change-AKXhB4ko4nAO for 
> > > `cl_khr_depth_images`?
> > > 
> > > > I personally would like to introduce new flag for OpenCL options in 
> > > > OpenCLExtensions.def which will indicate that feature/extension is 
> > > > header-only, and thus all of such options can be declared in 
> > > > OpenCLExtensions.def: if flag is set to true it can be stripped out 
> > > > from the parser. What do you think about this?
> > > 
> > > Hmm, I think the macros should either be declared in the headers or using 
> > > a flag `-D`. I don't know why would adding them in `OpenCLExtensions.def` 
> > > be beneficial if we can use conventional approaches? This allows avoiding 
> > > the complexity and makes things more modular. If we look at the OpenCL 
> > > vendor extensions for example - we probably don't want them all in one 
> > > place?
> > > This feature is header only.
> > 
> > Good catch!  I have updated the patch to define the feature macro in the 
> > header instead.  Currently that definition is not optional, since we don't 
> > have finalized the solution for handling this yet (though the __undef 
> > proposal seems to be compatible with this change).
> > 
> > > I personally would like to introduce new flag for OpenCL options in 
> > > OpenCLExtensions.def which will indicate that feature/extension is 
> > > header-only
> > 
> > If we still need to add header-only features to OpenCLExtensions.def, then 
> > they aren't really header-only anymore I'd argue (as @Anastasia pointed out 
> > above).  So I'm not sure we need it either, or perhaps I missed something.
> FYI we have already added extended subgroups extension macros for SPIR in 
> `opencl-c-base.h` without the `__undef<...>` trick.
> 
> ```
> #if defined(__SPIR__)
> #define cl_khr_subgroup_extended_types 1
> #define cl_khr_subgroup_non_uniform_vote 1
> #define cl_khr_subgroup_ballot 1
> #define cl_khr_subgroup_non_uniform_arithmetic 1
> #define cl_khr_subgroup_shuffle 1
> #define cl_khr_subgroup_shuffle_relative 1
> #define cl_khr_subgroup_clustered_reduce 1
> #endif // defined(__SPIR__)
> ```
> 
> But extra conditions can be added any time if we get the agreement on the 
> route forward. 
> Hmm, I think the macros should either be declared in the headers or using a 
> flag -D. I don't know why would adding them in OpenCLExtensions.def be 
> beneficial if we can use conventional approaches? This allows avoiding the 
> complexity and makes things more modular. If we look at the OpenCL vendor 
> extensions for example - we probably don't want them all in one place?

Well, IMO separating extensions/features into two classes of options exactly 
brings new complexities :) I'm not sure why do we need to have a separate 
interface for them if there already exists unified one. For example, Intel 
compute-runtime uses `-cl-ext` flag to forward options : 
https://github.com/intel/compute-runtime/blob/master/opencl/source/platform/extensions.cpp#L156.
 

Can we use this header  mechanism  to define header-only features/extensions 
while `-cl-ext`interface is preserved?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103241/new/

https://reviews.llvm.org/D103241

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://list

[PATCH] D103401: [OpenCL] Add support of __opencl_c_generic_address_space feature macro

2021-05-31 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov created this revision.
azabaznov added reviewers: Anastasia, svenvh.
Herald added subscribers: ldrumm, kerbowa, yaxunl, nhaehnle, jvesely.
azabaznov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103401

Files:
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/test/CodeGenOpenCL/address-spaces-conversions.cl
  clang/test/CodeGenOpenCL/address-spaces-mangling.cl
  clang/test/CodeGenOpenCL/address-spaces.cl
  clang/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl
  clang/test/CodeGenOpenCL/overload.cl
  clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
  clang/test/SemaOpenCL/address-spaces.cl

Index: clang/test/SemaOpenCL/address-spaces.cl
===
--- clang/test/SemaOpenCL/address-spaces.cl
+++ clang/test/SemaOpenCL/address-spaces.cl
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space -verify -pedantic -fsyntax-only
 // RUN: %clang_cc1 %s -cl-std=clc++ -verify -pedantic -fsyntax-only
 
 __constant int ci = 1;
Index: clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
===
--- clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
+++ clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
@@ -4,6 +4,9 @@
 // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DCONSTANT -cl-std=clc++
 // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=clc++
 // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=clc++
+// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DCONSTANT -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space
 
 /* OpenCLC v2.0 adds a set of restrictions for conversions between pointers to
 *  different address spaces, mainly described in Sections 6.5.5 and 6.5.6.
@@ -17,6 +20,8 @@
 *  case), and __constant, that should cover all program paths for CL address
 *  space conversions used in initialisations, assignments, casts, comparisons
 *  and arithmetic operations.
+*
+*  OpenCLC v3.0 supports generic address if __opencl_c_generic_address_space feature is supported
 */
 
 #ifdef GENERIC
Index: clang/test/CodeGenOpenCL/overload.cl
===
--- clang/test/CodeGenOpenCL/overload.cl
+++ clang/test/CodeGenOpenCL/overload.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -cl-std=CL2.0 -emit-llvm -o - -triple spir-unknown-unknown %s | FileCheck %s
+// RUN: %clang_cc1 -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space -emit-llvm -o - -triple spir-unknown-unknown %s | FileCheck %s
 
 typedef short short4 __attribute__((ext_vector_type(4)));
 
Index: clang/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl
===
--- clang/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl
+++ clang/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl
@@ -5,6 +5,18 @@
 // RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-std=CL1.2 %s -emit-llvm -o - | FileCheck %s
 // RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-std=CL2.0 %s -emit-llvm -o - | FileCheck %s
 
+// RUN: %clang_cc1 -triple r600 -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-mesa-mesa3d -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---opencl -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-mesa-mesa3d -cl-ext=+__opencl_c_generic_address_space -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---opencl -cl-ext=+__opencl_c_generic_address_space -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-ext=+__opencl_c_generic_address_space -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple r600 -cl-ext=+cl_khr_fp64,+__opencl_c_fp64 -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-mesa-mesa3d -cl-ext=+cl_khr_fp64,+__opencl_c_fp64 -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---opencl -cl-ext=+cl_khr_fp64,+__opencl_c_fp64 -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-ext=+cl_khr_fp64,+__opencl_c

[PATCH] D103191: [OpenCL] Add support of __opencl_c_program_scope_global_variables feature macro

2021-06-01 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/test/SemaOpenCL/storageclass.cl:22
+extern generic float g_generic_extern_var;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-17 {{program scope variable must reside in constant address 
space}}

svenvh wrote:
> Not sure if this is the best way to restructure this test?  Now the 
> diagnostics are quite far away from the declarations, and it is harder to see 
> which diagnostic belongs to which declaration.
> 
> I wonder if the following would be a better structure instead:
> ```
> int G3 = 0;
> #ifndef __opencl_c_program_scope_global_variables
> // expected-error@-2 {{program scope variable must reside in constant address 
> space}}
> #endif
> 
> global int G4 = 0;
> #ifndef __opencl_c_program_scope_global_variables
> // expected-error@-2 {{program scope variable must reside in constant address 
> space}}
> #endif
> 
> ... etc. ...
> ```
> 
> The downside is that it is a bit more verbose due to the repetition of the 
> `#if` guards, but it makes the test more readable/maintainable in my opinion.
Yeah, that's reasonable. I'll change that in the following patch. Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103191/new/

https://reviews.llvm.org/D103191

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103401: [OpenCL] Add support of __opencl_c_generic_address_space feature macro

2021-06-01 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/lib/Basic/TargetInfo.cpp:405
+  const auto &OpenCLFeaturesMap = getSupportedOpenCLOpts();
+  Opts.OpenCLGenericAddressSpace = hasFeatureEnabled(
+  OpenCLFeaturesMap, "__opencl_c_generic_address_space");

Anastasia wrote:
> svenvh wrote:
> > This means we now have two separate places that set 
> > `OpenCLGenericAddressSpace`, the other place being in 
> > `CompilerInvocation::setLangDefaults()`.  That feels like a maintenance 
> > hazard.  Do you think it makes sense to set this field in one single place 
> > instead?
> I think we should try to set it in `CompilerInvocation.cpp` directly, we 
> should be able to query `TargetOptions` there. Although that place is 
> expected to be for the language-specific defaults but we broke the standard 
> flow by having the language mode controlled by the target settings anyway.
> 
> I can't remember though why we have decided to add dedicated `LangOpts` 
> entries for generic address space instead of just using `OpenCLOptions` from 
> `Sema`? I think it simplifies the handling of some builtin functions?
> This means we now have two separate places that set 
> OpenCLGenericAddressSpace, the other place being in 
> CompilerInvocation::setLangDefaults(). That feels like a maintenance hazard. 
> Do you think it makes sense to set this field in one single place instead?

>I think we should try to set it in CompilerInvocation.cpp directly, we should 
>be able to query TargetOptions there. 

I don't think that we are able to access target options at that stage without 
modifying current interfaces.  `CompilerInvocation::setLangDefaults()` is a 
static member function.

> I can't remember though why we have decided to add dedicated LangOpts entries 
> for generic address space instead of just using OpenCLOptions from Sema? I 
> think it simplifies the handling of some builtin functions?

That's correct. Also, the idea was to reuse generic keyword in other languages.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103401/new/

https://reviews.llvm.org/D103401

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103401: [OpenCL] Add support of __opencl_c_generic_address_space feature macro

2021-06-01 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/lib/Basic/TargetInfo.cpp:405
+  const auto &OpenCLFeaturesMap = getSupportedOpenCLOpts();
+  Opts.OpenCLGenericAddressSpace = hasFeatureEnabled(
+  OpenCLFeaturesMap, "__opencl_c_generic_address_space");

Anastasia wrote:
> azabaznov wrote:
> > Anastasia wrote:
> > > svenvh wrote:
> > > > This means we now have two separate places that set 
> > > > `OpenCLGenericAddressSpace`, the other place being in 
> > > > `CompilerInvocation::setLangDefaults()`.  That feels like a maintenance 
> > > > hazard.  Do you think it makes sense to set this field in one single 
> > > > place instead?
> > > I think we should try to set it in `CompilerInvocation.cpp` directly, we 
> > > should be able to query `TargetOptions` there. Although that place is 
> > > expected to be for the language-specific defaults but we broke the 
> > > standard flow by having the language mode controlled by the target 
> > > settings anyway.
> > > 
> > > I can't remember though why we have decided to add dedicated `LangOpts` 
> > > entries for generic address space instead of just using `OpenCLOptions` 
> > > from `Sema`? I think it simplifies the handling of some builtin functions?
> > > This means we now have two separate places that set 
> > > OpenCLGenericAddressSpace, the other place being in 
> > > CompilerInvocation::setLangDefaults(). That feels like a maintenance 
> > > hazard. Do you think it makes sense to set this field in one single place 
> > > instead?
> > 
> > >I think we should try to set it in CompilerInvocation.cpp directly, we 
> > >should be able to query TargetOptions there. 
> > 
> > I don't think that we are able to access target options at that stage 
> > without modifying current interfaces.  
> > `CompilerInvocation::setLangDefaults()` is a static member function.
> > 
> > > I can't remember though why we have decided to add dedicated LangOpts 
> > > entries for generic address space instead of just using OpenCLOptions 
> > > from Sema? I think it simplifies the handling of some builtin functions?
> > 
> > That's correct. Also, the idea was to reuse generic keyword in other 
> > languages.
> > I don't think that we are able to access target options at that stage 
> > without modifying current interfaces. CompilerInvocation::setLangDefaults() 
> > is a static member function.
> 
> I wonder if the function is static due to an old interface or something 
> because it seems to be only called from `CompilerInvocation::ParseLangArgs` 
> which isn't a static member as far as I can see. I wonder if it should just 
> become a non-static member instead?
> 
Actually `CompilerInvocation::ParseLangArgs` is static as well. Anyway, I think 
this change would be really impactful. I believe `::adjust` is a prefect place 
to coordinate language options with target information (at least for now).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103401/new/

https://reviews.llvm.org/D103401

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92277: [OpenCL] Refactor of targets OpenCL option settings

2021-01-22 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 318458.
azabaznov added a comment.
Herald added a project: clang.

Removed getCoreFeatures() as it's not used in this change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92277/new/

https://reviews.llvm.org/D92277

Files:
  clang/include/clang/Basic/OpenCLExtensions.def
  clang/include/clang/Basic/OpenCLOptions.h
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/Basic/TargetOptions.h
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Misc/nvptx.languageOptsOpenCL.cl
  clang/test/Misc/r600.languageOptsOpenCL.cl

Index: clang/test/Misc/r600.languageOptsOpenCL.cl
===
--- clang/test/Misc/r600.languageOptsOpenCL.cl
+++ clang/test/Misc/r600.languageOptsOpenCL.cl
@@ -2,27 +2,21 @@
 // RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple r600-unknown-unknown -target-cpu cayman
 // RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple r600-unknown-unknown -target-cpu cayman
 // RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple r600-unknown-unknown -target-cpu cayman
-// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple r600-unknown-unknown -target-cpu cayman
 // RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu cayman
 // RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu cayman
 // RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu cayman
-// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu cayman
 // RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple r600-unknown-unknown -target-cpu cypress
 // RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple r600-unknown-unknown -target-cpu cypress
 // RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple r600-unknown-unknown -target-cpu cypress
-// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple r600-unknown-unknown -target-cpu cypress
 // RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu cypress
 // RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu cypress
 // RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu cypress
-// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu cypress
 // RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple r600-unknown-unknown -target-cpu turks
 // RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple r600-unknown-unknown -target-cpu turks
 // RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple r600-unknown-unknown -target-cpu turks
-// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple r600-unknown-unknown -target-cpu turks
 // RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu turks
 // RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu turks
 // RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu turks
-// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu turks
 
 // Extensions in all versions
 #ifndef cl_clang_storage_class_specifiers
Index: clang/test/Misc/nvptx.languageOptsOpenCL.cl
===
--- clang/test/Misc/nvptx.languageOptsOpenCL.cl
+++ clang/test/Misc/nvptx.languageOptsOpenCL.cl
@@ -2,19 +2,15 @@
 // RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple nvptx-unknown-unknown
 // RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple nvptx-unknown-unknown
 // RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple nvptx-unknown-unknown
-// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple nvptx-unknown-unknown
 // RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple nvptx-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
 // RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple nvptx-unknown-unknown -Wpedantic-core-features -

[PATCH] D92277: [OpenCL] Refactor of targets OpenCL option settings

2021-01-22 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov marked an inline comment as done.
azabaznov added inline comments.



Comment at: clang/test/Misc/nvptx.languageOptsOpenCL.cl:18
 // RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple 
nvptx64-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
+// XFAIL: *
 

Anastasia wrote:
> We shouldn't disable the test, but only change it to check the conformant 
> behavior i.e. the expected diagnostics for `cl_khr_3d_image_writes` should be 
> guarded by the OpenCL version.
Yeah, sure. This won't a problem in this case as these test contain OpenCL C 
1.2 runs. OpenCL C 3.0 is backward compatible with OpenCL C 1.2 so all 1.2 runs 
should be tested together with 3.0.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92277/new/

https://reviews.llvm.org/D92277

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92277: [OpenCL] Refactor of targets OpenCL option settings

2021-01-25 Thread Anton Zabaznov via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe123cd674c02: [OpenCL] Refactor of targets OpenCL option 
settings (authored by azabaznov).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92277/new/

https://reviews.llvm.org/D92277

Files:
  clang/include/clang/Basic/OpenCLExtensions.def
  clang/include/clang/Basic/OpenCLOptions.h
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/Basic/TargetOptions.h
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Misc/nvptx.languageOptsOpenCL.cl
  clang/test/Misc/r600.languageOptsOpenCL.cl

Index: clang/test/Misc/r600.languageOptsOpenCL.cl
===
--- clang/test/Misc/r600.languageOptsOpenCL.cl
+++ clang/test/Misc/r600.languageOptsOpenCL.cl
@@ -2,27 +2,21 @@
 // RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple r600-unknown-unknown -target-cpu cayman
 // RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple r600-unknown-unknown -target-cpu cayman
 // RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple r600-unknown-unknown -target-cpu cayman
-// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple r600-unknown-unknown -target-cpu cayman
 // RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu cayman
 // RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu cayman
 // RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu cayman
-// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu cayman
 // RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple r600-unknown-unknown -target-cpu cypress
 // RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple r600-unknown-unknown -target-cpu cypress
 // RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple r600-unknown-unknown -target-cpu cypress
-// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple r600-unknown-unknown -target-cpu cypress
 // RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu cypress
 // RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu cypress
 // RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu cypress
-// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu cypress
 // RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple r600-unknown-unknown -target-cpu turks
 // RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple r600-unknown-unknown -target-cpu turks
 // RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple r600-unknown-unknown -target-cpu turks
-// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple r600-unknown-unknown -target-cpu turks
 // RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu turks
 // RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu turks
 // RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu turks
-// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple r600-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES -target-cpu turks
 
 // Extensions in all versions
 #ifndef cl_clang_storage_class_specifiers
Index: clang/test/Misc/nvptx.languageOptsOpenCL.cl
===
--- clang/test/Misc/nvptx.languageOptsOpenCL.cl
+++ clang/test/Misc/nvptx.languageOptsOpenCL.cl
@@ -2,19 +2,15 @@
 // RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple nvptx-unknown-unknown
 // RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple nvptx-unknown-unknown
 // RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple nvptx-unknown-unknown
-// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple nvptx-unknown-unknown
 // RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple nvptx-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
 // RU

[PATCH] D95776: [OpenCL] Add macro definitions of OpenCL C 3.0 features

2021-02-01 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov created this revision.
azabaznov added reviewers: Anastasia, mantognini.
Herald added subscribers: jfb, yaxunl.
azabaznov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds possibility to define OpenCL C 3.0 feature macros
via command line option or target setting.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95776

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

Index: clang/test/SemaOpenCL/features.cl
===
--- /dev/null
+++ 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
Index: clang/lib/Headers/opencl-c.h
===
--- clang/lib/Headers/opencl-c.h
+++ 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_
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ 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:
 
 /**
Index: clang/lib/Basic/Targets.cpp
===
--- clang/lib/Basic/Targets.cpp
+++ 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");
 }
Index: clang/include/clang/Basic/OpenCLExtensions.def
===
--- clang/include/clang/Basic/OpenCLExtensions.def
+++ clang/include/clang/Basic/OpenCLExtensions.def
@@ -64,7 +64,7 @@

[PATCH] D89869: [OpenCL] Define OpenCL feature macros for all versions

2021-02-01 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov abandoned this revision.
azabaznov added a comment.

Due to refactoring in https://reviews.llvm.org/D92277 this flow is no longer 
valid.  New patch for this functionality is here: 
https://reviews.llvm.org/D95776.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89869/new/

https://reviews.llvm.org/D89869

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95776: [OpenCL] Add macro definitions of OpenCL C 3.0 features

2021-02-01 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

I suggest that renaming 'extension' to 'option' (extensions + features) concept 
to be done in separate commit. There are a lot of places to change all over the 
place in clang.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95776/new/

https://reviews.llvm.org/D95776

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95778: [OpenCL] Introduce new language options for OpenCL keywords.

2021-02-01 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov created this revision.
azabaznov added reviewers: Anastasia, svenvh.
Herald added subscribers: dexonsmith, yaxunl.
Herald added a reviewer: jansvoboda11.
azabaznov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

OpenCL keywords 'pipe' and 'generic' are unconditionally
supported for OpenCL C 2.0 or in OpenCL C++ mode. In OpenCL C 3.0
these keywords are available if corresponding optional core
feature is supported.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95778

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaType.cpp


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2060,10 +2060,9 @@
   !PointeeType->isSamplerT() &&
   !PointeeType.hasAddressSpace())
 PointeeType = S.getASTContext().getAddrSpaceQualType(
-PointeeType,
-S.getLangOpts().OpenCLCPlusPlus || S.getLangOpts().OpenCLVersion == 200
-? LangAS::opencl_generic
-: LangAS::opencl_private);
+PointeeType, S.getLangOpts().OpenCLGenericKeyword
+ ? LangAS::opencl_generic
+ : LangAS::opencl_private);
   return PointeeType;
 }
 
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -3894,8 +3894,7 @@
   isInvalid = DS.SetTypeAltiVecBool(true, Loc, PrevSpec, DiagID, Policy);
   break;
 case tok::kw_pipe:
-  if (!getLangOpts().OpenCL || (getLangOpts().OpenCLVersion < 200 &&
-!getLangOpts().OpenCLCPlusPlus)) {
+  if (!getLangOpts().OpenCLPipeKeyword) {
 // OpenCL 2.0 defined this keyword. OpenCL 1.2 and earlier should
 // support the "pipe" word as identifier.
 Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
@@ -4017,8 +4016,7 @@
 case tok::kw___generic:
   // generic address space is introduced only in OpenCL v2.0
   // see OpenCL C Spec v2.0 s6.5.5
-  if (Actions.getLangOpts().OpenCLVersion < 200 &&
-  !Actions.getLangOpts().OpenCLCPlusPlus) {
+  if (!Actions.getLangOpts().OpenCLGenericKeyword) {
 DiagID = diag::err_opencl_unknown_type_specifier;
 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
 isInvalid = true;
@@ -5070,8 +5068,7 @@
   default: return false;
 
   case tok::kw_pipe:
-return (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) ||
-   getLangOpts().OpenCLCPlusPlus;
+return getLangOpts().OpenCLPipeKeyword;
 
   case tok::identifier:   // foo::bar
 // Unfortunate hack to support "Class.factoryMethod" notation.
@@ -5599,8 +5596,7 @@
   if (Kind == tok::star || Kind == tok::caret)
 return true;
 
-  if (Kind == tok::kw_pipe &&
-  ((Lang.OpenCL && Lang.OpenCLVersion >= 200) || Lang.OpenCLCPlusPlus))
+  if (Kind == tok::kw_pipe && Lang.OpenCLPipeKeyword)
 return true;
 
   if (!Lang.CPlusPlus)
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2098,6 +2098,9 @@
 Opts.ZVector = 0;
 Opts.setDefaultFPContractMode(LangOptions::FPM_On);
 Opts.OpenCLCPlusPlus = Opts.CPlusPlus;
+Opts.OpenCLPipeKeyword = Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200;
+Opts.OpenCLGenericKeyword =
+Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200;
 
 // Include default header file for OpenCL.
 if (Opts.IncludeDefaultHeader) {
Index: clang/include/clang/Basic/LangOptions.def
===
--- clang/include/clang/Basic/LangOptions.def
+++ clang/include/clang/Basic/LangOptions.def
@@ -215,6 +215,8 @@
 LANGOPT(OpenCLVersion , 32, 0, "OpenCL C version")
 LANGOPT(OpenCLCPlusPlus   , 1, 0, "C++ for OpenCL")
 LANGOPT(OpenCLCPlusPlusVersion , 32, 0, "C++ for OpenCL version")
+LANGOPT(OpenCLGenericKeyword, 1, 0, "OpenCL generic keyword")
+LANGOPT(OpenCLPipeKeyword   , 1, 0, "OpenCL pipe keyword")
 LANGOPT(NativeHalfType, 1, 0, "Native half type support")
 LANGOPT(NativeHalfArgsAndReturns, 1, 0, "Native half args and returns")
 LANGOPT(HalfArgsAndReturns, 1, 0, "half args and returns")


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2060,10 +2060,9 @@
   !PointeeType->isSamplerT() &&
   !PointeeType.hasAddressSpace())
 PointeeType = S.getASTContext().getAddrSpaceQualType(
-PointeeType,
-S.getLangOpts().OpenCLCPlusPlus || S.getLangOpts().OpenCLVersion == 200
-

[PATCH] D95776: [OpenCL] Add macro definitions of OpenCL C 3.0 features

2021-02-02 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 320708.
azabaznov added a comment.

Rebased


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95776/new/

https://reviews.llvm.org/D95776

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

Index: clang/test/SemaOpenCL/features.cl
===
--- /dev/null
+++ 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
Index: clang/lib/Headers/opencl-c.h
===
--- clang/lib/Headers/opencl-c.h
+++ 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_
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ 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:
 
 /**
Index: clang/lib/Basic/Targets.cpp
===
--- clang/lib/Basic/Targets.cpp
+++ 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");
 }
Index: clang/include/clang/Basic/OpenCLExtensions.def
===
--- clang/include/clang/Basic/OpenCLExtensions.def
+++ 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

[PATCH] D95778: [OpenCL] Introduce new language options for OpenCL keywords.

2021-02-02 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 320709.
azabaznov added a comment.

Rebased


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95778/new/

https://reviews.llvm.org/D95778

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaType.cpp


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2060,10 +2060,9 @@
   !PointeeType->isSamplerT() &&
   !PointeeType.hasAddressSpace())
 PointeeType = S.getASTContext().getAddrSpaceQualType(
-PointeeType,
-S.getLangOpts().OpenCLCPlusPlus || S.getLangOpts().OpenCLVersion == 200
-? LangAS::opencl_generic
-: LangAS::opencl_private);
+PointeeType, S.getLangOpts().OpenCLGenericKeyword
+ ? LangAS::opencl_generic
+ : LangAS::opencl_private);
   return PointeeType;
 }
 
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -3894,8 +3894,7 @@
   isInvalid = DS.SetTypeAltiVecBool(true, Loc, PrevSpec, DiagID, Policy);
   break;
 case tok::kw_pipe:
-  if (!getLangOpts().OpenCL || (getLangOpts().OpenCLVersion < 200 &&
-!getLangOpts().OpenCLCPlusPlus)) {
+  if (!getLangOpts().OpenCLPipeKeyword) {
 // OpenCL 2.0 defined this keyword. OpenCL 1.2 and earlier should
 // support the "pipe" word as identifier.
 Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
@@ -4017,8 +4016,7 @@
 case tok::kw___generic:
   // generic address space is introduced only in OpenCL v2.0
   // see OpenCL C Spec v2.0 s6.5.5
-  if (Actions.getLangOpts().OpenCLVersion < 200 &&
-  !Actions.getLangOpts().OpenCLCPlusPlus) {
+  if (!Actions.getLangOpts().OpenCLGenericKeyword) {
 DiagID = diag::err_opencl_unknown_type_specifier;
 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
 isInvalid = true;
@@ -5070,8 +5068,7 @@
   default: return false;
 
   case tok::kw_pipe:
-return (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) ||
-   getLangOpts().OpenCLCPlusPlus;
+return getLangOpts().OpenCLPipeKeyword;
 
   case tok::identifier:   // foo::bar
 // Unfortunate hack to support "Class.factoryMethod" notation.
@@ -5599,8 +5596,7 @@
   if (Kind == tok::star || Kind == tok::caret)
 return true;
 
-  if (Kind == tok::kw_pipe &&
-  ((Lang.OpenCL && Lang.OpenCLVersion >= 200) || Lang.OpenCLCPlusPlus))
+  if (Kind == tok::kw_pipe && Lang.OpenCLPipeKeyword)
 return true;
 
   if (!Lang.CPlusPlus)
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2092,6 +2092,9 @@
 Opts.ZVector = 0;
 Opts.setDefaultFPContractMode(LangOptions::FPM_On);
 Opts.OpenCLCPlusPlus = Opts.CPlusPlus;
+Opts.OpenCLPipeKeyword = Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200;
+Opts.OpenCLGenericKeyword =
+Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200;
 
 // Include default header file for OpenCL.
 if (Opts.IncludeDefaultHeader) {
Index: clang/include/clang/Basic/LangOptions.def
===
--- clang/include/clang/Basic/LangOptions.def
+++ clang/include/clang/Basic/LangOptions.def
@@ -215,6 +215,8 @@
 LANGOPT(OpenCLVersion , 32, 0, "OpenCL C version")
 LANGOPT(OpenCLCPlusPlus   , 1, 0, "C++ for OpenCL")
 LANGOPT(OpenCLCPlusPlusVersion , 32, 0, "C++ for OpenCL version")
+LANGOPT(OpenCLGenericKeyword, 1, 0, "OpenCL generic keyword")
+LANGOPT(OpenCLPipeKeyword   , 1, 0, "OpenCL pipe keyword")
 LANGOPT(NativeHalfType, 1, 0, "Native half type support")
 LANGOPT(NativeHalfArgsAndReturns, 1, 0, "Native half args and returns")
 LANGOPT(HalfArgsAndReturns, 1, 0, "half args and returns")


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2060,10 +2060,9 @@
   !PointeeType->isSamplerT() &&
   !PointeeType.hasAddressSpace())
 PointeeType = S.getASTContext().getAddrSpaceQualType(
-PointeeType,
-S.getLangOpts().OpenCLCPlusPlus || S.getLangOpts().OpenCLVersion == 200
-? LangAS::opencl_generic
-: LangAS::opencl_private);
+PointeeType, S.getLangOpts().OpenCLGenericKeyword
+ ? LangAS::opencl_generic
+ : LangAS::opencl_private);
   return PointeeType;
 }
 
Index: clang/lib/Parse/ParseDecl.cpp
===

[PATCH] D95776: [OpenCL] Add macro definitions of OpenCL C 3.0 features

2021-02-02 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 320710.
azabaznov added a comment.

Rebased one more time


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95776/new/

https://reviews.llvm.org/D95776

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

Index: clang/test/SemaOpenCL/features.cl
===
--- /dev/null
+++ 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
Index: clang/lib/Headers/opencl-c.h
===
--- clang/lib/Headers/opencl-c.h
+++ 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_
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ 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:
 
 /**
Index: clang/lib/Basic/Targets.cpp
===
--- clang/lib/Basic/Targets.cpp
+++ 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");
 }
Index: clang/include/clang/Basic/OpenCLExtensions.def
===
--- clang/include/clang/Basic/OpenCLExtensions.def
+++ 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_wr

[PATCH] D95776: [OpenCL] Add macro definitions of OpenCL C 3.0 features

2021-02-02 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/lib/Basic/Targets.cpp:743
+  // Assume compiling for FULL profile
+  Builder.defineMacro("__opencl_c_int64");
 }

Anastasia wrote:
> Btw we could add the other feature macros for earlier versions too but I 
> guess it makes code more complicated?
Yes, this will complicate things: we decided to generate a warning if any of 
core features is unsupported, right? So making OpenCL C 3.0 features as core in 
OpenCL C 2.0 will result in this kind of warning; distinguishing these features 
among the set of core functionality may require workarounds in clang, so let's 
keep them in headers only for OpenCL C 2.0.



Comment at: clang/lib/Headers/opencl-c.h:17161
+#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200)
+#undef __opencl_c_pipes
+#undef __opencl_c_generic_address_space

svenvh wrote:
> Anastasia wrote:
> > Looping in @svenvh  - I don't mind if we define those macros in headers for 
> > OpenCL 2.0. The only concern is that if we `undef` them here we will end up 
> > with different behavior between `-finclude-default-header` and 
> > `-fdeclare-opencl-builtins`. I would suggest not to `undef` them because it 
> > is better if we have coherency. Alternatively we could also add a third 
> > header with undefs that can be included at the end for both but it seems to 
> > make things even more complicated.
> > 
> > FYI `__opencl_c_int64` is already added for all OpenCL versions.
> > The only concern is that if we undef them here we will end up with 
> > different behavior between -finclude-default-header and 
> > -fdeclare-opencl-builtins
> 
> This is a valid point.  Doing the undefs only in `opencl-c.h` will lead to a 
> problem similar to https://reviews.llvm.org/D91429 .
> 
> A third header just for the undefs sounds like a bit of an overkill indeed, 
> although having duplication isn't great either.  Not sure what's best to be 
> honest.
My idea was just to temporary define features for built-ins and enums 
definitions as this is the only place where these macros may be useful for 
OpenCL C 2.0. However, I don't have any strong concerns if these macros will 
remain defined.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95776/new/

https://reviews.llvm.org/D95776

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95778: [OpenCL] Introduce new language options for OpenCL keywords.

2021-02-02 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

In D95778#2536266 , @Anastasia wrote:

>> LGTM, but perhaps you can add a test that has each keyword disabled?
>
> FYI we currently already test that `pipe` and `generic` are valid for OpenCL 
> 2.0 and invalid for OpenCL < 2.0. Or do you mean different kind of tests? In 
> OpenCL 3.0 we will have to set the new `LangOpts` fields based on the values 
> of `OpenCLOptions`  but my guess is that is going to be added in the 
> subsequent patches...

Yes, I believe there are tests already for earlier versions. Should I mark this 
change as NFC?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95778/new/

https://reviews.llvm.org/D95778

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95778: [OpenCL] Introduce new language options for OpenCL keywords.

2021-02-02 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/include/clang/Basic/LangOptions.def:218
 LANGOPT(OpenCLCPlusPlusVersion , 32, 0, "C++ for OpenCL version")
+LANGOPT(OpenCLGenericKeyword, 1, 0, "OpenCL generic keyword")
+LANGOPT(OpenCLPipeKeyword   , 1, 0, "OpenCL pipe keyword")

Anastasia wrote:
> Normally we use just a name of the feature, so perhaps:
> 
> OpenCLGenericKeyword -> OpenCLGenericAddressSpace
> OpenCLPipeKeyword -> OpenCLPipe
Ok, will change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95778/new/

https://reviews.llvm.org/D95778

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95778: [OpenCL] Introduce new language options for OpenCL keywords.

2021-02-04 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 321348.
azabaznov added a comment.

Renamed language options and adjusted comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95778/new/

https://reviews.llvm.org/D95778

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaType.cpp


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2060,10 +2060,9 @@
   !PointeeType->isSamplerT() &&
   !PointeeType.hasAddressSpace())
 PointeeType = S.getASTContext().getAddrSpaceQualType(
-PointeeType,
-S.getLangOpts().OpenCLCPlusPlus || S.getLangOpts().OpenCLVersion == 200
-? LangAS::opencl_generic
-: LangAS::opencl_private);
+PointeeType, S.getLangOpts().OpenCLGenericAddressSpace
+ ? LangAS::opencl_generic
+ : LangAS::opencl_private);
   return PointeeType;
 }
 
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -3896,8 +3896,8 @@
 case tok::kw_pipe:
   if (!getLangOpts().OpenCL || (getLangOpts().OpenCLVersion < 200 &&
 !getLangOpts().OpenCLCPlusPlus)) {
-// OpenCL 2.0 defined this keyword. OpenCL 1.2 and earlier should
-// support the "pipe" word as identifier.
+// OpenCL 2.0 and later define this keyword. OpenCL 1.2 and earlier
+// should support the "pipe" word as identifier.
 Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
 goto DoneWithDeclSpec;
   }
@@ -4017,8 +4017,7 @@
 case tok::kw___generic:
   // generic address space is introduced only in OpenCL v2.0
   // see OpenCL C Spec v2.0 s6.5.5
-  if (Actions.getLangOpts().OpenCLVersion < 200 &&
-  !Actions.getLangOpts().OpenCLCPlusPlus) {
+  if (!Actions.getLangOpts().OpenCLGenericAddressSpace) {
 DiagID = diag::err_opencl_unknown_type_specifier;
 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
 isInvalid = true;
@@ -5070,8 +5069,7 @@
   default: return false;
 
   case tok::kw_pipe:
-return (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) ||
-   getLangOpts().OpenCLCPlusPlus;
+return getLangOpts().OpenCLPipe;
 
   case tok::identifier:   // foo::bar
 // Unfortunate hack to support "Class.factoryMethod" notation.
@@ -5599,8 +5597,7 @@
   if (Kind == tok::star || Kind == tok::caret)
 return true;
 
-  if (Kind == tok::kw_pipe &&
-  ((Lang.OpenCL && Lang.OpenCLVersion >= 200) || Lang.OpenCLCPlusPlus))
+  if (Kind == tok::kw_pipe && Lang.OpenCLPipe)
 return true;
 
   if (!Lang.CPlusPlus)
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2092,6 +2092,9 @@
 Opts.ZVector = 0;
 Opts.setDefaultFPContractMode(LangOptions::FPM_On);
 Opts.OpenCLCPlusPlus = Opts.CPlusPlus;
+Opts.OpenCLPipe = Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200;
+Opts.OpenCLGenericAddressSpace =
+Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200;
 
 // Include default header file for OpenCL.
 if (Opts.IncludeDefaultHeader) {
Index: clang/include/clang/Basic/LangOptions.def
===
--- clang/include/clang/Basic/LangOptions.def
+++ clang/include/clang/Basic/LangOptions.def
@@ -215,6 +215,8 @@
 LANGOPT(OpenCLVersion , 32, 0, "OpenCL C version")
 LANGOPT(OpenCLCPlusPlus   , 1, 0, "C++ for OpenCL")
 LANGOPT(OpenCLCPlusPlusVersion , 32, 0, "C++ for OpenCL version")
+LANGOPT(OpenCLGenericAddressSpace, 1, 0, "OpenCL generic keyword")
+LANGOPT(OpenCLPipe   , 1, 0, "OpenCL pipe keyword")
 LANGOPT(NativeHalfType, 1, 0, "Native half type support")
 LANGOPT(NativeHalfArgsAndReturns, 1, 0, "Native half args and returns")
 LANGOPT(HalfArgsAndReturns, 1, 0, "half args and returns")


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2060,10 +2060,9 @@
   !PointeeType->isSamplerT() &&
   !PointeeType.hasAddressSpace())
 PointeeType = S.getASTContext().getAddrSpaceQualType(
-PointeeType,
-S.getLangOpts().OpenCLCPlusPlus || S.getLangOpts().OpenCLVersion == 200
-? LangAS::opencl_generic
-: LangAS::opencl_private);
+PointeeType, S.getLangOpts().OpenCLGenericAddressSpace
+ ? LangAS::opencl_generic
+ : LangAS::opencl_private);
   return Po

[PATCH] D95776: [OpenCL] Add macro definitions of OpenCL C 3.0 features

2021-02-04 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 321385.
azabaznov added a comment.

Features remain defined in header for OpenCL C 2.0; adjusted the test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95776/new/

https://reviews.llvm.org/D95776

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

Index: clang/test/SemaOpenCL/features.cl
===
--- /dev/null
+++ 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
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ 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:
 
 /**
Index: clang/lib/Basic/Targets.cpp
===
--- clang/lib/Basic/Targets.cpp
+++ 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");
 }
Index: clang/include/clang/Basic/OpenCLExtensions.def
===
--- clang/include/clang/Basic/OpenCLExtensions.def
+++ 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_

[PATCH] D95776: [OpenCL] Add macro definitions of OpenCL C 3.0 features

2021-02-04 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/test/SemaOpenCL/features.cl:1
+// 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

Anastasia wrote:
> since `-cl-ext=-all` doesn't affect the header functionality I suggest to 
> drop it and use one one line with `-finclude-default-header`. Parsing time 
> with this header is 300x slower so we should minimise its use in tests to 
> avoid negative impact on clang testing.
> 
> Would it make sense to add a line without the header with `-cl-std=CL2.0` 
> or/and `-cl-std=CL1.2` to check that there are indeed no macros defined?
> Would it make sense to add a line without the header with -cl-std=CL2.0 
> or/and -cl-std=CL1.2 to check that there are indeed no macros defined?

I think this makes no sense since we are planning to use these macros only 
internally for headers. Or if it's planned to include `opencl-c-base.h` by 
default, then this kind of lines can be eliminated for < 3.0 at all.



Comment at: clang/test/SemaOpenCL/features.cl:14
+#ifndef __opencl_c_int64
+#error "Macro __opencl_c_int64 should be defined"
+#endif

Anastasia wrote:
> Do you want to add -verify and expected-no-diagnostics directive for this or 
> just change to FileCheck too?
Ok, I think I'll use FileCheck to be consistent.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95776/new/

https://reviews.llvm.org/D95776

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95776: [OpenCL] Add macro definitions of OpenCL C 3.0 features

2021-02-04 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 321425.
azabaznov added a comment.

Adjusted test one more time: moved header functionality into separate test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95776/new/

https://reviews.llvm.org/D95776

Files:
  clang/include/clang/Basic/OpenCLExtensions.def
  clang/lib/Basic/Targets.cpp
  clang/lib/Headers/opencl-c-base.h
  clang/test/Headers/opencl-c-header.cl
  clang/test/SemaOpenCL/features.cl

Index: clang/test/SemaOpenCL/features.cl
===
--- /dev/null
+++ clang/test/SemaOpenCL/features.cl
@@ -0,0 +1,48 @@
+// 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
+// RUN: %clang_cc1 -triple r600-unknown-unknown %s -E -dM -o - -x cl -cl-std=CL3.0 -cl-ext=+all \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=FEATURES
+
+// For OpenCL C 2.0 feature macros are defined only in header, so test that earlier OpenCL
+// versions don't define feature macros accidentally and CL2.0 don't define them without header
+// RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=CL1.1 \
+// 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=CL1.2 \
+// 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=CL2.0 \
+// 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=CLC++ \
+// 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: #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_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_device_enqueue
+// NO-FEATURES-NOT: __opencl_c_fp64
+// 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
+// NO-FEATURES-NOT: __opencl_c_subgroups
Index: clang/test/Headers/opencl-c-header.cl
===
--- clang/test/Headers/opencl-c-header.cl
+++ clang/test/Headers/opencl-c-header.cl
@@ -151,4 +151,88 @@
 
 #endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
 
+// OpenCL C features.
+#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200)
+
+#ifndef  __opencl_c_pipes
+#error "Feature macro __opencl_c_pipes should be defined"
+#endif
+#ifndef __opencl_c_generic_address_space
+#error "Feature macro __opencl_c_generic_address_space should be defined"
+#endif
+#ifndef __opencl_c_work_group_collective_functions
+#error "Feature macro __opencl_c_work_group_collective_functions should be defined"
+#endif
+#ifndef __opencl_c_atomic_order_acq_rel
+#error "Feature macro __opencl_c_atomic_order_acq_rel should be defined"
+#endif
+#ifndef __opencl_c_atomic_order_seq_cst
+#error "Feature macro __opencl_c_atomic_order_seq_cst should be defined"
+#endif
+#ifndef __opencl_c_atomic_scope_device
+#error "Feature macro __opencl_c_atomic_scope_device should be defined"
+#endif
+#ifndef __opencl_c_atomic_scope_all_devices
+#error "Feature macro __opencl_c_atomic_scope_all_devices should be defined"
+#endif
+#ifndef __opencl_c_device_enqueue
+#error "Feature macro __opencl_c_device_enqueue should be defined"
+#endif
+#ifndef __opencl_c_read_write_images
+#error "Feature macro __opencl_c_read_write_images should be defined"
+#endif
+#ifndef __opencl_c_program_scope_global_variables
+#error "Feature macro __opencl_c_p

[PATCH] D95778: [OpenCL] Introduce new language options for OpenCL keywords.

2021-02-05 Thread Anton Zabaznov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa5b627aa4fe7: [OpenCL] Introduce new language options for 
OpenCL keywords. (authored by azabaznov).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95778/new/

https://reviews.llvm.org/D95778

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaType.cpp


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2060,10 +2060,9 @@
   !PointeeType->isSamplerT() &&
   !PointeeType.hasAddressSpace())
 PointeeType = S.getASTContext().getAddrSpaceQualType(
-PointeeType,
-S.getLangOpts().OpenCLCPlusPlus || S.getLangOpts().OpenCLVersion == 200
-? LangAS::opencl_generic
-: LangAS::opencl_private);
+PointeeType, S.getLangOpts().OpenCLGenericAddressSpace
+ ? LangAS::opencl_generic
+ : LangAS::opencl_private);
   return PointeeType;
 }
 
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -3896,8 +3896,8 @@
 case tok::kw_pipe:
   if (!getLangOpts().OpenCL || (getLangOpts().OpenCLVersion < 200 &&
 !getLangOpts().OpenCLCPlusPlus)) {
-// OpenCL 2.0 defined this keyword. OpenCL 1.2 and earlier should
-// support the "pipe" word as identifier.
+// OpenCL 2.0 and later define this keyword. OpenCL 1.2 and earlier
+// should support the "pipe" word as identifier.
 Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
 goto DoneWithDeclSpec;
   }
@@ -4017,8 +4017,7 @@
 case tok::kw___generic:
   // generic address space is introduced only in OpenCL v2.0
   // see OpenCL C Spec v2.0 s6.5.5
-  if (Actions.getLangOpts().OpenCLVersion < 200 &&
-  !Actions.getLangOpts().OpenCLCPlusPlus) {
+  if (!Actions.getLangOpts().OpenCLGenericAddressSpace) {
 DiagID = diag::err_opencl_unknown_type_specifier;
 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
 isInvalid = true;
@@ -5070,8 +5069,7 @@
   default: return false;
 
   case tok::kw_pipe:
-return (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) ||
-   getLangOpts().OpenCLCPlusPlus;
+return getLangOpts().OpenCLPipe;
 
   case tok::identifier:   // foo::bar
 // Unfortunate hack to support "Class.factoryMethod" notation.
@@ -5599,8 +5597,7 @@
   if (Kind == tok::star || Kind == tok::caret)
 return true;
 
-  if (Kind == tok::kw_pipe &&
-  ((Lang.OpenCL && Lang.OpenCLVersion >= 200) || Lang.OpenCLCPlusPlus))
+  if (Kind == tok::kw_pipe && Lang.OpenCLPipe)
 return true;
 
   if (!Lang.CPlusPlus)
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2391,6 +2391,9 @@
 Opts.ZVector = 0;
 Opts.setDefaultFPContractMode(LangOptions::FPM_On);
 Opts.OpenCLCPlusPlus = Opts.CPlusPlus;
+Opts.OpenCLPipe = Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200;
+Opts.OpenCLGenericAddressSpace =
+Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200;
 
 // Include default header file for OpenCL.
 if (Opts.IncludeDefaultHeader) {
Index: clang/include/clang/Basic/LangOptions.def
===
--- clang/include/clang/Basic/LangOptions.def
+++ clang/include/clang/Basic/LangOptions.def
@@ -215,6 +215,8 @@
 LANGOPT(OpenCLVersion , 32, 0, "OpenCL C version")
 LANGOPT(OpenCLCPlusPlus   , 1, 0, "C++ for OpenCL")
 LANGOPT(OpenCLCPlusPlusVersion , 32, 0, "C++ for OpenCL version")
+LANGOPT(OpenCLGenericAddressSpace, 1, 0, "OpenCL generic keyword")
+LANGOPT(OpenCLPipe   , 1, 0, "OpenCL pipe keyword")
 LANGOPT(NativeHalfType, 1, 0, "Native half type support")
 LANGOPT(NativeHalfArgsAndReturns, 1, 0, "Native half args and returns")
 LANGOPT(HalfArgsAndReturns, 1, 0, "half args and returns")


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2060,10 +2060,9 @@
   !PointeeType->isSamplerT() &&
   !PointeeType.hasAddressSpace())
 PointeeType = S.getASTContext().getAddrSpaceQualType(
-PointeeType,
-S.getLangOpts().OpenCLCPlusPlus || S.getLangOpts().OpenCLVersion == 200
-? LangAS::opencl_generic
-: LangAS::opencl_private);
+PointeeType, S.getLangOpts().OpenCLGenericAdd

[PATCH] D95776: [OpenCL] Add macro definitions of OpenCL C 3.0 features

2021-02-05 Thread Anton Zabaznov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd88c55ab95c9: [OpenCL] Add macro definitions of OpenCL C 3.0 
features (authored by azabaznov).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95776/new/

https://reviews.llvm.org/D95776

Files:
  clang/include/clang/Basic/OpenCLExtensions.def
  clang/lib/Basic/Targets.cpp
  clang/lib/Headers/opencl-c-base.h
  clang/test/Headers/opencl-c-header.cl
  clang/test/SemaOpenCL/features.cl

Index: clang/test/SemaOpenCL/features.cl
===
--- /dev/null
+++ clang/test/SemaOpenCL/features.cl
@@ -0,0 +1,48 @@
+// 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
+// RUN: %clang_cc1 -triple r600-unknown-unknown %s -E -dM -o - -x cl -cl-std=CL3.0 -cl-ext=+all \
+// RUN:   | FileCheck -match-full-lines %s  --check-prefix=FEATURES
+
+// For OpenCL C 2.0 feature macros are defined only in header, so test that earlier OpenCL
+// versions don't define feature macros accidentally and CL2.0 don't define them without header
+// RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=CL1.1 \
+// 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=CL1.2 \
+// 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=CL2.0 \
+// 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=CLC++ \
+// 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: #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_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_device_enqueue
+// NO-FEATURES-NOT: __opencl_c_fp64
+// 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
+// NO-FEATURES-NOT: __opencl_c_subgroups
Index: clang/test/Headers/opencl-c-header.cl
===
--- clang/test/Headers/opencl-c-header.cl
+++ clang/test/Headers/opencl-c-header.cl
@@ -151,4 +151,88 @@
 
 #endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
 
+// OpenCL C features.
+#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200)
+
+#ifndef  __opencl_c_pipes
+#error "Feature macro __opencl_c_pipes should be defined"
+#endif
+#ifndef __opencl_c_generic_address_space
+#error "Feature macro __opencl_c_generic_address_space should be defined"
+#endif
+#ifndef __opencl_c_work_group_collective_functions
+#error "Feature macro __opencl_c_work_group_collective_functions should be defined"
+#endif
+#ifndef __opencl_c_atomic_order_acq_rel
+#error "Feature macro __opencl_c_atomic_order_acq_rel should be defined"
+#endif
+#ifndef __opencl_c_atomic_order_seq_cst
+#error "Feature macro __opencl_c_atomic_order_seq_cst should be defined"
+#endif
+#ifndef __opencl_c_atomic_scope_device
+#error "Feature macro __opencl_c_atomic_scope_device should be defined"
+#endif
+#ifndef __opencl_c_atomic_scope_all_devices
+#error "Feature macro __opencl_c_atomic_scope_all_devices should be defined"
+#endif
+#ifndef __opencl_c_device_enqueue
+#error "Feature macro __opencl_c_device_enqueue should be defined"
+#endif
+#ifndef __opencl_c_read_write_images
+#error "Feature macro __opencl_c_read_write_images should be defined"
+

[PATCH] D96178: [OpenCL] Create VoidPtrTy with generic AS in C++ for OpenCL mode

2021-02-05 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov created this revision.
azabaznov added reviewers: svenvh, Anastasia.
Herald added a subscriber: yaxunl.
azabaznov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change affects 'SemaOpenCLCXX/newdelete.cl' test,
thus the patch contains adjustments in types validation of
operators new and delete


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96178

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl


Index: clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -triple spir -cl-std=clc++ -emit-llvm -O0 -o - | 
FileCheck %s
+
+typedef __SIZE_TYPE__ size_t;
+
+class A {
+public:
+  void* operator new(size_t);
+  void operator delete(void *ptr);
+};
+
+void test_new_delete(A **a) {
+// CHECK: %{{.*}} = call spir_func i8 addrspace(4)* @_ZNU3AS41AnwEj(i32 {{.*}})
+*a = new A;
+// CHECK: call spir_func void @_ZNU3AS41AdlEPU3AS4v(i8 addrspace(4)* {{.*}})
+delete *a;
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15277,11 +15277,18 @@
   QualType ResultType =
   FnDecl->getType()->castAs()->getReturnType();
 
-  // The operator is valid on any address space for OpenCL.
   if (SemaRef.getLangOpts().OpenCLCPlusPlus) {
+// The operator is valid on any address space for OpenCL.
+// Drop address space from actual and expected result types.
 if (auto *PtrTy = ResultType->getAs()) {
   ResultType = RemoveAddressSpaceFromPtr(SemaRef, PtrTy);
 }
+
+if (CanQual ExpectedPtrTy =
+ExpectedResultType->getAs()) {
+  ExpectedResultType = SemaRef.Context.getCanonicalType(
+  RemoveAddressSpaceFromPtr(SemaRef, ExpectedPtrTy->getTypePtr()));
+}
   }
 
   // Check that the result type is what we expect.
@@ -15311,10 +15318,17 @@
   QualType FirstParamType = FnDecl->getParamDecl(0)->getType();
   if (SemaRef.getLangOpts().OpenCLCPlusPlus) {
 // The operator is valid on any address space for OpenCL.
+// Drop address space from actual and expected first parameter types.
 if (auto *PtrTy =
 FnDecl->getParamDecl(0)->getType()->getAs()) {
   FirstParamType = RemoveAddressSpaceFromPtr(SemaRef, PtrTy);
 }
+
+if (CanQual ExpectedPtrTy =
+ExpectedFirstParamType->getAs()) {
+  ExpectedFirstParamType = SemaRef.Context.getCanonicalType(
+  RemoveAddressSpaceFromPtr(SemaRef, ExpectedPtrTy->getTypePtr()));
+}
   }
 
   // Check that the first parameter type is what we expect.
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -1445,7 +1445,7 @@
   ObjCSuperType = QualType();
 
   // void * type
-  if (LangOpts.OpenCLVersion >= 200) {
+  if (LangOpts.OpenCLGenericAddressSpace) {
 auto Q = VoidTy.getQualifiers();
 Q.setAddressSpace(LangAS::opencl_generic);
 VoidPtrTy = getPointerType(getCanonicalType(


Index: clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -triple spir -cl-std=clc++ -emit-llvm -O0 -o - | FileCheck %s
+
+typedef __SIZE_TYPE__ size_t;
+
+class A {
+public:
+  void* operator new(size_t);
+  void operator delete(void *ptr);
+};
+
+void test_new_delete(A **a) {
+// CHECK: %{{.*}} = call spir_func i8 addrspace(4)* @_ZNU3AS41AnwEj(i32 {{.*}})
+*a = new A;
+// CHECK: call spir_func void @_ZNU3AS41AdlEPU3AS4v(i8 addrspace(4)* {{.*}})
+delete *a;
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15277,11 +15277,18 @@
   QualType ResultType =
   FnDecl->getType()->castAs()->getReturnType();
 
-  // The operator is valid on any address space for OpenCL.
   if (SemaRef.getLangOpts().OpenCLCPlusPlus) {
+// The operator is valid on any address space for OpenCL.
+// Drop address space from actual and expected result types.
 if (auto *PtrTy = ResultType->getAs()) {
   ResultType = RemoveAddressSpaceFromPtr(SemaRef, PtrTy);
 }
+
+if (CanQual ExpectedPtrTy =
+ExpectedResultType->getAs()) {
+  ExpectedResultType = SemaRef.Context.getCanonicalType(
+  RemoveAddressSpaceFromPtr(SemaRef, ExpectedPtrTy->getTypePtr()));
+}
   }
 
   // Check that the result type is what we expect.
@@ -15311,10 +15318,17 @@
   QualType FirstParamType = FnDecl->getParamDecl(0)->

[PATCH] D110036: [TargetInfo][LangOpts] Refactor target info and language options adjustment.

2021-09-19 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov created this revision.
azabaznov added reviewers: aaron.ballman, Anastasia, svenvh.
Herald added subscribers: dexonsmith, kerbowa, sunfish, kbarton, 
jgravelle-google, sbc100, nhaehnle, jvesely, nemanjai, dschuff.
azabaznov requested review of this revision.
Herald added subscribers: cfe-commits, aheejin.
Herald added a project: clang.

- Function CreateTargetInfo() has an access to language options which makes 
target immutable after creation without modification of language options 
themselves. Target specific hook TargetInfo::adjustAccordingToLangOpts() can be 
used if such modification depends on certain target.

- Introduce LangOptions::adjustAccordingToTI() to apply changes to language 
options based on target info (also without modification of target info). This 
also involves adding of some hooks (hasAtomics() / hasAltivec() as this options 
are used in PPC and WebAssembly in original TargetInfo::adjust()) which 
potentially can be reused.

- Validation of OpenCL target is in CreateTargetInfo() as language options are 
available at that point.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110036

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/LangOptions.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/ChainedIncludesSource.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Interpreter/Interpreter.cpp
  clang/tools/clang-import-test/clang-import-test.cpp
  clang/unittests/Analysis/MacroExpansionContextTest.cpp
  clang/unittests/Basic/SourceManagerTest.cpp
  clang/unittests/CodeGen/TestCompiler.h
  clang/unittests/Lex/HeaderSearchTest.cpp
  clang/unittests/Lex/LexerTest.cpp
  clang/unittests/Lex/PPCallbacksTest.cpp
  clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp

Index: clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
===
--- clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
+++ clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
@@ -36,7 +36,7 @@
   TargetOpts(new TargetOptions)
   {
 TargetOpts->Triple = "x86_64-apple-darwin11.1.0";
-Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
+Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts, LangOpts);
   }
 
   FileSystemOptions FileMgrOpts;
Index: clang/unittests/Lex/PPCallbacksTest.cpp
===
--- clang/unittests/Lex/PPCallbacksTest.cpp
+++ clang/unittests/Lex/PPCallbacksTest.cpp
@@ -136,7 +136,7 @@
 Diags(DiagID, DiagOpts.get(), new IgnoringDiagConsumer()),
 SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions()) {
 TargetOpts->Triple = "x86_64-apple-darwin11.1.0";
-Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
+Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts, LangOpts);
   }
 
   IntrusiveRefCntPtr InMemoryFileSystem;
Index: clang/unittests/Lex/LexerTest.cpp
===
--- clang/unittests/Lex/LexerTest.cpp
+++ clang/unittests/Lex/LexerTest.cpp
@@ -43,7 +43,7 @@
   TargetOpts(new TargetOptions)
   {
 TargetOpts->Triple = "x86_64-apple-darwin11.1.0";
-Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
+Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts, LangOpts);
   }
 
   std::unique_ptr CreatePP(StringRef Source,
Index: clang/unittests/Lex/HeaderSearchTest.cpp
===
--- clang/unittests/Lex/HeaderSearchTest.cpp
+++ clang/unittests/Lex/HeaderSearchTest.cpp
@@ -34,7 +34,7 @@
 Search(std::make_shared(), SourceMgr, Diags,
LangOpts, Target.get()) {
 TargetOpts->Triple = "x86_64-apple-darwin11.1.0";
-Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
+Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts, LangOpts);
   }
 
   void addSearchDir(llvm::StringRef Dir) {
Index: clang/unittests/CodeGen/TestCompiler.h
===
--- clang/unittests/CodeGen/TestCompiler.h
+++ clang/unittests/CodeGen/TestCompiler.h
@@ -45,7 +45,8 @@
 compiler.getTargetOpts().Triple = Tr.getTriple();
 compiler.setTarget(clang::TargetInfo::CreateTargetInfo(
 compiler.getDiagnostics(),
-std::make_shared(compiler.getTargetOpts(;
+std::make_shared(compiler.getTargetOpts()),
+compiler.getLangOpts()));
 
 const clang::TargetInfo &TInfo = compiler.getTarget();
 PtrSize = TInfo.getPointerWidth(0) / 8;
Index: clang/unittests/Basic/SourceManagerTest.

[PATCH] D96178: [OpenCL] Create VoidPtrTy with generic AS in C++ for OpenCL mode

2021-02-10 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

Thanks for review. Just to be clear: can I proceed with this? Or we should 
discuss it first? As I see possible this change can be abandoned after 
discussion.

Moreover,  I see nothing about address space of void pointer in OpenCL C spec. 
For example (OpenCL C 2.2, Clause 6.3.2.3 - Pointers, replace the first two 
paragraphs with the following paragraphs):

//A pointer to void in any address space may be converted to or from a pointer 
to any incomplete or
object type. A pointer to any incomplete or object type in some address space 
may be converted to a
pointer to void in an enclosing address space and back again; the result shall 
compare equal to the
original pointer.//

Do I understand correctly that this means void pointer is not necessarily 
points to generic AS?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96178/new/

https://reviews.llvm.org/D96178

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96178: [OpenCL] Create VoidPtrTy with generic AS in C++ for OpenCL mode

2021-02-12 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 323421.
azabaznov added a comment.

Rewrote 'RemoveAddressSpaceFromPtr' to return canonical type


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96178/new/

https://reviews.llvm.org/D96178

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl


Index: clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -triple spir -cl-std=clc++ -emit-llvm -O0 -o - | 
FileCheck %s
+
+typedef __SIZE_TYPE__ size_t;
+
+class A {
+public:
+  void* operator new(size_t);
+  void operator delete(void *ptr);
+};
+
+void test_new_delete(A **a) {
+// CHECK: %{{.*}} = call spir_func i8 addrspace(4)* @_ZNU3AS41AnwEj(i32 {{.*}})
+*a = new A;
+// CHECK: call spir_func void @_ZNU3AS41AdlEPU3AS4v(i8 addrspace(4)* {{.*}})
+delete *a;
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15261,11 +15261,13 @@
   return false;
 }
 
-static QualType
-RemoveAddressSpaceFromPtr(Sema &SemaRef, const PointerType *PtrTy) {
-  QualType QTy = PtrTy->getPointeeType();
-  QTy = SemaRef.Context.removeAddrSpaceQualType(QTy);
-  return SemaRef.Context.getPointerType(QTy);
+static CanQualType RemoveAddressSpaceFromPtr(Sema &SemaRef,
+ const PointerType *PtrTy) {
+  auto &Ctx = SemaRef.Context;
+  Qualifiers PtrQuals = PtrTy->getPointeeType().getQualifiers();
+  PtrQuals.removeAddressSpace();
+  return Ctx.getPointerType(Ctx.getCanonicalType(Ctx.getQualifiedType(
+  PtrTy->getPointeeType().getUnqualifiedType(), PtrQuals)));
 }
 
 static inline bool
@@ -15277,11 +15279,14 @@
   QualType ResultType =
   FnDecl->getType()->castAs()->getReturnType();
 
-  // The operator is valid on any address space for OpenCL.
   if (SemaRef.getLangOpts().OpenCLCPlusPlus) {
-if (auto *PtrTy = ResultType->getAs()) {
+// The operator is valid on any address space for OpenCL.
+// Drop address space from actual and expected result types.
+if (auto *PtrTy = ResultType->getAs())
   ResultType = RemoveAddressSpaceFromPtr(SemaRef, PtrTy);
-}
+
+if (auto ExpectedPtrTy = ExpectedResultType->getAs())
+  ExpectedResultType = RemoveAddressSpaceFromPtr(SemaRef, ExpectedPtrTy);
   }
 
   // Check that the result type is what we expect.
@@ -15311,10 +15316,13 @@
   QualType FirstParamType = FnDecl->getParamDecl(0)->getType();
   if (SemaRef.getLangOpts().OpenCLCPlusPlus) {
 // The operator is valid on any address space for OpenCL.
-if (auto *PtrTy =
-FnDecl->getParamDecl(0)->getType()->getAs()) {
+// Drop address space from actual and expected first parameter types.
+if (auto *PtrTy = FnDecl->getParamDecl(0)->getType()->getAs())
   FirstParamType = RemoveAddressSpaceFromPtr(SemaRef, PtrTy);
-}
+
+if (auto ExpectedPtrTy = ExpectedFirstParamType->getAs())
+  ExpectedFirstParamType =
+  RemoveAddressSpaceFromPtr(SemaRef, ExpectedPtrTy);
   }
 
   // Check that the first parameter type is what we expect.
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -1445,7 +1445,7 @@
   ObjCSuperType = QualType();
 
   // void * type
-  if (LangOpts.OpenCLVersion >= 200) {
+  if (LangOpts.OpenCLGenericAddressSpace) {
 auto Q = VoidTy.getQualifiers();
 Q.setAddressSpace(LangAS::opencl_generic);
 VoidPtrTy = getPointerType(getCanonicalType(


Index: clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -triple spir -cl-std=clc++ -emit-llvm -O0 -o - | FileCheck %s
+
+typedef __SIZE_TYPE__ size_t;
+
+class A {
+public:
+  void* operator new(size_t);
+  void operator delete(void *ptr);
+};
+
+void test_new_delete(A **a) {
+// CHECK: %{{.*}} = call spir_func i8 addrspace(4)* @_ZNU3AS41AnwEj(i32 {{.*}})
+*a = new A;
+// CHECK: call spir_func void @_ZNU3AS41AdlEPU3AS4v(i8 addrspace(4)* {{.*}})
+delete *a;
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15261,11 +15261,13 @@
   return false;
 }
 
-static QualType
-RemoveAddressSpaceFromPtr(Sema &SemaRef, const PointerType *PtrTy) {
-  QualType QTy = PtrTy->getPointeeType();
-  QTy = SemaRef.Context.removeAddrSpaceQualType(QTy);
-  return SemaRef.Context.getPointerType(QTy);
+static CanQualType RemoveAddressSpaceFromPtr(Se

[PATCH] D96178: [OpenCL] Create VoidPtrTy with generic AS in C++ for OpenCL mode

2021-02-12 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov marked an inline comment as done.
azabaznov added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:15289
+ExpectedResultType->getAs()) {
+  ExpectedResultType = SemaRef.Context.getCanonicalType(
+  RemoveAddressSpaceFromPtr(SemaRef, ExpectedPtrTy->getTypePtr()));

Anastasia wrote:
> FYI I think `ExpectedResultType` is going to be in always in the canonical 
> form here by the way it is constructed so `getCanonicalType` should be 
> redundant.
> 
> 
Not sure if I understand this one, because `QualType` can't be cast to 
`CanQualType` so I think `getCanonicalType()` is needed. But I tried to unify 
existing logic and rewrote `RemoveAddressSpaceFromPtr()` to return 
`CanQualType` as it can be implicitly cast to `QualType`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96178/new/

https://reviews.llvm.org/D96178

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96524: [OpenCL] Add support of OpenCL C 3.0 __opencl_c_fp64

2021-02-15 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/include/clang/Basic/OpenCLOptions.h:157
+  // Is OpenCL C feature (OpenCL C 3.0, 6.2.1. Features)
+  bool isFeature(llvm::StringRef Ext) const;
+

svenvh wrote:
> The argument "Ext" suggests "Extension", so perhaps rename if this is about 
> features? (also in the definition in the .cpp file)
Sure, thanks. I was going to rename 'extensions' to other concept which will 
represent extensions and features, but this will be done in a separate  commit



Comment at: clang/lib/Basic/OpenCLOptions.cpp:24
+  auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
+  return CLVer >= 300 ? isEnabled("__opencl_c_fp64") : 
isEnabled("cl_khr_fp64");
+}

Anastasia wrote:
> We should at least be checking for `isSupported("__opencl_c_fp64")`, but 
> frankly I would prefer to check for supported and not for enabled for 
> `cl_khr_fp64` too. Note that we don't break backward compatibility if we 
> change this because the existing kernels will still be valid and it makes 
> things easier for writing new kernels too.
I think everything fine with this for now because 
`OpenCLOptions::enableSupportedCore` is called to set all supported core or 
optional core features to enabled state. So you suggest to removing this method 
at all too?

I think with your approach things will be unobvious in code: for some 
extensions there will be check for `isSupported` for some other there will be 
check for `isEnabled`. I think we should stay consistent here and check 
availability of all options in the same manner.



Comment at: clang/lib/Basic/TargetInfo.cpp:395
+
+// Set extensions simultaneosly with correspoding features
+// for OpenCL C 3.0 and higher

svenvh wrote:
> simultaneosly -> simultaneously
> correspoding -> corresponding
Sure, thanks



Comment at: clang/lib/Basic/TargetInfo.cpp:398
+auto CLVer = Opts.OpenCLCPlusPlus ? 200 : Opts.OpenCLVersion;
+if (CLVer >= 300) {
+  auto &OCLOpts = getSupportedOpenCLOpts();

Anastasia wrote:
> I suggest we move this onto `OpenCLOptions::addSupport`.
This should stay here to control simultaneous macro definitions



Comment at: clang/lib/Headers/opencl-c.h:4635
 
-#ifdef cl_khr_fp64
+#if defined(cl_khr_fp64) || defined(__opencl_c_fp64)
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable

Anastasia wrote:
> svenvh wrote:
> > Wondering if we need a similar change in 
> > `clang/lib/Headers/opencl-c-base.h` to guard the double vector types?
> Instead of growing the guard condition, I suggest we only check for one for 
> example the feature macro and then make sure the feature macro is defined in 
> `opencl-c-base.h` if the extensions that aliases to the feature is supported. 
> However, it would also be ok to do the opposite since the extensions and the 
> corresponding features should both be available.
> 
> FYI, something similar was done in https://reviews.llvm.org/D92004.
> 
> This will also help to propagate the functionality into Tablegen header 
> because we won't need to extend it to work with multiple extensions but we 
> might still need to do the rename.
Yeah, I overlooked this place... Thanks!



Comment at: clang/lib/Headers/opencl-c.h:4635
 
-#ifdef cl_khr_fp64
+#if defined(cl_khr_fp64) || defined(__opencl_c_fp64)
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable

azabaznov wrote:
> Anastasia wrote:
> > svenvh wrote:
> > > Wondering if we need a similar change in 
> > > `clang/lib/Headers/opencl-c-base.h` to guard the double vector types?
> > Instead of growing the guard condition, I suggest we only check for one for 
> > example the feature macro and then make sure the feature macro is defined 
> > in `opencl-c-base.h` if the extensions that aliases to the feature is 
> > supported. However, it would also be ok to do the opposite since the 
> > extensions and the corresponding features should both be available.
> > 
> > FYI, something similar was done in https://reviews.llvm.org/D92004.
> > 
> > This will also help to propagate the functionality into Tablegen header 
> > because we won't need to extend it to work with multiple extensions but we 
> > might still need to do the rename.
> Yeah, I overlooked this place... Thanks!
I don't think that growing of this condition will hurt in some cases... Note, 
that unifying condition check makes sense if some features are unconditionally 
supported for OpenCL C 2.0, such as generic address space for example. In other 
cases (such as fp64, 3d image writes, subgroups) we should use OR in guard 
condition.  

Your approach will require extra checks in clang such as, for example, to make 
sure that extension macro is not predefined if the feature macro is defined, 
because there will be redefinition since extension macro is defined in header.



Comment at: clang/lib/Se

[PATCH] D96178: [OpenCL] Create VoidPtrTy with generic AS in C++ for OpenCL mode

2021-02-16 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 324004.
azabaznov added a comment.

Fix clang-tidy warnings


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96178/new/

https://reviews.llvm.org/D96178

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl


Index: clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -triple spir -cl-std=clc++ -emit-llvm -O0 -o - | 
FileCheck %s
+
+typedef __SIZE_TYPE__ size_t;
+
+class A {
+public:
+  void* operator new(size_t);
+  void operator delete(void *ptr);
+};
+
+void test_new_delete(A **a) {
+// CHECK: %{{.*}} = call spir_func i8 addrspace(4)* @_ZNU3AS41AnwEj(i32 {{.*}})
+*a = new A;
+// CHECK: call spir_func void @_ZNU3AS41AdlEPU3AS4v(i8 addrspace(4)* {{.*}})
+delete *a;
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15261,11 +15261,13 @@
   return false;
 }
 
-static QualType
-RemoveAddressSpaceFromPtr(Sema &SemaRef, const PointerType *PtrTy) {
-  QualType QTy = PtrTy->getPointeeType();
-  QTy = SemaRef.Context.removeAddrSpaceQualType(QTy);
-  return SemaRef.Context.getPointerType(QTy);
+static CanQualType RemoveAddressSpaceFromPtr(Sema &SemaRef,
+ const PointerType *PtrTy) {
+  auto &Ctx = SemaRef.Context;
+  Qualifiers PtrQuals = PtrTy->getPointeeType().getQualifiers();
+  PtrQuals.removeAddressSpace();
+  return Ctx.getPointerType(Ctx.getCanonicalType(Ctx.getQualifiedType(
+  PtrTy->getPointeeType().getUnqualifiedType(), PtrQuals)));
 }
 
 static inline bool
@@ -15277,11 +15279,14 @@
   QualType ResultType =
   FnDecl->getType()->castAs()->getReturnType();
 
-  // The operator is valid on any address space for OpenCL.
   if (SemaRef.getLangOpts().OpenCLCPlusPlus) {
-if (auto *PtrTy = ResultType->getAs()) {
+// The operator is valid on any address space for OpenCL.
+// Drop address space from actual and expected result types.
+if (const auto *PtrTy = ResultType->getAs())
   ResultType = RemoveAddressSpaceFromPtr(SemaRef, PtrTy);
-}
+
+if (auto ExpectedPtrTy = ExpectedResultType->getAs())
+  ExpectedResultType = RemoveAddressSpaceFromPtr(SemaRef, ExpectedPtrTy);
   }
 
   // Check that the result type is what we expect.
@@ -15311,10 +15316,14 @@
   QualType FirstParamType = FnDecl->getParamDecl(0)->getType();
   if (SemaRef.getLangOpts().OpenCLCPlusPlus) {
 // The operator is valid on any address space for OpenCL.
-if (auto *PtrTy =
-FnDecl->getParamDecl(0)->getType()->getAs()) {
+// Drop address space from actual and expected first parameter types.
+if (const auto *PtrTy =
+FnDecl->getParamDecl(0)->getType()->getAs())
   FirstParamType = RemoveAddressSpaceFromPtr(SemaRef, PtrTy);
-}
+
+if (auto ExpectedPtrTy = ExpectedFirstParamType->getAs())
+  ExpectedFirstParamType =
+  RemoveAddressSpaceFromPtr(SemaRef, ExpectedPtrTy);
   }
 
   // Check that the first parameter type is what we expect.
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -1445,7 +1445,7 @@
   ObjCSuperType = QualType();
 
   // void * type
-  if (LangOpts.OpenCLVersion >= 200) {
+  if (LangOpts.OpenCLGenericAddressSpace) {
 auto Q = VoidTy.getQualifiers();
 Q.setAddressSpace(LangAS::opencl_generic);
 VoidPtrTy = getPointerType(getCanonicalType(


Index: clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -triple spir -cl-std=clc++ -emit-llvm -O0 -o - | FileCheck %s
+
+typedef __SIZE_TYPE__ size_t;
+
+class A {
+public:
+  void* operator new(size_t);
+  void operator delete(void *ptr);
+};
+
+void test_new_delete(A **a) {
+// CHECK: %{{.*}} = call spir_func i8 addrspace(4)* @_ZNU3AS41AnwEj(i32 {{.*}})
+*a = new A;
+// CHECK: call spir_func void @_ZNU3AS41AdlEPU3AS4v(i8 addrspace(4)* {{.*}})
+delete *a;
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15261,11 +15261,13 @@
   return false;
 }
 
-static QualType
-RemoveAddressSpaceFromPtr(Sema &SemaRef, const PointerType *PtrTy) {
-  QualType QTy = PtrTy->getPointeeType();
-  QTy = SemaRef.Context.removeAddrSpaceQualType(QTy);
-  return SemaRef.Context.getPointerType(QTy);
+static CanQualType RemoveAddressSpaceFromPtr(Sema &SemaRef,

[PATCH] D96178: [OpenCL] Create VoidPtrTy with generic AS in C++ for OpenCL mode

2021-02-16 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

Thanks for review. Last change is a small fix for if clang-tidy warnings


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96178/new/

https://reviews.llvm.org/D96178

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96178: [OpenCL] Create VoidPtrTy with generic AS in C++ for OpenCL mode

2021-02-17 Thread Anton Zabaznov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe1a64aa66c33: [OpenCL] Create VoidPtrTy with generic AS in 
C++ for OpenCL mode (authored by azabaznov).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96178/new/

https://reviews.llvm.org/D96178

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl


Index: clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -triple spir -cl-std=clc++ -emit-llvm -O0 -o - | 
FileCheck %s
+
+typedef __SIZE_TYPE__ size_t;
+
+class A {
+public:
+  void* operator new(size_t);
+  void operator delete(void *ptr);
+};
+
+void test_new_delete(A **a) {
+// CHECK: %{{.*}} = call spir_func i8 addrspace(4)* @_ZNU3AS41AnwEj(i32 {{.*}})
+*a = new A;
+// CHECK: call spir_func void @_ZNU3AS41AdlEPU3AS4v(i8 addrspace(4)* {{.*}})
+delete *a;
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15261,11 +15261,13 @@
   return false;
 }
 
-static QualType
-RemoveAddressSpaceFromPtr(Sema &SemaRef, const PointerType *PtrTy) {
-  QualType QTy = PtrTy->getPointeeType();
-  QTy = SemaRef.Context.removeAddrSpaceQualType(QTy);
-  return SemaRef.Context.getPointerType(QTy);
+static CanQualType RemoveAddressSpaceFromPtr(Sema &SemaRef,
+ const PointerType *PtrTy) {
+  auto &Ctx = SemaRef.Context;
+  Qualifiers PtrQuals = PtrTy->getPointeeType().getQualifiers();
+  PtrQuals.removeAddressSpace();
+  return Ctx.getPointerType(Ctx.getCanonicalType(Ctx.getQualifiedType(
+  PtrTy->getPointeeType().getUnqualifiedType(), PtrQuals)));
 }
 
 static inline bool
@@ -15277,11 +15279,14 @@
   QualType ResultType =
   FnDecl->getType()->castAs()->getReturnType();
 
-  // The operator is valid on any address space for OpenCL.
   if (SemaRef.getLangOpts().OpenCLCPlusPlus) {
-if (auto *PtrTy = ResultType->getAs()) {
+// The operator is valid on any address space for OpenCL.
+// Drop address space from actual and expected result types.
+if (const auto *PtrTy = ResultType->getAs())
   ResultType = RemoveAddressSpaceFromPtr(SemaRef, PtrTy);
-}
+
+if (auto ExpectedPtrTy = ExpectedResultType->getAs())
+  ExpectedResultType = RemoveAddressSpaceFromPtr(SemaRef, ExpectedPtrTy);
   }
 
   // Check that the result type is what we expect.
@@ -15311,10 +15316,14 @@
   QualType FirstParamType = FnDecl->getParamDecl(0)->getType();
   if (SemaRef.getLangOpts().OpenCLCPlusPlus) {
 // The operator is valid on any address space for OpenCL.
-if (auto *PtrTy =
-FnDecl->getParamDecl(0)->getType()->getAs()) {
+// Drop address space from actual and expected first parameter types.
+if (const auto *PtrTy =
+FnDecl->getParamDecl(0)->getType()->getAs())
   FirstParamType = RemoveAddressSpaceFromPtr(SemaRef, PtrTy);
-}
+
+if (auto ExpectedPtrTy = ExpectedFirstParamType->getAs())
+  ExpectedFirstParamType =
+  RemoveAddressSpaceFromPtr(SemaRef, ExpectedPtrTy);
   }
 
   // Check that the first parameter type is what we expect.
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -1445,7 +1445,7 @@
   ObjCSuperType = QualType();
 
   // void * type
-  if (LangOpts.OpenCLVersion >= 200) {
+  if (LangOpts.OpenCLGenericAddressSpace) {
 auto Q = VoidTy.getQualifiers();
 Q.setAddressSpace(LangAS::opencl_generic);
 VoidPtrTy = getPointerType(getCanonicalType(


Index: clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -triple spir -cl-std=clc++ -emit-llvm -O0 -o - | FileCheck %s
+
+typedef __SIZE_TYPE__ size_t;
+
+class A {
+public:
+  void* operator new(size_t);
+  void operator delete(void *ptr);
+};
+
+void test_new_delete(A **a) {
+// CHECK: %{{.*}} = call spir_func i8 addrspace(4)* @_ZNU3AS41AnwEj(i32 {{.*}})
+*a = new A;
+// CHECK: call spir_func void @_ZNU3AS41AdlEPU3AS4v(i8 addrspace(4)* {{.*}})
+delete *a;
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15261,11 +15261,13 @@
   return false;
 }
 
-static QualType
-RemoveAddressSpaceFromPtr(Sema &SemaRef, const PointerType *PtrTy) {
-  QualType QTy = PtrTy->getPointeeType();
-  QTy = 

[PATCH] D97058: [OpenCL] Refactor diagnostic for OpenCL extension/feature

2021-02-19 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov created this revision.
azabaznov added reviewers: Anastasia, svenvh.
Herald added subscribers: jfb, yaxunl.
azabaznov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

There is no need to check for enabled pragma for core or optional core features,
thus this check is removed


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97058

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/OpenCLOptions.h
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/Parser/opencl-atomics-cl20.cl
  clang/test/SemaOpenCL/access-qualifier.cl
  clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
  clang/test/SemaOpenCL/extension-begin.cl
  clang/test/SemaOpenCL/extensions.cl

Index: clang/test/SemaOpenCL/extensions.cl
===
--- clang/test/SemaOpenCL/extensions.cl
+++ clang/test/SemaOpenCL/extensions.cl
@@ -43,8 +43,8 @@
 #endif
 
 #if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 120)
-void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}}
-  double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
+void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 support}}
+  double d; // expected-error {{type 'double' requires cl_khr_fp64 support}}
   (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}}
 }
 #endif
@@ -72,14 +72,14 @@
 void f2(void) {
   double d;
 #ifdef NOFP64
-// expected-error@-2{{use of type 'double' requires cl_khr_fp64 extension to be enabled}}
+// expected-error@-2{{use of type 'double' requires cl_khr_fp64 support}}
 #endif
 
   typedef double double4 __attribute__((ext_vector_type(4)));
   double4 d4 = {0.0f, 2.0f, 3.0f, 1.0f};
 #ifdef NOFP64
-// expected-error@-3 {{use of type 'double' requires cl_khr_fp64 extension to be enabled}}
-// expected-error@-3 {{use of type 'double4' (vector of 4 'double' values) requires cl_khr_fp64 extension to be enabled}}
+// expected-error@-3 {{use of type 'double' requires cl_khr_fp64 support}}
+// expected-error@-3 {{use of type 'double4' (vector of 4 'double' values) requires cl_khr_fp64 support}}
 #endif
 
   (void) 1.0;
@@ -96,6 +96,6 @@
 
 #if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 120)
 void f3(void) {
-  double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
+  double d; // expected-error {{type 'double' requires cl_khr_fp64 support}}
 }
 #endif
Index: clang/test/SemaOpenCL/extension-begin.cl
===
--- clang/test/SemaOpenCL/extension-begin.cl
+++ clang/test/SemaOpenCL/extension-begin.cl
@@ -41,11 +41,11 @@
 
 #pragma OPENCL EXTENSION my_ext : disable 
 void test_f2(void) {
-  struct A test_A2; // expected-error {{use of type 'struct A' requires my_ext extension to be enabled}}
-  const struct A test_A_local; // expected-error {{use of type 'struct A' requires my_ext extension to be enabled}}
-  TypedefOfA test_typedef_A; // expected-error {{use of type 'TypedefOfA' (aka 'struct A') requires my_ext extension to be enabled}}
-  PointerOfA test_A_pointer; // expected-error {{use of type 'PointerOfA' (aka 'const __private struct A *') requires my_ext extension to be enabled}}
-  f(); // expected-error {{use of declaration 'f' requires my_ext extension to be enabled}}
+  struct A test_A2; // expected-error {{use of type 'struct A' requires my_ext support}}
+  const struct A test_A_local; // expected-error {{use of type 'struct A' requires my_ext support}}
+  TypedefOfA test_typedef_A; // expected-error {{use of type 'TypedefOfA' (aka 'struct A') requires my_ext support}}
+  PointerOfA test_A_pointer; // expected-error {{use of type 'PointerOfA' (aka 'const __private struct A *') requires my_ext support}}
+  f(); // expected-error {{use of declaration 'f' requires my_ext support}}
   g(0); // expected-error {{no matching function for call to 'g'}}
 // expected-note@extension-begin.h:18 {{candidate unavailable as it requires OpenCL extension 'my_ext' to be enabled}}
 // expected-note@extension-begin.h:23 {{candidate function not viable: requires 0 arguments, but 1 was provided}}
Index: clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
===
--- clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -235,11 +235,11 @@
 kernel void foo1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // expected-error {{use

[PATCH] D97052: [OpenCL] Prevent adding extension pragma by default

2021-02-19 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

Thanks! I review is shortly. As for now, I also was doing some refactoring: 
https://reviews.llvm.org/D97058. Check-clang passes, as I see there are no 
conflicts for now.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97052/new/

https://reviews.llvm.org/D97052

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97052: [OpenCL] Prevent adding extension pragma by default

2021-02-19 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:71
+OPENCL_EXTENSION(cl_khr_int64_extended_atomics, true, 100)
+OPENCL_COREFEATURE(cl_khr_3d_image_writes, true, 100, OCL_C_20)
 

I think core and optional core features do not require pragma too. So for 
example 3d image writes or fp64 do not require pragma in OpenCL C 2.0. Isn't 
that so?



Comment at: clang/test/SemaOpenCL/extension-version.cl:217
+
+// Check that pragmas for the OpenCL 3.0 features are rejected.
+

Again about core or optional core: don't you feel that current diagnostic is 
good already (https://godbolt.org/z/Kcjdvr)?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97052/new/

https://reviews.llvm.org/D97052

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97052: [OpenCL] Prevent adding extension pragma by default

2021-02-20 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:71
+OPENCL_EXTENSION(cl_khr_int64_extended_atomics, true, 100)
+OPENCL_COREFEATURE(cl_khr_3d_image_writes, true, 100, OCL_C_20)
 

Anastasia wrote:
> azabaznov wrote:
> > I think core and optional core features do not require pragma too. So for 
> > example 3d image writes or fp64 do not require pragma in OpenCL C 2.0. 
> > Isn't that so?
> Well to be honest nothing seems to need pragma but we have to accept it for 
> the backward compatibility. :)
> 
> In case of the core features if pragma would have been useful we would have 
> to still accept it for the backward compatibility even if the feature became 
> core.
I'm just wondering if this new field needed in the file to maintain backward 
compatibility. Maybe we can highlight OpenCL C 3.0 features with some other 
way? Is it seems that check for name starting with "__opencl_c" is a bad idea?



Comment at: clang/lib/Parse/ParsePragma.cpp:785
+  // Therefore, it should never be added by default.
+  Opt.acceptsPragma(Name);
 }

Anastasia wrote:
> svenvh wrote:
> > I fail to understand why this is needed, so perhaps this needs a bit more 
> > explanation.  Extensions that should continue to support pragmas already 
> > have their `WithPragma` field set to `true` via `OpenCLExtensions.def`.  
> > Why do we need to dynamically modify the field?
> It is a bit twisty here to be honest. Because we have also introduced the 
> pragma `begin` and `end` that would add pragma `enable`/`disable` by default. 
> So any extension added dynamically using `begin`/`end` would have to accept 
> the pragma `enable`/`disable`. 
> 
> https://clang.llvm.org/docs/UsersManual.html#opencl-extensions
> 
> But in the subsequent patches, I hope to remove this because I just don't see 
> where it is useful but it is very confusing.
Is it ok not to track this situation here:

```
#pragma OPENCL EXTENSION __opencl_c_feature : begin
#pragma OPENCL EXTENSION __opencl_c_feature: end
```

This is some of a corner case, but still...


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97052/new/

https://reviews.llvm.org/D97052

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96524: [OpenCL] Add support of OpenCL C 3.0 __opencl_c_fp64

2021-02-20 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov marked 3 inline comments as done.
azabaznov added inline comments.



Comment at: clang/lib/Basic/OpenCLOptions.cpp:24
+  auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
+  return CLVer >= 300 ? isEnabled("__opencl_c_fp64") : 
isEnabled("cl_khr_fp64");
+}

Anastasia wrote:
> azabaznov wrote:
> > Anastasia wrote:
> > > We should at least be checking for `isSupported("__opencl_c_fp64")`, but 
> > > frankly I would prefer to check for supported and not for enabled for 
> > > `cl_khr_fp64` too. Note that we don't break backward compatibility if we 
> > > change this because the existing kernels will still be valid and it makes 
> > > things easier for writing new kernels too.
> > I think everything fine with this for now because 
> > `OpenCLOptions::enableSupportedCore` is called to set all supported core or 
> > optional core features to enabled state. So you suggest to removing this 
> > method at all too?
> > 
> > I think with your approach things will be unobvious in code: for some 
> > extensions there will be check for `isSupported` for some other there will 
> > be check for `isEnabled`. I think we should stay consistent here and check 
> > availability of all options in the same manner.
> > I think everything fine with this for now because 
> > OpenCLOptions::enableSupportedCore is called to set all supported core or 
> > optional core features to enabled state. So you suggest to removing this 
> > method at all too?
> 
> Yes, I find it redundant somehow. Maybe it's best to indeed remove enabling 
> functionality for features since we definitely don't plan to use pragmas for 
> those? However, I appreciate it might be better to do as a separate change.
> 
>  
> > I think with your approach things will be unobvious in code: for some 
> > extensions there will be check for isSupported for some other there will be 
> > check for isEnabled. I think we should stay consistent here and check 
> > availability of all options in the same manner.
> 
> That's right, we might get some inconsistency at the start. But I think we 
> should drive towards checking `isSupported` rather than `isEnabled`. I don't 
> think we will have many cases for `isEnabled` at the end.
Thanks for feedback. I did some refactoring needed for this patch to proceed: 
https://reviews.llvm.org/D97058. AFAIU it doesn't conflict with the one you did 
(https://reviews.llvm.org/D97052). 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96524/new/

https://reviews.llvm.org/D96524

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97052: [OpenCL] Prevent adding extension pragma by default

2021-02-25 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:71
+OPENCL_EXTENSION(cl_khr_int64_extended_atomics, true, 100)
+OPENCL_COREFEATURE(cl_khr_3d_image_writes, true, 100, OCL_C_20)
 

Anastasia wrote:
> azabaznov wrote:
> > Anastasia wrote:
> > > azabaznov wrote:
> > > > I think core and optional core features do not require pragma too. So 
> > > > for example 3d image writes or fp64 do not require pragma in OpenCL C 
> > > > 2.0. Isn't that so?
> > > Well to be honest nothing seems to need pragma but we have to accept it 
> > > for the backward compatibility. :)
> > > 
> > > In case of the core features if pragma would have been useful we would 
> > > have to still accept it for the backward compatibility even if the 
> > > feature became core.
> > I'm just wondering if this new field needed in the file to maintain 
> > backward compatibility. Maybe we can highlight OpenCL C 3.0 features with 
> > some other way? Is it seems that check for name starting with "__opencl_c" 
> > is a bad idea?
> Not sure I understand you here but I don't think that we should add extension 
> pragmas any longer at all even for the new extensions. FYI I am planning to 
> add guidelines for that in https://reviews.llvm.org/D97072. Maybe it helps to 
> clarify the idea?
I mean that you could modify `OpenCLOptions::isWithPragma` that it will check 
if extension/feature was introduced in OpenCL C 3.0. If that's the case then no 
pragma needed. This new field `pragma` looks redundant as it is set to true 
only for OpenCL C 3.0 features. However, it may be more cosmetic concern...



Comment at: clang/lib/Parse/ParsePragma.cpp:785
+  // Therefore, it should never be added by default.
+  Opt.acceptsPragma(Name);
 }

Anastasia wrote:
> azabaznov wrote:
> > Anastasia wrote:
> > > svenvh wrote:
> > > > I fail to understand why this is needed, so perhaps this needs a bit 
> > > > more explanation.  Extensions that should continue to support pragmas 
> > > > already have their `WithPragma` field set to `true` via 
> > > > `OpenCLExtensions.def`.  Why do we need to dynamically modify the field?
> > > It is a bit twisty here to be honest. Because we have also introduced the 
> > > pragma `begin` and `end` that would add pragma `enable`/`disable` by 
> > > default. So any extension added dynamically using `begin`/`end` would 
> > > have to accept the pragma `enable`/`disable`. 
> > > 
> > > https://clang.llvm.org/docs/UsersManual.html#opencl-extensions
> > > 
> > > But in the subsequent patches, I hope to remove this because I just don't 
> > > see where it is useful but it is very confusing.
> > Is it ok not to track this situation here:
> > 
> > ```
> > #pragma OPENCL EXTENSION __opencl_c_feature : begin
> > #pragma OPENCL EXTENSION __opencl_c_feature: end
> > ```
> > 
> > This is some of a corner case, but still...
> I see. I am not sure what should happen here - I guess we should give an 
> error? Although for earlier versions than OpenCL 3.0 this should probably be 
> accepted?
> 
> Perhaps we can create a PR for this for now...
Oh, I think we can ignore this as double underscored identifiers are reserved. 
It's not expected that users will declare new features.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97052/new/

https://reviews.llvm.org/D97052

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97058: [OpenCL] Refactor diagnostic for OpenCL extension/feature

2021-02-25 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

> FYI, I would even be ok if we remove the need for enabling non-core

AFAIU this can be done not for every extension to maintain backward 
compatibility. In this case I think https://reviews.llvm.org/D97052 can be 
useful.

Also, I imagine that implicit type definition is not  needed if no pragma 
required.




Comment at: clang/lib/Sema/Sema.cpp:360
 
 setOpenCLExtensionForType(Context.DoubleTy, "cl_khr_fp64");
 

Anastasia wrote:
> I think the same should apply to `double` not only `atomic_double`?
I think `double` is created in a place where it's not possible to guard it with 
OpenCL extensions support. I will double-check.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97058/new/

https://reviews.llvm.org/D97058

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97052: [OpenCL] Prevent adding extension pragma by default

2021-02-25 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

I see the update regaring this functionality on github issue: 
https://github.com/KhronosGroup/OpenCL-Docs/issues/82#issuecomment-785496025. 
Is it a right way to reflect this information in`OpenCLExtensions.def`?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97052/new/

https://reviews.llvm.org/D97052

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102853: [OpenCL] Align definition of __IMAGE_SUPPORT__ feature macro with OpenCL version and __opencl_c_images feature macro definition

2021-06-04 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

In D102853#2773890 , @Anastasia wrote:

> LGTM! Although I think it would be better if we set `__IMAGE_SUPPORT__` 
> conditionally also for earlier OpenCL versions.

It has always been defined for SPIR target only. Should we wait for spec fix 
before merging this?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102853/new/

https://reviews.llvm.org/D102853

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103241: [OpenCL] Add memory_scope_all_devices

2021-06-08 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:113
 OPENCL_OPTIONALCOREFEATURE(__opencl_c_atomic_order_seq_cst, false, 300, 
OCL_C_30)
+OPENCL_OPTIONALCOREFEATURE(__opencl_c_atomic_scope_all_devices, false, 300, 
OCL_C_30)
 OPENCL_OPTIONALCOREFEATURE(__opencl_c_subgroups, false, 300, OCL_C_30)

Anastasia wrote:
> azabaznov wrote:
> > Anastasia wrote:
> > > svenvh wrote:
> > > > Anastasia wrote:
> > > > > azabaznov wrote:
> > > > > > This feature is header only. We had a lot of discussions on that 
> > > > > > and the main idea was not to declare header only 
> > > > > > features/extensions in `OpenCLExtensions.def` and use 
> > > > > > `-D__opencl_c_atomic_scope_all_devices=1` instead, @Anastasia can 
> > > > > > comment on this.
> > > > > > 
> > > > > > I personally would like to introduce new flag for OpenCL options in 
> > > > > > `OpenCLExtensions.def` which will indicate that feature/extension 
> > > > > > is header-only, and thus all of such options can be declared in 
> > > > > > `OpenCLExtensions.def`: if flag is set to true it can be stripped 
> > > > > > out from the parser. What do you think about this?
> > > > > Yes, I agree the idea is to align with C/C++ directions for 
> > > > > scalability i.e. we should only add what is absolutely necessary to 
> > > > > the compiler and implement the rest using libraries - just like 
> > > > > regular C and C++. We won't be able to scale if we keep adding 
> > > > > everything in the compiler. In fact, we already have a huge 
> > > > > scalability issue with our builtin functions. If we look at modern 
> > > > > C++ - more than 70% of features are not in the compiler at all.
> > > > > 
> > > > > Would it be possible to do something like suggested here: 
> > > > > https://reviews.llvm.org/D91531#change-AKXhB4ko4nAO for 
> > > > > `cl_khr_depth_images`?
> > > > > 
> > > > > > I personally would like to introduce new flag for OpenCL options in 
> > > > > > OpenCLExtensions.def which will indicate that feature/extension is 
> > > > > > header-only, and thus all of such options can be declared in 
> > > > > > OpenCLExtensions.def: if flag is set to true it can be stripped out 
> > > > > > from the parser. What do you think about this?
> > > > > 
> > > > > Hmm, I think the macros should either be declared in the headers or 
> > > > > using a flag `-D`. I don't know why would adding them in 
> > > > > `OpenCLExtensions.def` be beneficial if we can use conventional 
> > > > > approaches? This allows avoiding the complexity and makes things more 
> > > > > modular. If we look at the OpenCL vendor extensions for example - we 
> > > > > probably don't want them all in one place?
> > > > > This feature is header only.
> > > > 
> > > > Good catch!  I have updated the patch to define the feature macro in 
> > > > the header instead.  Currently that definition is not optional, since 
> > > > we don't have finalized the solution for handling this yet (though the 
> > > > __undef proposal seems to be compatible with this change).
> > > > 
> > > > > I personally would like to introduce new flag for OpenCL options in 
> > > > > OpenCLExtensions.def which will indicate that feature/extension is 
> > > > > header-only
> > > > 
> > > > If we still need to add header-only features to OpenCLExtensions.def, 
> > > > then they aren't really header-only anymore I'd argue (as @Anastasia 
> > > > pointed out above).  So I'm not sure we need it either, or perhaps I 
> > > > missed something.
> > > FYI we have already added extended subgroups extension macros for SPIR in 
> > > `opencl-c-base.h` without the `__undef<...>` trick.
> > > 
> > > ```
> > > #if defined(__SPIR__)
> > > #define cl_khr_subgroup_extended_types 1
> > > #define cl_khr_subgroup_non_uniform_vote 1
> > > #define cl_khr_subgroup_ballot 1
> > > #define cl_khr_subgroup_non_uniform_arithmetic 1
> > > #define cl_khr_subgroup_shuffle 1
> > > #define cl_khr_subgroup_shuffle_relative 1
> > > #define cl_khr_subgroup_clustered_reduce 1
> > > #endif // defined(__SPIR__)
> > > ```
> > > 
> > > But extra conditions can be added any time if we get the agreement on the 
> > > route forward. 
> > > Hmm, I think the macros should either be declared in the headers or using 
> > > a flag -D. I don't know why would adding them in OpenCLExtensions.def be 
> > > beneficial if we can use conventional approaches? This allows avoiding 
> > > the complexity and makes things more modular. If we look at the OpenCL 
> > > vendor extensions for example - we probably don't want them all in one 
> > > place?
> > 
> > Well, IMO separating extensions/features into two classes of options 
> > exactly brings new complexities :) I'm not sure why do we need to have a 
> > separate interface for them if there already exists unified one. For 
> > example, Intel compute-runtime uses `-cl-ext` flag to forward options : 
> > https://github.com/intel/compute-runtime/blob/master/ope

  1   2   3   >