[clang] b5fef6d - [OpenCL] Allow optional __generic in __remove_address_space utility
Author: Justas Janickas Date: 2021-12-27T08:39:21Z New Revision: b5fef6dbfd6b4c84d61155fd2221064bcc1ecdcf URL: https://github.com/llvm/llvm-project/commit/b5fef6dbfd6b4c84d61155fd2221064bcc1ecdcf DIFF: https://github.com/llvm/llvm-project/commit/b5fef6dbfd6b4c84d61155fd2221064bcc1ecdcf.diff LOG: [OpenCL] Allow optional __generic in __remove_address_space utility Added: clang/test/SemaOpenCLCXX/remove-address-space.clcpp Modified: clang/lib/Headers/opencl-c-base.h Removed: clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp diff --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h index 9c81ddb5e2a73..7485386c82346 100644 --- a/clang/lib/Headers/opencl-c-base.h +++ b/clang/lib/Headers/opencl-c-base.h @@ -600,9 +600,11 @@ typedef struct { // C++ for OpenCL - __remove_address_space #if defined(__OPENCL_CPP_VERSION__) template struct __remove_address_space { using type = _Tp; }; +#if defined(__opencl_c_generic_address_space) template struct __remove_address_space<__generic _Tp> { using type = _Tp; }; +#endif template struct __remove_address_space<__global _Tp> { using type = _Tp; }; diff --git a/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp b/clang/test/SemaOpenCLCXX/remove-address-space.clcpp similarity index 75% rename from clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp rename to clang/test/SemaOpenCLCXX/remove-address-space.clcpp index f6f0c3290aa66..e6b2924eab5f8 100644 --- a/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp +++ b/clang/test/SemaOpenCLCXX/remove-address-space.clcpp @@ -1,4 +1,8 @@ -// RUN: %clang_cc1 %s -cl-std=clc++ -fdeclare-opencl-builtins -finclude-default-header +// RUN: %clang_cc1 %s -cl-std=clc++1.0 -triple spir-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header -verify +// RUN: %clang_cc1 %s -cl-std=clc++2021 -triple spir-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header -verify +// RUN: %clang_cc1 %s -cl-std=clc++2021 -cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes -triple spir-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header -verify + +// expected-no-diagnostics template struct is_same { @@ -19,8 +23,10 @@ void test_is_same() { void test_remove_address_space() { static_assert(is_same<__remove_address_space::type, int>::value, "type without an address space unexpectedly modified by __remove_address_space"); +#if defined(__opencl_c_generic_address_space) static_assert(is_same<__remove_address_space<__generic int>::type, int>::value, "__generic address space not removed by __remove_address_space"); +#endif static_assert(is_same<__remove_address_space<__global char>::type, char>::value, "__global address space not removed by __remove_address_space"); static_assert(is_same<__remove_address_space<__private ulong>::type, ulong>::value, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 388e811 - [OpenCL] Constructor address space test adjusted for C++ for OpenCL 2021
Author: Justas Janickas Date: 2021-11-12T14:31:50Z New Revision: 388e8110db6f7b4ad9d655a70780f8698c4b9fd1 URL: https://github.com/llvm/llvm-project/commit/388e8110db6f7b4ad9d655a70780f8698c4b9fd1 DIFF: https://github.com/llvm/llvm-project/commit/388e8110db6f7b4ad9d655a70780f8698c4b9fd1.diff LOG: [OpenCL] Constructor address space test adjusted for C++ for OpenCL 2021 Reuses C++ for OpenCL constructor address space test so that it supports optional generic address spaces in version 2021. Differential Revision: https://reviews.llvm.org/D110184 Added: Modified: clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp Removed: diff --git a/clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp b/clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp index c0913f484f5e3..9ad251d051c77 100644 --- a/clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp +++ b/clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -triple spir-unknown-unknown | FileCheck %s +// RUN: %clang_cc1 %s -cl-std=clc++1.0 -DGENERIC -emit-llvm -o - -O0 -triple spir-unknown-unknown | FileCheck %s +// RUN: %clang_cc1 %s -cl-std=clc++2021 -DGENERIC -emit-llvm -o - -O0 -triple spir-unknown-unknown | FileCheck %s +// RUN: %clang_cc1 %s -cl-std=clc++2021 -cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes -emit-llvm -o - -O0 -triple spir-unknown-unknown | FileCheck %s // CHECK: %struct.X = type { i32 } @@ -11,8 +13,10 @@ struct X { int x; // Local variables are handled in local_addrspace_init.clcpp - X() /*__generic*/ : x(0) {} + X() /*__generic or __private*/ : x(0) {} +#if defined(GENERIC) X() __private : x(0) {} +#endif X() __global : x(0) {} constexpr X() __constant : x(0) {} constexpr X(int x) __constant : x(x) {} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] d85d57e - Revert "[OpenCL] Allow optional __generic in __remove_address_space utility"
Author: Justas Janickas Date: 2021-11-09T09:42:17Z New Revision: d85d57e98789d187cac415d9d8a0973ae6f2e4e1 URL: https://github.com/llvm/llvm-project/commit/d85d57e98789d187cac415d9d8a0973ae6f2e4e1 DIFF: https://github.com/llvm/llvm-project/commit/d85d57e98789d187cac415d9d8a0973ae6f2e4e1.diff LOG: Revert "[OpenCL] Allow optional __generic in __remove_address_space utility" This reverts commit 81081daef0299ad59fca299c7cde3888fa691c6a. Added: Modified: clang/lib/Headers/opencl-c-base.h clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp Removed: diff --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h index 7485386c82346..9c81ddb5e2a73 100644 --- a/clang/lib/Headers/opencl-c-base.h +++ b/clang/lib/Headers/opencl-c-base.h @@ -600,11 +600,9 @@ typedef struct { // C++ for OpenCL - __remove_address_space #if defined(__OPENCL_CPP_VERSION__) template struct __remove_address_space { using type = _Tp; }; -#if defined(__opencl_c_generic_address_space) template struct __remove_address_space<__generic _Tp> { using type = _Tp; }; -#endif template struct __remove_address_space<__global _Tp> { using type = _Tp; }; diff --git a/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp b/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp index 9043a7d53c682..f6f0c3290aa66 100644 --- a/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp +++ b/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp @@ -1,6 +1,4 @@ -// RUN: %clang_cc1 %s -cl-std=clc++1.0 -fdeclare-opencl-builtins -finclude-default-header -// RUN: %clang_cc1 %s -cl-std=clc++2021 -fdeclare-opencl-builtins -finclude-default-header -// RUN: %clang_cc1 %s -cl-std=clc++2021 -cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes -fdeclare-opencl-builtins -finclude-default-header +// RUN: %clang_cc1 %s -cl-std=clc++ -fdeclare-opencl-builtins -finclude-default-header template struct is_same { @@ -21,10 +19,8 @@ void test_is_same() { void test_remove_address_space() { static_assert(is_same<__remove_address_space::type, int>::value, "type without an address space unexpectedly modified by __remove_address_space"); -#if defined(__opencl_c_generic_address_space) static_assert(is_same<__remove_address_space<__generic int>::type, int>::value, "__generic address space not removed by __remove_address_space"); -#endif static_assert(is_same<__remove_address_space<__global char>::type, char>::value, "__global address space not removed by __remove_address_space"); static_assert(is_same<__remove_address_space<__private ulong>::type, ulong>::value, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 81081da - [OpenCL] Allow optional __generic in __remove_address_space utility
Author: Justas Janickas Date: 2021-11-09T08:13:34Z New Revision: 81081daef0299ad59fca299c7cde3888fa691c6a URL: https://github.com/llvm/llvm-project/commit/81081daef0299ad59fca299c7cde3888fa691c6a DIFF: https://github.com/llvm/llvm-project/commit/81081daef0299ad59fca299c7cde3888fa691c6a.diff LOG: [OpenCL] Allow optional __generic in __remove_address_space utility Clang builtin utility `__remove_address_space` now works if generic address space is not supported in C++ for OpenCL 2021. Differential Revision: https://reviews.llvm.org/D110155 Added: Modified: clang/lib/Headers/opencl-c-base.h clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp Removed: diff --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h index 9c81ddb5e2a73..7485386c82346 100644 --- a/clang/lib/Headers/opencl-c-base.h +++ b/clang/lib/Headers/opencl-c-base.h @@ -600,9 +600,11 @@ typedef struct { // C++ for OpenCL - __remove_address_space #if defined(__OPENCL_CPP_VERSION__) template struct __remove_address_space { using type = _Tp; }; +#if defined(__opencl_c_generic_address_space) template struct __remove_address_space<__generic _Tp> { using type = _Tp; }; +#endif template struct __remove_address_space<__global _Tp> { using type = _Tp; }; diff --git a/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp b/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp index f6f0c3290aa66..9043a7d53c682 100644 --- a/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp +++ b/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 %s -cl-std=clc++ -fdeclare-opencl-builtins -finclude-default-header +// RUN: %clang_cc1 %s -cl-std=clc++1.0 -fdeclare-opencl-builtins -finclude-default-header +// RUN: %clang_cc1 %s -cl-std=clc++2021 -fdeclare-opencl-builtins -finclude-default-header +// RUN: %clang_cc1 %s -cl-std=clc++2021 -cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes -fdeclare-opencl-builtins -finclude-default-header template struct is_same { @@ -19,8 +21,10 @@ void test_is_same() { void test_remove_address_space() { static_assert(is_same<__remove_address_space::type, int>::value, "type without an address space unexpectedly modified by __remove_address_space"); +#if defined(__opencl_c_generic_address_space) static_assert(is_same<__remove_address_space<__generic int>::type, int>::value, "__generic address space not removed by __remove_address_space"); +#endif static_assert(is_same<__remove_address_space<__global char>::type, char>::value, "__global address space not removed by __remove_address_space"); static_assert(is_same<__remove_address_space<__private ulong>::type, ulong>::value, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 32b994b - [OpenCL] Defines helper function for OpenCL default address space
Author: Justas Janickas Date: 2021-09-21T15:12:08+01:00 New Revision: 32b994bca66641cdac8586f25315daf349921ebc URL: https://github.com/llvm/llvm-project/commit/32b994bca66641cdac8586f25315daf349921ebc DIFF: https://github.com/llvm/llvm-project/commit/32b994bca66641cdac8586f25315daf349921ebc.diff LOG: [OpenCL] Defines helper function for OpenCL default address space Helper function `getDefaultOpenCLPointeeAddrSpace()` introduced to `ASTContext` class. It returns default OpenCL address space depending on language version and enabled features. If generic address space is supported, the helper function returns value `LangAS::opencl_generic`. Otherwise, value `LangAS::opencl_private` is returned. Code refactoring changes performed in several suitable places. Differential Revision: https://reviews.llvm.org/D109874 Added: Modified: clang/include/clang/AST/ASTContext.h clang/lib/AST/Expr.cpp clang/lib/Sema/Sema.cpp clang/lib/Sema/SemaTemplateDeduction.cpp clang/lib/Sema/SemaType.cpp Removed: diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index b8f7c3aae2608..f1b057c8003f8 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1362,6 +1362,12 @@ class ASTContext : public RefCountedBase { /// Get address space for OpenCL type. LangAS getOpenCLTypeAddrSpace(const Type *T) const; + /// Returns default address space based on OpenCL version and enabled features + inline LangAS getDefaultOpenCLPointeeAddrSpace() { +return LangOpts.OpenCLGenericAddressSpace ? LangAS::opencl_generic + : LangAS::opencl_private; + } + void setcudaConfigureCallDecl(FunctionDecl *FD) { cudaConfigureCallDecl = FD; } diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 31733932361f3..9fde21c7ee9e1 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -3779,11 +3779,8 @@ Expr::isNullPointerConstant(ASTContext , // has non-default address space it is not treated as nullptr. // (__generic void*)0 in OpenCL 2.0 should not be treated as nullptr // since it cannot be assigned to a pointer to constant address space. -if ((Ctx.getLangOpts().OpenCLVersion >= 200 && - Pointee.getAddressSpace() == LangAS::opencl_generic) || -(Ctx.getLangOpts().OpenCL && - Ctx.getLangOpts().OpenCLVersion < 200 && - Pointee.getAddressSpace() == LangAS::opencl_private)) +if (Ctx.getLangOpts().OpenCL && +Pointee.getAddressSpace() == Ctx.getDefaultOpenCLPointeeAddrSpace()) Qs.removeAddressSpace(); if (Pointee->isVoidType() && Qs.empty() && // to void* diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 0b936d60fc5ee..c997c70d17cef 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -1430,7 +1430,7 @@ NamedDecl *Sema::getCurFunctionOrMethodDecl() { LangAS Sema::getDefaultCXXMethodAddrSpace() const { if (getLangOpts().OpenCL) -return LangAS::opencl_generic; +return getASTContext().getDefaultOpenCLPointeeAddrSpace(); return LangAS::Default; } diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 826abbd8c3623..060f42bf9d644 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -3894,8 +3894,9 @@ static bool AdjustFunctionParmAndArgTypesForDeduction( // "lvalue reference to A" is used in place of A for type deduction. if (isForwardingReference(QualType(ParamRefType, 0), FirstInnerIndex) && Arg->isLValue()) { - if (S.getLangOpts().OpenCL && !ArgType.hasAddressSpace()) -ArgType = S.Context.getAddrSpaceQualType(ArgType, LangAS::opencl_generic); + if (S.getLangOpts().OpenCL && !ArgType.hasAddressSpace()) +ArgType = S.Context.getAddrSpaceQualType( +ArgType, S.Context.getDefaultOpenCLPointeeAddrSpace()); ArgType = S.Context.getLValueReferenceType(ArgType); } } else { diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index fcc2cf055be9e..d2d54281c63e0 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -2092,9 +2092,7 @@ static QualType deduceOpenCLPointeeAddrSpace(Sema , QualType PointeeType) { !PointeeType->isSamplerT() && !PointeeType.hasAddressSpace()) PointeeType = S.getASTContext().getAddrSpaceQualType( -PointeeType, S.getLangOpts().OpenCLGenericAddressSpace - ? LangAS::opencl_generic - : LangAS::opencl_private); +PointeeType, S.getASTContext().getDefaultOpenCLPointeeAddrSpace()); return PointeeType; } ___ cfe-commits mailing
[clang] 57b8b5c - [OpenCL] Test case for C++ for OpenCL 2021 in OpenCL C header test
Author: Justas Janickas Date: 2021-09-21T10:27:46+01:00 New Revision: 57b8b5c114b6e595f8d9118807d741ef30518777 URL: https://github.com/llvm/llvm-project/commit/57b8b5c114b6e595f8d9118807d741ef30518777 DIFF: https://github.com/llvm/llvm-project/commit/57b8b5c114b6e595f8d9118807d741ef30518777.diff LOG: [OpenCL] Test case for C++ for OpenCL 2021 in OpenCL C header test RUN line representing C++ for OpenCL 2021 added to the test. This should have been done as part of earlier commit fb321c2ea274 but was missed during rebasing. Differential Revision: https://reviews.llvm.org/D109492 Added: Modified: clang/test/Headers/opencl-c-header.cl Removed: diff --git a/clang/test/Headers/opencl-c-header.cl b/clang/test/Headers/opencl-c-header.cl index d300803f86fbb..bcce9623fafcb 100644 --- a/clang/test/Headers/opencl-c-header.cl +++ b/clang/test/Headers/opencl-c-header.cl @@ -1,8 +1,9 @@ // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify | FileCheck %s // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.1 | FileCheck %s // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.2 | FileCheck %s -// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=clc++ | FileCheck %s --check-prefix=CHECK20 +// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=clc++1.0 | FileCheck %s --check-prefix=CHECK20 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL3.0 | FileCheck %s +// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=clc++2021 | FileCheck %s // Test including the default header as a module. // The module should be compiled only once and loaded from cache afterwards. @@ -57,7 +58,7 @@ // CHECK20: _Z16convert_char_rtec char f(char x) { // Check functionality from OpenCL 2.0 onwards -#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0) +#if (__OPENCL_CPP_VERSION__ == 100) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0) ndrange_t t; x = ctz(x); #endif //__OPENCL_C_VERSION__ @@ -82,7 +83,7 @@ void test_atomics(__generic volatile unsigned int* a) { #endif // Verify that ATOMIC_VAR_INIT is defined. -#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0) +#if (__OPENCL_CPP_VERSION__ == 100) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0) global atomic_int z = ATOMIC_VAR_INIT(99); #endif //__OPENCL_C_VERSION__ // CHECK-MOD: Reading modules ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 228dd20 - [OpenCL] Supports atomics in C++ for OpenCL 2021
Author: Justas Janickas Date: 2021-09-20T16:24:30+01:00 New Revision: 228dd20c3f1e619193c68b288e0d5e8525c3a618 URL: https://github.com/llvm/llvm-project/commit/228dd20c3f1e619193c68b288e0d5e8525c3a618 DIFF: https://github.com/llvm/llvm-project/commit/228dd20c3f1e619193c68b288e0d5e8525c3a618.diff LOG: [OpenCL] Supports atomics in C++ for OpenCL 2021 Atomics in C++ for OpenCL 2021 are now handled the same way as in OpenCL C 3.0. This is a header-only change. Differential Revision: https://reviews.llvm.org/D109424 Added: Modified: clang/lib/Headers/opencl-c-base.h clang/lib/Headers/opencl-c.h Removed: diff --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h index 7cc356015d95..a36e657612e5 100644 --- a/clang/lib/Headers/opencl-c-base.h +++ b/clang/lib/Headers/opencl-c-base.h @@ -348,9 +348,9 @@ typedef enum memory_scope { memory_scope_device = __OPENCL_MEMORY_SCOPE_DEVICE, #if defined(__opencl_c_atomic_scope_all_devices) memory_scope_all_svm_devices = __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES, -#if (__OPENCL_C_VERSION__ >= CL_VERSION_3_0) +#if (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 202100) memory_scope_all_devices = memory_scope_all_svm_devices, -#endif // __OPENCL_C_VERSION__ >= CL_VERSION_3_0 +#endif // (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 202100) #endif // defined(__opencl_c_atomic_scope_all_devices) /** * Subgroups have diff erent requirements on forward progress, so just test diff --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h index e96022859480..705a3231b577 100644 --- a/clang/lib/Headers/opencl-c.h +++ b/clang/lib/Headers/opencl-c.h @@ -13256,7 +13256,7 @@ void __ovld atomic_init(volatile atomic_double *object, double value); #endif //cl_khr_fp64 #endif #endif //defined(__opencl_c_generic_address_space) -#if __OPENCL_C_VERSION__ >= CL_VERSION_3_0 +#if (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 202100) void __ovld atomic_init(volatile __global atomic_int *object, int value); void __ovld atomic_init(volatile __local atomic_int *object, int value); void __ovld atomic_init(volatile __global atomic_uint *object, uint value); @@ -13273,7 +13273,7 @@ void __ovld atomic_init(volatile __global atomic_double *object, double value); void __ovld atomic_init(volatile __local atomic_double *object, double value); #endif //cl_khr_fp64 #endif -#endif //__OPENCL_C_VERSION__ >= CL_VERSION_3_0 +#endif // (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 202100) // atomic_work_item_fence() void __ovld atomic_work_item_fence(cl_mem_fence_flags flags, memory_order order, memory_scope scope); @@ -13317,7 +13317,7 @@ uintptr_t __ovld atomic_fetch_add(volatile atomic_uintptr_t *object, ptr diff _t o uintptr_t __ovld atomic_fetch_sub(volatile atomic_uintptr_t *object, ptr diff _t operand); #endif //defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics) #endif //defined(__opencl_c_generic_address_space) -#if __OPENCL_C_VERSION__ >= CL_VERSION_3_0 +#if (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 202100) int __ovld atomic_fetch_add(volatile __global atomic_int *object, int operand); int __ovld atomic_fetch_add(volatile __local atomic_int *object, int operand); uint __ovld atomic_fetch_add(volatile __global atomic_uint *object, uint operand); @@ -13398,7 +13398,7 @@ ulong __ovld atomic_fetch_max(volatile __local atomic_ulong *object, ulong opera uintptr_t __ovld atomic_fetch_add(volatile __global atomic_uintptr_t *object, ptr diff _t operand); uintptr_t __ovld atomic_fetch_sub(volatile __local atomic_uintptr_t *object, ptr diff _t operand); #endif //defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics) -#endif //__OPENCL_C_VERSION__ >= CL_VERSION_3_0 +#endif // (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 202100) #endif #if defined(__opencl_c_atomic_scope_device) @@ -13436,7 +13436,7 @@ uintptr_t __ovld atomic_fetch_add_explicit(volatile atomic_uintptr_t *object, pt uintptr_t __ovld atomic_fetch_sub_explicit(volatile atomic_uintptr_t *object, ptr diff _t operand, memory_order order); #endif //defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics) #endif //defined(__opencl_c_generic_address_space) -#if __OPENCL_C_VERSION__ >= CL_VERSION_3_0 +#if (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 202100) int __ovld atomic_fetch_add_explicit(volatile __global atomic_int *object, int operand, memory_order order); int __ovld atomic_fetch_add_explicit(volatile __local atomic_int *object, int operand, memory_order order); uint __ovld atomic_fetch_add_explicit(volatile __global atomic_uint *object, uint operand, memory_order order); @@ -13517,7 +13517,7 @@ ulong __ovld
[clang] ca3bebd - [OpenCL] Supports optional writing to 3d images in C++ for OpenCL 2021
Author: Justas Janickas Date: 2021-09-20T10:07:38+01:00 New Revision: ca3bebd8440f9f88f1457dad9c12933b73d9590f URL: https://github.com/llvm/llvm-project/commit/ca3bebd8440f9f88f1457dad9c12933b73d9590f DIFF: https://github.com/llvm/llvm-project/commit/ca3bebd8440f9f88f1457dad9c12933b73d9590f.diff LOG: [OpenCL] Supports optional writing to 3d images in C++ for OpenCL 2021 Adds support for a feature macro __opencl_c_3d_image_writes in C++ for OpenCL 2021 enabling a respective optional core feature from OpenCL 3.0. This change aims to achieve compatibility between C++ for OpenCL 2021 and OpenCL 3.0. Differential Revision: https://reviews.llvm.org/D109328 Added: Modified: clang/lib/Sema/SemaType.cpp clang/test/Misc/opencl-c-3.0.incorrect_options.cl clang/test/SemaOpenCL/unsupported-image.cl Removed: diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index f7f428c1e6d8d..df9f203ae4c6b 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1732,10 +1732,6 @@ static QualType ConvertDeclSpecToType(TypeProcessingState ) { if (S.getLangOpts().OpenCL) { const auto = S.getOpenCLOptions(); -// FIXME: both variables IsOpenCLC30 and IsOpenCLC30Compatible should be -// unified into one when __opencl_c_3d_image_writes option is enabled in -// C++ for OpenCL 2021 -bool IsOpenCLC30 = (S.getLangOpts().OpenCLVersion == 300); bool IsOpenCLC30Compatible = S.getLangOpts().getOpenCLCompatibleVersion() == 300; // OpenCL C v3.0 s6.3.3 - OpenCL image types require __opencl_c_images @@ -1756,7 +1752,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState ) { S.getLangOpts())) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension) << 0 << Result - << (IsOpenCLC30 + << (IsOpenCLC30Compatible ? "cl_khr_3d_image_writes and __opencl_c_3d_image_writes" : "cl_khr_3d_image_writes"); declarator.setInvalidType(); diff --git a/clang/test/Misc/opencl-c-3.0.incorrect_options.cl b/clang/test/Misc/opencl-c-3.0.incorrect_options.cl index 6232806c5c6d9..b3f3ab974ddd0 100644 --- a/clang/test/Misc/opencl-c-3.0.incorrect_options.cl +++ b/clang/test/Misc/opencl-c-3.0.incorrect_options.cl @@ -8,6 +8,8 @@ // RUN: not %clang_cc1 -cl-std=clc++2021 -triple spir-unknown-unknown -cl-ext=+__opencl_c_pipes,-__opencl_c_generic_address_space %s 2>&1 | FileCheck -check-prefix=CHECK-PIPES %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 +// RUN: not %clang_cc1 -cl-std=clc++2021 -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=clc++2021 -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 diff erent values diff --git a/clang/test/SemaOpenCL/unsupported-image.cl b/clang/test/SemaOpenCL/unsupported-image.cl index 8db3f61b0146b..53422fa259f29 100644 --- a/clang/test/SemaOpenCL/unsupported-image.cl +++ b/clang/test/SemaOpenCL/unsupported-image.cl @@ -2,7 +2,8 @@ // 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=clc++2021 -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=clc++2021 -cl-ext=+__opencl_c_images %s +// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=clc++2021 -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=clc++2021 -cl-ext=+__opencl_c_images,+__opencl_c_read_write_images,-cl_khr_3d_image_writes,-__opencl_c_3d_image_writes %s #if defined(__opencl_c_images) && defined(__opencl_c_3d_image_writes) //expected-no-diagnostics
[clang] b7e9d20 - [OpenCL] Supports optional same image reads and writes in C++ for OpenCL 2021
Author: Justas Janickas Date: 2021-09-17T14:14:31+01:00 New Revision: b7e9d203c6793873f72dd3ffaf7c9365ce03007e URL: https://github.com/llvm/llvm-project/commit/b7e9d203c6793873f72dd3ffaf7c9365ce03007e DIFF: https://github.com/llvm/llvm-project/commit/b7e9d203c6793873f72dd3ffaf7c9365ce03007e.diff LOG: [OpenCL] Supports optional same image reads and writes in C++ for OpenCL 2021 Adds support for a feature macro `__opencl_c_read_write_images` in C++ for OpenCL 2021 enabling a respective optional core feature from OpenCL 3.0. This change aims to achieve compatibility between C++ for OpenCL 2021 and OpenCL 3.0. Differential Revision: https://reviews.llvm.org/D109307 Added: Modified: clang/lib/Sema/SemaDeclAttr.cpp clang/test/Misc/opencl-c-3.0.incorrect_options.cl clang/test/SemaOpenCL/access-qualifier.cl Removed: diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 35c32043e377..8092aeb21ada 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -7552,18 +7552,17 @@ static void handleOpenCLAccessAttr(Sema , Decl *D, const ParsedAttr ) { // OpenCL v3.0 s6.8 - For OpenCL C 2.0, or with the // __opencl_c_read_write_images feature, image objects specified as arguments // to a kernel can additionally be declared to be read-write. - // C++ for OpenCL inherits rule from OpenCL C v2.0. + // C++ for OpenCL 1.0 inherits rule from OpenCL C v2.0. + // C++ for OpenCL 2021 inherits rule from OpenCL C v3.0. if (const auto *PDecl = dyn_cast(D)) { const Type *DeclTy = PDecl->getType().getCanonicalType().getTypePtr(); if (AL.getAttrName()->getName().find("read_write") != StringRef::npos) { - bool ReadWriteImagesUnsupportedForOCLC = - (S.getLangOpts().OpenCLVersion < 200) || - (S.getLangOpts().OpenCLVersion == 300 && + bool ReadWriteImagesUnsupported = + (S.getLangOpts().getOpenCLCompatibleVersion() < 200) || + (S.getLangOpts().getOpenCLCompatibleVersion() == 300 && !S.getOpenCLOptions().isSupported("__opencl_c_read_write_images", S.getLangOpts())); - if ((!S.getLangOpts().OpenCLCPlusPlus && - ReadWriteImagesUnsupportedForOCLC) || - DeclTy->isPipeType()) { + if (ReadWriteImagesUnsupported || DeclTy->isPipeType()) { S.Diag(AL.getLoc(), diag::err_opencl_invalid_read_write) << AL << PDecl->getType() << DeclTy->isImageType(); D->setInvalidDecl(true); diff --git a/clang/test/Misc/opencl-c-3.0.incorrect_options.cl b/clang/test/Misc/opencl-c-3.0.incorrect_options.cl index 3ce0f325ce91..6232806c5c6d 100644 --- a/clang/test/Misc/opencl-c-3.0.incorrect_options.cl +++ b/clang/test/Misc/opencl-c-3.0.incorrect_options.cl @@ -3,6 +3,7 @@ // RUN: not %clang_cc1 -cl-std=clc++2021 -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=clc++2021 -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=clc++2021 -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_pipes,-__opencl_c_generic_address_space %s 2>&1 | FileCheck -check-prefix=CHECK-PIPES %s // RUN: not %clang_cc1 -cl-std=clc++2021 -triple spir-unknown-unknown -cl-ext=+__opencl_c_pipes,-__opencl_c_generic_address_space %s 2>&1 | FileCheck -check-prefix=CHECK-PIPES %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 diff --git a/clang/test/SemaOpenCL/access-qualifier.cl b/clang/test/SemaOpenCL/access-qualifier.cl index fc6ad750e717..726253c0b1a2 100644 --- a/clang/test/SemaOpenCL/access-qualifier.cl +++ b/clang/test/SemaOpenCL/access-qualifier.cl @@ -2,24 +2,38 @@ // RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL2.0 %s // RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL3.0 %s // RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL3.0 %s -cl-ext=-__opencl_c_read_write_images +// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=clc++2021 %s +// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=clc++2021 %s
[clang] 37cdc7e - [OpenCL] Supports optional pipe types in C++ for OpenCL 2021
Author: Justas Janickas Date: 2021-09-17T09:56:20+01:00 New Revision: 37cdc7ebd9a373100cbbe39f5b9be7a4e4f7813d URL: https://github.com/llvm/llvm-project/commit/37cdc7ebd9a373100cbbe39f5b9be7a4e4f7813d DIFF: https://github.com/llvm/llvm-project/commit/37cdc7ebd9a373100cbbe39f5b9be7a4e4f7813d.diff LOG: [OpenCL] Supports optional pipe types in C++ for OpenCL 2021 Adds support for a feature macro `__opencl_c_pipes` in C++ for OpenCL 2021 enabling a respective optional core feature from OpenCL 3.0. This change aims to achieve compatibility between C++ for OpenCL 2021 and OpenCL 3.0. Differential Revision: https://reviews.llvm.org/D109306 Added: Modified: clang/lib/Basic/TargetInfo.cpp clang/test/CodeGenOpenCL/address-spaces-mangling.cl clang/test/CodeGenOpenCL/address-spaces.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 Removed: diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp index 133391b0d20c4..a70abd1c9243b 100644 --- a/clang/lib/Basic/TargetInfo.cpp +++ b/clang/lib/Basic/TargetInfo.cpp @@ -413,9 +413,8 @@ void TargetInfo::adjust(DiagnosticsEngine , LangOptions ) { const auto = getSupportedOpenCLOpts(); Opts.OpenCLGenericAddressSpace = hasFeatureEnabled( OpenCLFeaturesMap, "__opencl_c_generic_address_space"); - if (Opts.OpenCLVersion == 300) -Opts.OpenCLPipes = -hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_pipes"); + Opts.OpenCLPipes = + hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_pipes"); } } diff --git a/clang/test/CodeGenOpenCL/address-spaces-mangling.cl b/clang/test/CodeGenOpenCL/address-spaces-mangling.cl index 7699c6f5d459c..32ba5d4c3a186 100644 --- a/clang/test/CodeGenOpenCL/address-spaces-mangling.cl +++ b/clang/test/CodeGenOpenCL/address-spaces-mangling.cl @@ -10,6 +10,8 @@ // RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL1.2 -emit-llvm -o - | FileCheck -check-prefix=OCL-12 %s // RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space -emit-llvm -o - | FileCheck -check-prefix=OCL-20 %s // RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL3.0 -cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes -emit-llvm -o - | FileCheck -check-prefix=OCL-12 %s +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=clc++2021 -cl-ext=+__opencl_c_generic_address_space -emit-llvm -o - | FileCheck -check-prefix=OCL-20 %s +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=clc++2021 -cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes -emit-llvm -o - | FileCheck -check-prefix=OCL-12 %s // We can't name this f as private is equivalent to default // no specifier given address space so we get multiple definition diff --git a/clang/test/CodeGenOpenCL/address-spaces.cl b/clang/test/CodeGenOpenCL/address-spaces.cl index 97236ffcd7734..b1c73561ade84 100644 --- a/clang/test/CodeGenOpenCL/address-spaces.cl +++ b/clang/test/CodeGenOpenCL/address-spaces.cl @@ -1,5 +1,6 @@ // RUN: %clang_cc1 %s -O0 -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,SPIR // RUN: %clang_cc1 %s -O0 -cl-std=CL3.0 -cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,SPIR +// RUN: %clang_cc1 %s -O0 -cl-std=clc++2021 -cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,SPIR // RUN: %clang_cc1 %s -O0 -DCL20 -cl-std=CL2.0 -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20SPIR // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s @@ -91,13 +92,13 @@ void f(int *arg) { typedef int int_td; typedef int *intp_td; -// SPIR: define {{(dso_local )?}}void @test_typedef(i32 addrspace(1)* %x, i32 addrspace(2)* %y, i32* %z) +// SPIR: define {{(dso_local )?}}void @{{.*}}test_typedef{{.*}}(i32 addrspace(1)* %x, i32 addrspace(2)* %y, i32* %z) void test_typedef(global int_td *x, constant int_td *y, intp_td z) { *x = *y; *z = 0; } -// SPIR: define {{(dso_local )?}}void @test_struct() +// SPIR: define {{(dso_local )?}}void @{{.*}}test_struct{{.*}}() void test_struct() { // SPIR: %ps = alloca %struct.S* // CL20SPIR: %ps = alloca %struct.S addrspace(4)* @@ -111,11 +112,11 @@ void test_struct() { #endif } -// SPIR-LABEL: define {{(dso_local )?}}void @test_void_par() +// SPIR-LABEL:
[clang] 054e331 - [OpenCL] Supports optional program scope global variables in C++ for OpenCL 2021
Author: Justas Janickas Date: 2021-09-16T12:48:01+01:00 New Revision: 054e331d9dbd3ce98b19625b75ba38dd9ebc34cc URL: https://github.com/llvm/llvm-project/commit/054e331d9dbd3ce98b19625b75ba38dd9ebc34cc DIFF: https://github.com/llvm/llvm-project/commit/054e331d9dbd3ce98b19625b75ba38dd9ebc34cc.diff LOG: [OpenCL] Supports optional program scope global variables in C++ for OpenCL 2021 Adds support for macro `__opencl_c_program_scope_global_variables` in C++ for OpenCL 2021 enabling a respective optional core feature from OpenCL 3.0. This change aims to achieve compatibility between C++ for OpenCL 2021 and OpenCL 3.0. Differential Revision: https://reviews.llvm.org/D109305 Added: Modified: clang/include/clang/Basic/OpenCLOptions.h clang/test/SemaOpenCL/storageclass.cl Removed: diff --git a/clang/include/clang/Basic/OpenCLOptions.h b/clang/include/clang/Basic/OpenCLOptions.h index 4bc568802584..d6cb1a210519 100644 --- a/clang/include/clang/Basic/OpenCLOptions.h +++ b/clang/include/clang/Basic/OpenCLOptions.h @@ -80,7 +80,7 @@ class OpenCLOptions { // C++ for OpenCL inherits rule from OpenCL C v2.0. bool areProgramScopeVariablesSupported(const LangOptions ) const { return Opts.getOpenCLCompatibleVersion() == 200 || - (Opts.OpenCLVersion == 300 && + (Opts.getOpenCLCompatibleVersion() == 300 && isSupported("__opencl_c_program_scope_global_variables", Opts)); } diff --git a/clang/test/SemaOpenCL/storageclass.cl b/clang/test/SemaOpenCL/storageclass.cl index 77880d1e3009..030d9c5ba54f 100644 --- a/clang/test/SemaOpenCL/storageclass.cl +++ b/clang/test/SemaOpenCL/storageclass.cl @@ -3,6 +3,10 @@ // 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 +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -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=clc++2021 -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=clc++2021 -cl-ext=-__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=+__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space static constant int G1 = 0; constant int G2 = 0; @@ -43,19 +47,23 @@ static private float g_private_static_var = 0; #endif static generic float g_generic_static_var = 0; -#if (__OPENCL_C_VERSION__ < 300) +#if (defined(__OPENCL_C_VERSION__) && __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 +#elif (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300) +#if !defined(__opencl_c_generic_address_space) +#if (__OPENCL_C_VERSION__ == 300) +// expected-error@-7 {{OpenCL C version 3.0 does not support the 'generic' type qualifier}} +#elif (__OPENCL_CPP_VERSION__ == 202100) +// expected-error@-9 {{C++ for OpenCL version 2021 does not support the 'generic' type qualifier}} +#endif +#endif +#if !defined(__opencl_c_program_scope_global_variables) +// expected-error@-13 {{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@-16 {{program scope variable must reside in global or constant address space}} +#endif #endif extern float g_implicit_extern_var; @@ -85,32 +93,36 @@ extern private float g_private_extern_var; #endif extern generic float g_generic_extern_var; -#if (__OPENCL_C_VERSION__ < 300) +#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300) //
[clang] 3b9470a - [OpenCL] Supports optional image types in C++ for OpenCL 2021
Author: Justas Janickas Date: 2021-09-15T10:03:47+01:00 New Revision: 3b9470a6c46d0ecdb586a5a1e9223ea0c832337c URL: https://github.com/llvm/llvm-project/commit/3b9470a6c46d0ecdb586a5a1e9223ea0c832337c DIFF: https://github.com/llvm/llvm-project/commit/3b9470a6c46d0ecdb586a5a1e9223ea0c832337c.diff LOG: [OpenCL] Supports optional image types in C++ for OpenCL 2021 Adds support for a feature macro `__opencl_c_images` in C++ for OpenCL 2021 enabling a respective optional core feature from OpenCL 3.0. This change aims to achieve compatibility between C++ for OpenCL 2021 and OpenCL 3.0. Differential Revision: https://reviews.llvm.org/D109002 Added: Modified: clang/lib/Sema/SemaType.cpp clang/test/SemaOpenCL/unsupported-image.cl Removed: diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index dcf18d3b4ba3d..f7f428c1e6d8d 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1732,7 +1732,12 @@ static QualType ConvertDeclSpecToType(TypeProcessingState ) { if (S.getLangOpts().OpenCL) { const auto = S.getOpenCLOptions(); +// FIXME: both variables IsOpenCLC30 and IsOpenCLC30Compatible should be +// unified into one when __opencl_c_3d_image_writes option is enabled in +// C++ for OpenCL 2021 bool IsOpenCLC30 = (S.getLangOpts().OpenCLVersion == 300); +bool IsOpenCLC30Compatible = +S.getLangOpts().getOpenCLCompatibleVersion() == 300; // OpenCL C v3.0 s6.3.3 - OpenCL image types require __opencl_c_images // support. // OpenCL C v3.0 s6.2.1 - OpenCL 3d image write types requires support @@ -1741,7 +1746,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState ) { // 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()) && -(IsOpenCLC30 && +(IsOpenCLC30Compatible && !OpenCLOptions.isSupported("__opencl_c_images", S.getLangOpts( { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension) << 0 << Result << "__opencl_c_images"; diff --git a/clang/test/SemaOpenCL/unsupported-image.cl b/clang/test/SemaOpenCL/unsupported-image.cl index 40772460e54d1..8db3f61b0146b 100644 --- a/clang/test/SemaOpenCL/unsupported-image.cl +++ b/clang/test/SemaOpenCL/unsupported-image.cl @@ -1,6 +1,8 @@ // 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 +// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=clc++2021 -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=clc++2021 -cl-ext=+__opencl_c_images %s #if defined(__opencl_c_images) && defined(__opencl_c_3d_image_writes) //expected-no-diagnostics ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 09dc454 - [OpenCL] Enables .rgba vector extension in C++ for OpenCL 2021
Author: Justas Janickas Date: 2021-09-14T13:05:42+01:00 New Revision: 09dc454b00b8ed0a19f766f760fa19e86a0b9059 URL: https://github.com/llvm/llvm-project/commit/09dc454b00b8ed0a19f766f760fa19e86a0b9059 DIFF: https://github.com/llvm/llvm-project/commit/09dc454b00b8ed0a19f766f760fa19e86a0b9059.diff LOG: [OpenCL] Enables .rgba vector extension in C++ for OpenCL 2021 `.rgba` vector extension setting in C++ for OpenCL 2021 is now performed analogously to OpenCL C 3.0. Test case added. Differential Revision: https://reviews.llvm.org/D109370 Added: Modified: clang/lib/Sema/SemaExprMember.cpp clang/test/SemaOpenCL/ext_vectors.cl Removed: diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp index 92b7464cd0bbf..0f0dd8a42cfca 100644 --- a/clang/lib/Sema/SemaExprMember.cpp +++ b/clang/lib/Sema/SemaExprMember.cpp @@ -340,7 +340,8 @@ CheckExtVectorComponent(Sema , QualType baseType, ExprValueKind , // Emit a warning if an rgba selector is used earlier than OpenCL C 3.0. if (HasRGBA || (*compStr && IsRGBA(*compStr))) { - if (S.getLangOpts().OpenCL && S.getLangOpts().OpenCLVersion < 300) { + if (S.getLangOpts().OpenCL && + S.getLangOpts().getOpenCLCompatibleVersion() < 300) { const char *DiagBegin = HasRGBA ? CompName->getNameStart() : compStr; S.Diag(OpLoc, diag::ext_opencl_ext_vector_type_rgba_selector) << StringRef(DiagBegin, 1) << SourceRange(CompLoc); diff --git a/clang/test/SemaOpenCL/ext_vectors.cl b/clang/test/SemaOpenCL/ext_vectors.cl index 7404f037d93f5..ce5b333bd8aab 100644 --- a/clang/test/SemaOpenCL/ext_vectors.cl +++ b/clang/test/SemaOpenCL/ext_vectors.cl @@ -2,6 +2,7 @@ // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++1.0 +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 typedef float float4 __attribute__((ext_vector_type(4))); @@ -9,13 +10,13 @@ void test_ext_vector_accessors(float4 V) { V = V.wzyx; V = V.abgr; -#if (__OPENCL_C_VERSION__ < 300) +#if ((defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300) || (defined(__OPENCL_CPP_VERSION__) && __OPENCL_CPP_VERSION__ < 202100)) // expected-warning@-2 {{vector component name 'a' is a feature from OpenCL version 3.0 onwards}} #endif V = V.xyzr; // expected-error@-1 {{illegal vector component name 'r'}} -#if (__OPENCL_C_VERSION__ < 300) +#if ((defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 300) || (defined(__OPENCL_CPP_VERSION__) && __OPENCL_CPP_VERSION__ < 202100)) // expected-warning@-3 {{vector component name 'r' is a feature from OpenCL version 3.0 onwards}} #endif } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] ad88632 - [OpenCL] Tests C++ for OpenCL version macros
Author: Justas Janickas Date: 2021-09-14T09:49:20+01:00 New Revision: ad88632b650325af755ae42ff29114c1f6eb2841 URL: https://github.com/llvm/llvm-project/commit/ad88632b650325af755ae42ff29114c1f6eb2841 DIFF: https://github.com/llvm/llvm-project/commit/ad88632b650325af755ae42ff29114c1f6eb2841.diff LOG: [OpenCL] Tests C++ for OpenCL version macros Version macro definitions are tested for C++ for OpenCL when explicit version is provided on command line via `-cl-std` flag. Differential Revision: https://reviews.llvm.org/D109366 Added: Modified: clang/test/Preprocessor/predefined-macros.c Removed: diff --git a/clang/test/Preprocessor/predefined-macros.c b/clang/test/Preprocessor/predefined-macros.c index 82077fcdbc76a..14b2d9529e9c2 100644 --- a/clang/test/Preprocessor/predefined-macros.c +++ b/clang/test/Preprocessor/predefined-macros.c @@ -137,6 +137,10 @@ // RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-FRM // RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=clc++ \ // RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CLCPP10 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=clc++1.0 \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CLCPP10 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=clc++2021 \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CLCPP2021 // CHECK-CL10: #define CL_VERSION_1_0 100 // CHECK-CL10: #define CL_VERSION_1_1 110 // CHECK-CL10: #define CL_VERSION_1_2 120 @@ -174,9 +178,15 @@ // CHECK-CL30-NOT: #define __FAST_RELAXED_MATH__ 1 // CHECK-FRM: #define __FAST_RELAXED_MATH__ 1 // CHECK-CLCPP10: #define __CL_CPP_VERSION_1_0__ 100 +// CHECK-CLCPP10: #define __CL_CPP_VERSION_2021__ 202100 // CHECK-CLCPP10: #define __OPENCL_CPP_VERSION__ 100 // CHECK-CLCPP10-NOT: #define __FAST_RELAXED_MATH__ 1 // CHECK-CLCPP10-NOT: #define __ENDIAN_LITTLE__ 1 +// CHECK-CLCPP2021: #define __CL_CPP_VERSION_1_0__ 100 +// CHECK-CLCPP2021: #define __CL_CPP_VERSION_2021__ 202100 +// CHECK-CLCPP2021: #define __OPENCL_CPP_VERSION__ 202100 +// CHECK-CLCPP2021-NOT: #define __FAST_RELAXED_MATH__ 1 +// CHECK-CLCPP2021-NOT: #define __ENDIAN_LITTLE__ 1 // RUN: %clang_cc1 %s -E -dM -o - -x cl \ // RUN: | FileCheck %s --check-prefix=MSCOPE ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] c33e296 - [OpenCL] Disallows static kernel functions in C++ for OpenCL
Author: Justas Janickas Date: 2021-09-07T10:23:50+01:00 New Revision: c33e296be1daa621f5933f3729a0ce51172f1505 URL: https://github.com/llvm/llvm-project/commit/c33e296be1daa621f5933f3729a0ce51172f1505 DIFF: https://github.com/llvm/llvm-project/commit/c33e296be1daa621f5933f3729a0ce51172f1505.diff LOG: [OpenCL] Disallows static kernel functions in C++ for OpenCL It is disallowed in OpenCL C to declare static kernel functions and C++ for OpenCL is expected to inherit such behaviour. Error is now correctly reported in C++ for OpenCL when declaring a static kernel function. Differential Revision: https://reviews.llvm.org/D109150 Added: Modified: clang/lib/Sema/SemaDecl.cpp clang/test/SemaOpenCL/storageclass-cl20.cl Removed: diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index f33811f63c71e..92c1a37fdab96 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -9970,8 +9970,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator , DeclContext *DC, if (getLangOpts().OpenCL && NewFD->hasAttr()) { // OpenCL v1.2 s6.8 static is invalid for kernel functions. -if ((getLangOpts().OpenCLVersion >= 120) -&& (SC == SC_Static)) { +if (SC == SC_Static) { Diag(D.getIdentifierLoc(), diag::err_static_kernel); D.setInvalidType(); } diff --git a/clang/test/SemaOpenCL/storageclass-cl20.cl b/clang/test/SemaOpenCL/storageclass-cl20.cl index 581701d2a6a54..f07966e5bd01f 100644 --- a/clang/test/SemaOpenCL/storageclass-cl20.cl +++ b/clang/test/SemaOpenCL/storageclass-cl20.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=clc++1.0 int G2 = 0; global int G3 = 0; @@ -18,6 +19,9 @@ extern local float g_local_extern_var; // expected-error {{extern variable m extern private float g_private_extern_var; // expected-error {{extern variable must reside in global or constant address space}} extern generic float g_generic_extern_var; // expected-error {{extern variable must reside in global or constant address space}} +static void kernel bar() { // expected-error{{kernel functions cannot be declared static}} +} + void kernel foo() { constant int L1 = 0; local int L2; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 52f7cd2 - [OpenCL] Fix condition macro name in test
Author: Justas Janickas Date: 2021-09-06T13:13:13+01:00 New Revision: 52f7cd23b4af84c9e195e9e2263b8ece8d233fe2 URL: https://github.com/llvm/llvm-project/commit/52f7cd23b4af84c9e195e9e2263b8ece8d233fe2 DIFF: https://github.com/llvm/llvm-project/commit/52f7cd23b4af84c9e195e9e2263b8ece8d233fe2.diff LOG: [OpenCL] Fix condition macro name in test Added: Modified: clang/test/SemaOpenCL/access-qualifier.cl Removed: diff --git a/clang/test/SemaOpenCL/access-qualifier.cl b/clang/test/SemaOpenCL/access-qualifier.cl index c538e73253ce0..fc6ad750e7174 100644 --- a/clang/test/SemaOpenCL/access-qualifier.cl +++ b/clang/test/SemaOpenCL/access-qualifier.cl @@ -79,7 +79,7 @@ kernel void read_write_twice_typedef(read_write img1d_rw i){} // expected-warnin // expected-note@-67 {{previously declared 'read_write' here}} #endif -#if OPENCL_C_VERSION__ >= 200 +#if __OPENCL_C_VERSION__ >= 200 void myPipeWrite(write_only pipe int); // expected-note {{passing argument to parameter here}} kernel void k14(read_only pipe int p) { myPipeWrite(p); // expected-error {{passing '__private read_only pipe int' to parameter of incompatible type 'write_only pipe int'}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cc9260a - [OpenCL] Supports optional generic address space semantics in C++ for OpenCL 2021
Author: Justas Janickas Date: 2021-09-06T10:20:38+01:00 New Revision: cc9260a0fb7c42ac8a8bb87eac1e11900c25ed20 URL: https://github.com/llvm/llvm-project/commit/cc9260a0fb7c42ac8a8bb87eac1e11900c25ed20 DIFF: https://github.com/llvm/llvm-project/commit/cc9260a0fb7c42ac8a8bb87eac1e11900c25ed20.diff LOG: [OpenCL] Supports optional generic address space semantics in C++ for OpenCL 2021 Adds support for a feature macro `__opencl_c_generic_adress_space` in C++ for OpenCL 2021 enabling a respective optional core feature from OpenCL 3.0. Testing is only performed in SemaOpenCL because generic address space functionality is yet to be implemented in C++ for OpenCL 2021. This change aims to achieve compatibility between C++ for OpenCL 2021 and OpenCL 3.0. Differential Revision: https://reviews.llvm.org/D108461 Added: Modified: clang/lib/Basic/TargetInfo.cpp clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl clang/test/SemaOpenCL/address-spaces.cl Removed: diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp index 5f8e04c2bd6c4..bc5f86a28d89d 100644 --- a/clang/lib/Basic/TargetInfo.cpp +++ b/clang/lib/Basic/TargetInfo.cpp @@ -406,12 +406,13 @@ void TargetInfo::adjust(DiagnosticsEngine , LangOptions ) { // for OpenCL C 2.0 but with no access to target capabilities. Target // should be immutable once created and thus these language options need // to be defined only once. -if (Opts.OpenCLVersion == 300) { +if (Opts.getOpenCLCompatibleVersion() == 300) { const auto = getSupportedOpenCLOpts(); Opts.OpenCLGenericAddressSpace = hasFeatureEnabled( OpenCLFeaturesMap, "__opencl_c_generic_address_space"); - Opts.OpenCLPipes = - hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_pipes"); + if (Opts.OpenCLVersion == 300) +Opts.OpenCLPipes = +hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_pipes"); } } diff --git a/clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl b/clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl index 7531e742f0264..482254190789a 100644 --- a/clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl +++ b/clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl @@ -1,12 +1,15 @@ // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DCONSTANT -cl-std=CL2.0 // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=CL2.0 // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=CL2.0 -// 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=clc++1.0 +// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=clc++1.0 +// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=clc++1.0 // 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 +// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DCONSTANT -cl-std=clc++2021 -cl-ext=+__opencl_c_generic_address_space +// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=clc++2021 -cl-ext=+__opencl_c_generic_address_space +// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=clc++2021 -cl-ext=+__opencl_c_generic_address_space /* OpenCLC v2.0 adds a set of restrictions for conversions between pointers to * diff erent address spaces, mainly described in Sections 6.5.5 and 6.5.6. diff --git a/clang/test/SemaOpenCL/address-spaces.cl b/clang/test/SemaOpenCL/address-spaces.cl index 61a1c8ec73ee3..21992d970560f 100644 --- a/clang/test/SemaOpenCL/address-spaces.cl +++ b/clang/test/SemaOpenCL/address-spaces.cl @@ -1,7 +1,8 @@ // 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 +// RUN: %clang_cc1 %s -cl-std=clc++1.0 -verify -pedantic
[clang] bd74f4b - [OpenCL] Supports optional 64-bit floating point types in C++ for OpenCL 2021
Author: Justas Janickas Date: 2021-09-03T10:58:05+01:00 New Revision: bd74f4b108346deb37f305690f164181df2e8602 URL: https://github.com/llvm/llvm-project/commit/bd74f4b108346deb37f305690f164181df2e8602 DIFF: https://github.com/llvm/llvm-project/commit/bd74f4b108346deb37f305690f164181df2e8602.diff LOG: [OpenCL] Supports optional 64-bit floating point types in C++ for OpenCL 2021 Adds support for a feature macro `__opencl_c_fp64` in C++ for OpenCL 2021 enabling a respective optional core feature from OpenCL 3.0. This change aims to achieve compatibility between C++ for OpenCL 2021 and OpenCL 3.0. Differential Revision: https://reviews.llvm.org/D108989 Added: Modified: 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/fp64-fp16-options.cl Removed: diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 9d7738c3a2349..11d8c3589c273 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3870,7 +3870,7 @@ ExprResult Sema::ActOnNumericConstant(const Token , Scope *UDLScope) { "cl_khr_fp64", getLangOpts())) { // Impose single-precision float type when cl_khr_fp64 is not enabled. Diag(Tok.getLocation(), diag::warn_double_const_requires_fp64) -<< (getLangOpts().OpenCLVersion >= 300); +<< (getLangOpts().getOpenCLCompatibleVersion() >= 300); Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get(); } } diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index f493798c43c17..21ef55bc87f27 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1532,7 +1532,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState ) { if (!S.getOpenCLOptions().isSupported("cl_khr_fp64", S.getLangOpts())) S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension) << 0 << Result -<< (S.getLangOpts().OpenCLVersion == 300 +<< (S.getLangOpts().getOpenCLCompatibleVersion() == 300 ? "cl_khr_fp64 and __opencl_c_fp64" : "cl_khr_fp64"); else if (!S.getOpenCLOptions().isAvailableOption("cl_khr_fp64", S.getLangOpts())) diff --git a/clang/test/CodeGenOpenCL/printf.cl b/clang/test/CodeGenOpenCL/printf.cl index c68c43bcc2864..8c63796d876ba 100644 --- a/clang/test/CodeGenOpenCL/printf.cl +++ b/clang/test/CodeGenOpenCL/printf.cl @@ -2,6 +2,8 @@ // RUN: %clang_cc1 -cl-std=CL1.2 -cl-ext=-cl_khr_fp64 -triple spir-unknown-unknown -disable-llvm-passes -emit-llvm -o - %s | FileCheck -check-prefixes=NOFP64,ALL %s // RUN: %clang_cc1 -cl-std=CL3.0 -cl-ext=+__opencl_c_fp64,+cl_khr_fp64 -triple spir-unknown-unknown -disable-llvm-passes -emit-llvm -o - %s | FileCheck -check-prefixes=FP64,ALL %s // RUN: %clang_cc1 -cl-std=CL3.0 -cl-ext=-__opencl_c_fp64,-cl_khr_fp64 -triple spir-unknown-unknown -disable-llvm-passes -emit-llvm -o - %s | FileCheck -check-prefixes=NOFP64,ALL %s +// RUN: %clang_cc1 -cl-std=clc++2021 -cl-ext=+__opencl_c_fp64,+cl_khr_fp64 -triple spir-unknown-unknown -disable-llvm-passes -emit-llvm -o - %s | FileCheck -check-prefixes=FP64,ALL %s +// RUN: %clang_cc1 -cl-std=clc++2021 -cl-ext=-__opencl_c_fp64,-cl_khr_fp64 -triple spir-unknown-unknown -disable-llvm-passes -emit-llvm -o - %s | FileCheck -check-prefixes=NOFP64,ALL %s typedef __attribute__((ext_vector_type(2))) float float2; typedef __attribute__((ext_vector_type(2))) half half2; @@ -14,25 +16,24 @@ int printf(__constant const char* st, ...) __attribute__((format(printf, 1, 2))) // ALL-LABEL: @test_printf_float2( -// FP64: %call = call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([7 x i8], [7 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x float> %0) +// FP64: %call = call spir_func i32 (i8 addrspace(2)*, ...) @{{.*}}printf{{.*}}(i8 addrspace(2)* getelementptr inbounds ([7 x i8], [7 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x float> %0) - -// NOFP64: call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([7 x i8], [7 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x float> %0) +// NOFP64: call spir_func i32 (i8 addrspace(2)*, ...) @{{.*}}printf{{.*}}(i8 addrspace(2)* getelementptr inbounds ([7 x i8], [7 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x float> %0) kernel void test_printf_float2(float2 arg) { printf("%v2hlf", arg); } // ALL-LABEL: @test_printf_half2( -// FP64: %call = call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([6 x i8], [6 x i8] addrspace(2)* @.str.1, i32 0, i32 0), <2 x half> %0) +// FP64: %call = call spir_func i32 (i8 addrspace(2)*, ...)
[clang] fb321c2 - [OpenCL] Define OpenCL 3.0 optional core features in C++ for OpenCL 2021
Author: Justas Janickas Date: 2021-09-01T10:15:17+01:00 New Revision: fb321c2ea274c1bd1e1b294f2c090f1c0d9a97fe URL: https://github.com/llvm/llvm-project/commit/fb321c2ea274c1bd1e1b294f2c090f1c0d9a97fe DIFF: https://github.com/llvm/llvm-project/commit/fb321c2ea274c1bd1e1b294f2c090f1c0d9a97fe.diff LOG: [OpenCL] Define OpenCL 3.0 optional core features in C++ for OpenCL 2021 Modifies OpenCL 3.0 optional core feature macro definitions so that they are set analogously in C++ for OpenCL 2021. This change aims to achieve compatibility between C++ for OpenCL 2021 and OpenCL 3.0. Differential Revision: https://reviews.llvm.org/D108704 Added: Modified: clang/lib/Headers/opencl-c-base.h clang/test/Headers/opencl-c-header.cl clang/test/SemaOpenCL/features.cl Removed: diff --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h index ff8b776d03bb8..f3605c659d952 100644 --- a/clang/lib/Headers/opencl-c-base.h +++ b/clang/lib/Headers/opencl-c-base.h @@ -30,7 +30,7 @@ #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) +#if (__OPENCL_CPP_VERSION__ == 100 || __OPENCL_C_VERSION__ == 200) #define __opencl_c_pipes 1 #define __opencl_c_generic_address_space 1 #define __opencl_c_work_group_collective_functions 1 @@ -45,12 +45,12 @@ #endif // Define header-only feature macros for OpenCL C 3.0. -#if (__OPENCL_C_VERSION__ == 300) +#if (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300) // For the SPIR target all features are supported. #if defined(__SPIR__) #define __opencl_c_atomic_scope_all_devices 1 #endif // defined(__SPIR__) -#endif // (__OPENCL_C_VERSION__ == 300) +#endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300) // built-in scalar data types: diff --git a/clang/test/Headers/opencl-c-header.cl b/clang/test/Headers/opencl-c-header.cl index e7d0ae017d3a7..50b9ebba8f0d2 100644 --- a/clang/test/Headers/opencl-c-header.cl +++ b/clang/test/Headers/opencl-c-header.cl @@ -175,13 +175,13 @@ global atomic_int z = ATOMIC_VAR_INIT(99); #endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200) // OpenCL C features. -#if (__OPENCL_C_VERSION__ == 300) +#if (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300) #if __opencl_c_atomic_scope_all_devices != 1 #error "Incorrectly defined feature macro __opencl_c_atomic_scope_all_devices" #endif -#elif (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200) +#elif (__OPENCL_CPP_VERSION__ == 100 || __OPENCL_C_VERSION__ == 200) #ifndef __opencl_c_pipes #error "Feature macro __opencl_c_pipes should be defined" @@ -262,6 +262,6 @@ global atomic_int z = ATOMIC_VAR_INIT(99); #error "Incorrect feature macro __opencl_c_subgroups define" #endif -#endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200) +#endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300) #endif // defined(__SPIR__) diff --git a/clang/test/SemaOpenCL/features.cl b/clang/test/SemaOpenCL/features.cl index 57c52694b6850..af058b5e69828 100644 --- a/clang/test/SemaOpenCL/features.cl +++ b/clang/test/SemaOpenCL/features.cl @@ -6,6 +6,14 @@ // 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 +// RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=clc++2021 -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=clc++2021 -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=clc++2021 \ +// 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=clc++2021 -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 @@ -15,7 +23,7 @@ // 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: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=clc++1.0 \ // RUN: | FileCheck -match-full-lines %s
[clang] f9bc1b3 - [OpenCL] Defines helper function for kernel language compatible OpenCL version
Author: Justas Janickas Date: 2021-08-31T10:08:38+01:00 New Revision: f9bc1b3bee557de5735c745f9558c47ca568bd96 URL: https://github.com/llvm/llvm-project/commit/f9bc1b3bee557de5735c745f9558c47ca568bd96 DIFF: https://github.com/llvm/llvm-project/commit/f9bc1b3bee557de5735c745f9558c47ca568bd96.diff LOG: [OpenCL] Defines helper function for kernel language compatible OpenCL version This change defines a helper function getOpenCLCompatibleVersion() inside LangOptions class. The function contains mapping between C++ for OpenCL versions and their corresponding compatible OpenCL versions. This mapping function should be updated each time a new C++ for OpenCL language version is introduced. The helper function is expected to simplify conditions on OpenCL C and C++ for OpenCL versions inside compiler code. Code refactoring performed. Differential Revision: https://reviews.llvm.org/D108693 Added: Modified: clang/include/clang/Basic/LangOptions.h clang/include/clang/Basic/OpenCLOptions.h clang/lib/Basic/Builtins.cpp clang/lib/Basic/LangOptions.cpp clang/lib/Basic/Targets.cpp clang/lib/CodeGen/CodeGenModule.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/lib/Parse/ParseDecl.cpp clang/lib/Sema/DeclSpec.cpp clang/lib/Sema/Sema.cpp clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaType.cpp Removed: diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index ea6a792f0598..43e33c7029b8 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -444,6 +444,9 @@ class LangOptions : public LangOptionsBase { /// Return the OpenCL C or C++ version as a VersionTuple. VersionTuple getOpenCLVersionTuple() const; + /// Return the OpenCL version that kernel language is compatible with + unsigned getOpenCLCompatibleVersion() const; + /// Return the OpenCL C or C++ for OpenCL language name and version /// as a string. std::string getOpenCLVersionString() const; diff --git a/clang/include/clang/Basic/OpenCLOptions.h b/clang/include/clang/Basic/OpenCLOptions.h index 1a035626fade..4bc568802584 100644 --- a/clang/include/clang/Basic/OpenCLOptions.h +++ b/clang/include/clang/Basic/OpenCLOptions.h @@ -58,7 +58,7 @@ static inline OpenCLVersionID encodeOpenCLVersion(unsigned OpenCLVersion) { // mask. static inline bool isOpenCLVersionContainedInMask(const LangOptions , unsigned Mask) { - auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion; + auto CLVer = LO.getOpenCLCompatibleVersion(); OpenCLVersionID Code = encodeOpenCLVersion(CLVer); return Mask & Code; } @@ -79,7 +79,7 @@ class OpenCLOptions { // the __opencl_c_program_scope_global_variables feature is supported // C++ for OpenCL inherits rule from OpenCL C v2.0. bool areProgramScopeVariablesSupported(const LangOptions ) const { -return Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200 || +return Opts.getOpenCLCompatibleVersion() == 200 || (Opts.OpenCLVersion == 300 && isSupported("__opencl_c_program_scope_global_variables", Opts)); } @@ -115,8 +115,7 @@ class OpenCLOptions { // Is option available in OpenCL version \p LO. bool isAvailableIn(const LangOptions ) const { // In C++ mode all extensions should work at least as in v2.0. - auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion; - return CLVer >= Avail; + return LO.getOpenCLCompatibleVersion() >= Avail; } // Is core option in OpenCL version \p LO. diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp index 7118aa9dc210..2b0f4071662c 100644 --- a/clang/lib/Basic/Builtins.cpp +++ b/clang/lib/Basic/Builtins.cpp @@ -72,7 +72,7 @@ bool Builtin::Context::builtinIsSupported(const Builtin::Info , bool OclC1Unsupported = (LangOpts.OpenCLVersion / 100) != 1 && (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES ) == OCLC1X_LANG; bool OclC2Unsupported = - (LangOpts.OpenCLVersion != 200 && !LangOpts.OpenCLCPlusPlus) && + (LangOpts.getOpenCLCompatibleVersion() != 200) && (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES) == OCLC20_LANG; bool OclCUnsupported = !LangOpts.OpenCL && (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES); diff --git a/clang/lib/Basic/LangOptions.cpp b/clang/lib/Basic/LangOptions.cpp index 3e3e7fe3dc15..b6dc73d66304 100644 --- a/clang/lib/Basic/LangOptions.cpp +++ b/clang/lib/Basic/LangOptions.cpp @@ -52,6 +52,16 @@ VersionTuple LangOptions::getOpenCLVersionTuple() const { return VersionTuple(Ver / 100, (Ver % 100) / 10); } +unsigned LangOptions::getOpenCLCompatibleVersion() const { + if (!OpenCLCPlusPlus) +return OpenCLVersion; + if
[clang] 9dc92bb - [OpenCL][NFC] Fix code example in __remove_address_space documentation.
Author: Justas Janickas Date: 2021-08-25T21:24:32+01:00 New Revision: 9dc92bba6c742216096e33402a1a8aebf5ca48b7 URL: https://github.com/llvm/llvm-project/commit/9dc92bba6c742216096e33402a1a8aebf5ca48b7 DIFF: https://github.com/llvm/llvm-project/commit/9dc92bba6c742216096e33402a1a8aebf5ca48b7.diff LOG: [OpenCL][NFC] Fix code example in __remove_address_space documentation. Added: Modified: clang/docs/LanguageExtensions.rst Removed: diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index fada65c487bc..3193c8cdc11e 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -1978,7 +1978,7 @@ address space qualifiers, therefore, other type qualifiers such as void foo(T *par){ T var1; // error - local function variable with global address space __private T var2; // error - conflicting address space qualifiers -__private __remove_address_space var3; // var3 is __private int +__private __remove_address_space::type var3; // var3 is __private int } void bar(){ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 9ae9262 - [OpenCL] Fix version reporting of C++ for OpenCL 2021
Author: Justas Janickas Date: 2021-08-20T08:58:12+01:00 New Revision: 9ae9262857a1e7aadc385a68a00755896440f6b1 URL: https://github.com/llvm/llvm-project/commit/9ae9262857a1e7aadc385a68a00755896440f6b1 DIFF: https://github.com/llvm/llvm-project/commit/9ae9262857a1e7aadc385a68a00755896440f6b1.diff LOG: [OpenCL] Fix version reporting of C++ for OpenCL 2021 C++ for OpenCL version 2021 and later are expected to consist of a major version number only. Therefore, a different constructor for `VersionTuple` needs to be called when reporting language version. Differential Revision: https://reviews.llvm.org/D108379 Added: Modified: clang/lib/Basic/LangOptions.cpp Removed: diff --git a/clang/lib/Basic/LangOptions.cpp b/clang/lib/Basic/LangOptions.cpp index 169b67949038..3e3e7fe3dc15 100644 --- a/clang/lib/Basic/LangOptions.cpp +++ b/clang/lib/Basic/LangOptions.cpp @@ -47,6 +47,8 @@ bool LangOptions::isNoBuiltinFunc(StringRef FuncName) const { VersionTuple LangOptions::getOpenCLVersionTuple() const { const int Ver = OpenCLCPlusPlus ? OpenCLCPlusPlusVersion : OpenCLVersion; + if (OpenCLCPlusPlus && Ver != 100) +return VersionTuple(Ver / 100); return VersionTuple(Ver / 100, (Ver % 100) / 10); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 0d0628b - [OpenCL] C++ for OpenCL version 2021 introduced to command line.
Author: Justas Janickas Date: 2021-08-18T10:08:59+01:00 New Revision: 0d0628b2d213a43f80e4967d83b905c6d2211651 URL: https://github.com/llvm/llvm-project/commit/0d0628b2d213a43f80e4967d83b905c6d2211651 DIFF: https://github.com/llvm/llvm-project/commit/0d0628b2d213a43f80e4967d83b905c6d2211651.diff LOG: [OpenCL] C++ for OpenCL version 2021 introduced to command line. Introduces language standard `lang_openclcpp2021` and allows `clc++2021` as a version flag for `-cl-std` in command line. Defines macros related to C++ for OpenCL version 2021. C++ for OpenCL version 2021 has been proposed in an RFC: https://lists.llvm.org/pipermail/cfe-dev/2021-August/068593.html Differential Revision: https://reviews.llvm.org/D108038 Added: Modified: clang/include/clang/Basic/LangStandards.def clang/include/clang/Driver/Options.td clang/lib/Frontend/CompilerInvocation.cpp clang/lib/Frontend/InitPreprocessor.cpp clang/test/Driver/autocomplete.c clang/test/Driver/unknown-std.cl clang/test/Frontend/stdlang.c Removed: diff --git a/clang/include/clang/Basic/LangStandards.def b/clang/include/clang/Basic/LangStandards.def index 160dc3f2405a7..6056cfd65bbbf 100644 --- a/clang/include/clang/Basic/LangStandards.def +++ b/clang/include/clang/Basic/LangStandards.def @@ -180,12 +180,18 @@ LANGSTANDARD(opencl20, "cl2.0", LANGSTANDARD(opencl30, "cl3.0", OpenCL, "OpenCL 3.0", LineComment | C99 | Digraphs | HexFloat | OpenCL) + LANGSTANDARD(openclcpp10, "clc++1.0", OpenCL, "C++ for OpenCL 1.0", LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 | Digraphs | HexFloat | OpenCL) LANGSTANDARD_ALIAS(openclcpp10, "clc++") +LANGSTANDARD(openclcpp2021, "clc++2021", + OpenCL, "C++ for OpenCL 2021", + LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 | + Digraphs | HexFloat | OpenCL) + LANGSTANDARD_ALIAS_DEPR(opencl10, "CL") LANGSTANDARD_ALIAS_DEPR(opencl11, "CL1.1") LANGSTANDARD_ALIAS_DEPR(opencl12, "CL1.2") @@ -193,6 +199,7 @@ LANGSTANDARD_ALIAS_DEPR(opencl20, "CL2.0") LANGSTANDARD_ALIAS_DEPR(opencl30, "CL3.0") LANGSTANDARD_ALIAS_DEPR(openclcpp10, "CLC++") LANGSTANDARD_ALIAS_DEPR(openclcpp10, "CLC++1.0") +LANGSTANDARD_ALIAS_DEPR(openclcpp2021, "CLC++2021") // CUDA LANGSTANDARD(cuda, "cuda", CUDA, "NVIDIA CUDA(tm)", diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 5d43660ca7dec..fd9ecd7394a01 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -866,7 +866,7 @@ def cl_no_signed_zeros : Flag<["-"], "cl-no-signed-zeros">, Group, MarshallingInfoFlag>; def cl_std_EQ : Joined<["-"], "cl-std=">, Group, Flags<[CC1Option]>, HelpText<"OpenCL language standard to compile for.">, - Values<"cl,CL,cl1.0,CL1.0,cl1.1,CL1.1,cl1.2,CL1.2,cl2.0,CL2.0,cl3.0,CL3.0,clc++,CLC++,clc++1.0,CLC++1.0">; + Values<"cl,CL,cl1.0,CL1.0,cl1.1,CL1.1,cl1.2,CL1.2,cl2.0,CL2.0,cl3.0,CL3.0,clc++,CLC++,clc++1.0,CLC++1.0,clc++2021,CLC++2021">; def cl_denorms_are_zero : Flag<["-"], "cl-denorms-are-zero">, Group, HelpText<"OpenCL only. Allow denormals to be flushed to zero.">; def cl_fp32_correctly_rounded_divide_sqrt : Flag<["-"], "cl-fp32-correctly-rounded-divide-sqrt">, Group, Flags<[CC1Option]>, diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 83dc6ec858fa9..eb691679ca778 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -3165,6 +3165,8 @@ void CompilerInvocation::setLangDefaults(LangOptions , InputKind IK, Opts.OpenCLVersion = 300; else if (LangStd == LangStandard::lang_openclcpp10) Opts.OpenCLCPlusPlusVersion = 100; + else if (LangStd == LangStandard::lang_openclcpp2021) +Opts.OpenCLCPlusPlusVersion = 202100; // OpenCL has some additional defaults. if (Opts.OpenCL) { @@ -3314,6 +3316,7 @@ void CompilerInvocation::GenerateLangArgs(const LangOptions , case LangStandard::lang_opencl20: case LangStandard::lang_opencl30: case LangStandard::lang_openclcpp10: + case LangStandard::lang_openclcpp2021: StdOpt = OPT_cl_std_EQ; break; default: @@ -3612,6 +3615,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions , ArgList , .Cases("cl3.0", "CL3.0", LangStandard::lang_opencl30) .Cases("clc++", "CLC++", LangStandard::lang_openclcpp10) .Cases("clc++1.0", "CLC++1.0", LangStandard::lang_openclcpp10) +.Cases("clc++2021", "CLC++2021", LangStandard::lang_openclcpp2021) .Default(LangStandard::lang_unspecified); if (OpenCLLangStd == LangStandard::lang_unspecified) { diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index
[clang] cfdfb75 - [OpenCL] Clang diagnostics allow reporting C++ for OpenCL version.
Author: Justas Janickas Date: 2021-08-13T13:55:22+01:00 New Revision: cfdfb75c1ff354471bcea5fad872e40e345016ae URL: https://github.com/llvm/llvm-project/commit/cfdfb75c1ff354471bcea5fad872e40e345016ae DIFF: https://github.com/llvm/llvm-project/commit/cfdfb75c1ff354471bcea5fad872e40e345016ae.diff LOG: [OpenCL] Clang diagnostics allow reporting C++ for OpenCL version. Some Clang diagnostics could only report OpenCL C version. Because C++ for OpenCL can be used as an alternative to OpenCL C, the text for diagnostics should reflect that. Desrciptions modified for these diagnostics: `err_opencl_unknown_type_specifier` `warn_option_invalid_ocl_version` `err_attribute_requires_opencl_version` `warn_opencl_attr_deprecated_ignored` `ext_opencl_ext_vector_type_rgba_selector` Differential Revision: https://reviews.llvm.org/D107648 Added: Modified: clang/include/clang/Basic/DiagnosticCommonKinds.td clang/include/clang/Basic/DiagnosticFrontendKinds.td clang/include/clang/Basic/DiagnosticSemaKinds.td clang/include/clang/Basic/LangOptions.h clang/lib/Basic/LangOptions.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/lib/Parse/ParseDecl.cpp clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/test/Frontend/opencl.cl clang/test/SemaOpenCL/ext_vectors.cl clang/test/SemaOpenCL/nosvm.cl Removed: diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td b/clang/include/clang/Basic/DiagnosticCommonKinds.td index 4dff3379ed35b..4e21e276c69c5 100644 --- a/clang/include/clang/Basic/DiagnosticCommonKinds.td +++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td @@ -149,8 +149,8 @@ def err_nullability_conflicting : Error< // OpenCL Section 6.8.g def err_opencl_unknown_type_specifier : Error< - "%select{OpenCL C|C++ for OpenCL}0 version %1 does not support the " - "'%2' %select{type qualifier|storage class specifier}3">; + "%0 does not support the '%1' " + "%select{type qualifier|storage class specifier}2">; def warn_unknown_attribute_ignored : Warning< "unknown attribute %0 ignored">, InGroup; diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index 4bc5097762186..2bbc93d5682ce 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -247,7 +247,7 @@ def err_invalid_vfs_overlay : Error< "invalid virtual filesystem overlay file '%0'">, DefaultFatal; def warn_option_invalid_ocl_version : Warning< - "OpenCL version %0 does not support the option '%1'">, InGroup; + "%0 does not support the option '%1'">, InGroup; def err_builtin_needs_feature : Error<"%0 needs target feature %1">; def err_function_needs_feature : Error< diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 73217b418e81f..cbcc0e1f11c48 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -2959,7 +2959,7 @@ def err_attribute_requires_positive_integer : Error< "%0 attribute requires a %select{positive|non-negative}1 " "integral compile time constant expression">; def err_attribute_requires_opencl_version : Error< - "%0 attribute requires OpenCL version %1%select{| or above}2">; + "attribute %0 is supported in the OpenCL version %1%select{| onwards}2">; def err_invalid_branch_protection_spec : Error< "invalid or misplaced branch protection specification '%0'">; def warn_unsupported_target_attribute @@ -10098,8 +10098,7 @@ def err_opencl_type_can_only_be_used_as_function_parameter : Error < def err_opencl_type_not_found : Error< "%0 type %1 not found; include the base header with -finclude-default-header">; def warn_opencl_attr_deprecated_ignored : Warning < - "%0 attribute is deprecated and ignored in OpenCL version %1">, - InGroup; + "%0 attribute is deprecated and ignored in %1">, InGroup; def err_opencl_variadic_function : Error< "invalid prototype, variadic arguments are not allowed in OpenCL">; def err_opencl_requires_extension : Error< @@ -10164,7 +10163,7 @@ def err_opencl_builtin_expected_type : Error< // OpenCL v3.0 s6.3.7 - Vector Components def ext_opencl_ext_vector_type_rgba_selector: ExtWarn< - "vector component name '%0' is an OpenCL C version 3.0 feature">, + "vector component name '%0' is a feature from OpenCL version 3.0 onwards">, InGroup; def err_openclcxx_placement_new : Error< diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index 72793114dbb38..ea6a792f0598b 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -444,6 +444,10 @@ class LangOptions : public LangOptionsBase { /// Return the OpenCL C or C++ version as a VersionTuple.
[clang] a5a2f05 - [C++4OpenCL] Introduces __remove_address_space utility
Author: Justas Janickas Date: 2021-08-06T10:40:22+01:00 New Revision: a5a2f05dcc803e79a797fb82dc0932a1a00ac46f URL: https://github.com/llvm/llvm-project/commit/a5a2f05dcc803e79a797fb82dc0932a1a00ac46f DIFF: https://github.com/llvm/llvm-project/commit/a5a2f05dcc803e79a797fb82dc0932a1a00ac46f.diff LOG: [C++4OpenCL] Introduces __remove_address_space utility This change provides a way to conveniently declare types that have address space qualifiers removed. Since OpenCL adds address spaces implicitly even when they are not specified in source, it is useful to allow deriving address space unqualified types. Fixes llvm.org/PR45326 Differential Revision: https://reviews.llvm.org/D106785 Added: clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp Modified: clang/docs/LanguageExtensions.rst clang/lib/Headers/opencl-c-base.h Removed: diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index aaee136530fef..6ced38dd2faef 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -1961,6 +1961,30 @@ between the host and device is known to be compatible. global OnlySL *d, ); +Remove address space builtin function +- + +``__remove_address_space`` allows to derive types in C++ for OpenCL +that have address space qualifiers removed. This utility only affects +address space qualifiers, therefore, other type qualifiers such as +``const`` or ``volatile`` remain unchanged. + +**Example of Use**: + +.. code-block:: c++ + + template + void foo(T *par){ +T var1; // error - local function variable with global address space +__private T var2; // error - conflicting address space qualifiers +__private __remove_address_space var3; // var3 is __private int + } + + void bar(){ +__global int* ptr; +foo(ptr); + } + Legacy 1.x atomics with generic address space - diff --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h index 3c5e2c9739368..a9b2364e7457d 100644 --- a/clang/lib/Headers/opencl-c-base.h +++ b/clang/lib/Headers/opencl-c-base.h @@ -572,6 +572,26 @@ typedef struct { #define as_intptr_t(x) __builtin_astype((x), intptr_t) #define as_uintptr_t(x) __builtin_astype((x), uintptr_t) +// C++ for OpenCL - __remove_address_space +#if defined(__OPENCL_CPP_VERSION__) +template struct __remove_address_space { using type = _Tp; }; +template struct __remove_address_space<__generic _Tp> { + using type = _Tp; +}; +template struct __remove_address_space<__global _Tp> { + using type = _Tp; +}; +template struct __remove_address_space<__private _Tp> { + using type = _Tp; +}; +template struct __remove_address_space<__local _Tp> { + using type = _Tp; +}; +template struct __remove_address_space<__constant _Tp> { + using type = _Tp; +}; +#endif + // OpenCL v1.1 s6.9, v1.2/2.0 s6.10 - Function qualifiers #define __kernel_exec(X, typen) __kernel \ diff --git a/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp b/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp new file mode 100644 index 0..f6f0c3290aa66 --- /dev/null +++ b/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 %s -cl-std=clc++ -fdeclare-opencl-builtins -finclude-default-header + +template +struct is_same { + static const bool value = false; +}; + +template +struct is_same { + static const bool value = true; +}; + +void test_is_same() { + static_assert(is_same::value); + static_assert(!is_same::value); + static_assert(!is_same<__private int, int>::value); +} + +void test_remove_address_space() { + static_assert(is_same<__remove_address_space::type, int>::value, +"type without an address space unexpectedly modified by __remove_address_space"); + static_assert(is_same<__remove_address_space<__generic int>::type, int>::value, +"__generic address space not removed by __remove_address_space"); + static_assert(is_same<__remove_address_space<__global char>::type, char>::value, +"__global address space not removed by __remove_address_space"); + static_assert(is_same<__remove_address_space<__private ulong>::type, ulong>::value, +"__private address space not removed by __remove_address_space"); + static_assert(is_same<__remove_address_space<__local short>::type, short>::value, +"__local address space not removed by __remove_address_space"); + static_assert(is_same<__remove_address_space<__constant int3>::type, int3>::value, +"__constant address space not removed by __remove_address_space"); + static_assert(is_same<__remove_address_space::type, const volatile int>::value, +"non-address-space qualifiers inappropriately removed by __remove_address_space"); +}
[clang] b13fc73 - [OpenCL] __cpp_threadsafe_static_init is by default undefined in OpenCL mode.
Author: Justas Janickas Date: 2021-08-02T14:10:15+01:00 New Revision: b13fc7311eabca27b3baea99b7be6edef0213406 URL: https://github.com/llvm/llvm-project/commit/b13fc7311eabca27b3baea99b7be6edef0213406 DIFF: https://github.com/llvm/llvm-project/commit/b13fc7311eabca27b3baea99b7be6edef0213406.diff LOG: [OpenCL] __cpp_threadsafe_static_init is by default undefined in OpenCL mode. Definition of `__cpp_threadsafe_static_init` macro is controlled by language option Opts.ThreadsafeStatics. This patch sets language option to false by default in OpenCL mode, resulting in macro `__cpp_threadsafe_static_init` being undefined. Default value can be overridden using command line option -fthreadsafe-statics. Change is supposed to address portability because not all OpenCL vendors support thread safe implementation of static initialization. Fixes llvm.org/PR48012 Differential Revision: https://reviews.llvm.org/D107163 Added: clang/test/Driver/threadsafe-statics.clcpp Modified: clang/lib/Driver/ToolChains/Clang.cpp Removed: diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index e13302528cbd1..7042bf5fc9e2a 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6192,7 +6192,8 @@ void Clang::ConstructJob(Compilation , const JobAction , // than 19. if (!Args.hasFlag(options::OPT_fthreadsafe_statics, options::OPT_fno_threadsafe_statics, -!IsWindowsMSVC || IsMSVC2015Compatible)) +!types::isOpenCL(InputType) && +(!IsWindowsMSVC || IsMSVC2015Compatible))) CmdArgs.push_back("-fno-threadsafe-statics"); // -fno-delayed-template-parsing is default, except when targeting MSVC. diff --git a/clang/test/Driver/threadsafe-statics.clcpp b/clang/test/Driver/threadsafe-statics.clcpp new file mode 100644 index 0..3e71293e7ce7e --- /dev/null +++ b/clang/test/Driver/threadsafe-statics.clcpp @@ -0,0 +1,11 @@ +// RUN: %clang -### -c -DNO_THREADSAFE_STATICS %s 2>&1 | FileCheck --check-prefix=CHECK-NO-THREADSAFE-STATICS %s +// RUN: %clang -### -fno-threadsafe-statics -DNO_THREADSAFE_STATICS -c %s 2>&1 | FileCheck --check-prefix=CHECK-NO-THREADSAFE-STATICS %s + +// CHECK-NO-THREADSAFE-STATICS: "-cc1" +// CHECK-NO-THREADSAFE-STATICS: "-fno-threadsafe-statics" +// CHECK-NO-THREADSAFE-STATICS-NOT: "-fthreadsafe-statics" + +// RUN: %clang -### -fthreadsafe-statics -DTHREADSAFE_STATICS -c %s 2>&1 | FileCheck --check-prefix=CHECK-THREADSAFE-STATICS %s + +// CHECK-THREADSAFE-STATICS: "-cc1" +// CHECK-THREADSAFE-STATICS-NOT: "-fno-threadsafe-statics" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 9988ab3 - [clang][NFC] Typo fixes. Test commit.
Author: Justas Janickas Date: 2021-08-02T13:25:08+01:00 New Revision: 9988ab3989a2e2e9cde3cc1ab4d7a44a87dee393 URL: https://github.com/llvm/llvm-project/commit/9988ab3989a2e2e9cde3cc1ab4d7a44a87dee393 DIFF: https://github.com/llvm/llvm-project/commit/9988ab3989a2e2e9cde3cc1ab4d7a44a87dee393.diff LOG: [clang][NFC] Typo fixes. Test commit. Fixed spelling of word "whether" Added: Modified: clang/lib/Sema/SemaChecking.cpp Removed: diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 4c63781660fbe..d3736311d5662 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -16013,7 +16013,7 @@ static bool isLayoutCompatible(ASTContext , QualType T1, QualType T2) { /// /// \param MagicValue Type tag magic value. /// -/// \param isConstantEvaluated wether the evalaution should be performed in +/// \param isConstantEvaluated whether the evalaution should be performed in /// constant context. static bool FindTypeTagExpr(const Expr *TypeExpr, const ASTContext , @@ -16093,7 +16093,7 @@ static bool FindTypeTagExpr(const Expr *TypeExpr, const ASTContext , /// /// \param TypeInfo Information about the corresponding C type. /// -/// \param isConstantEvaluated wether the evalaution should be performed in +/// \param isConstantEvaluated whether the evalaution should be performed in /// constant context. /// /// \returns true if the corresponding C type was found. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits