Skip to content

Commit f41d626

Browse files
azabaznomemfrob
authored andcommitted
[OpenCL] Add support of __opencl_c_generic_address_space feature macro
Reviewed By: Anastasia Differential Revision: https://reviews.llvm.org/D103401
1 parent 35d1d72 commit f41d626

File tree

9 files changed

+51
-4
lines changed

9 files changed

+51
-4
lines changed

clang/lib/Basic/TargetInfo.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,19 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
396396
HalfFormat = &llvm::APFloat::IEEEhalf();
397397
FloatFormat = &llvm::APFloat::IEEEsingle();
398398
LongDoubleFormat = &llvm::APFloat::IEEEquad();
399+
400+
// OpenCL C v3.0 s6.7.5 - The generic address space requires support for
401+
// OpenCL C 2.0 or OpenCL C 3.0 with the __opencl_c_generic_address_space
402+
// feature
403+
// FIXME: OpenCLGenericAddressSpace is also defined in setLangDefaults()
404+
// for OpenCL C 2.0 but with no access to target capabilities. Target
405+
// should be immutable once created and thus this language option needs
406+
// to be defined only once.
407+
if (Opts.OpenCLVersion >= 300) {
408+
const auto &OpenCLFeaturesMap = getSupportedOpenCLOpts();
409+
Opts.OpenCLGenericAddressSpace = hasFeatureEnabled(
410+
OpenCLFeaturesMap, "__opencl_c_generic_address_space");
411+
}
399412
}
400413

401414
if (Opts.DoubleSize) {

clang/lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4072,6 +4072,8 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
40724072
case tok::kw___generic:
40734073
// generic address space is introduced only in OpenCL v2.0
40744074
// see OpenCL C Spec v2.0 s6.5.5
4075+
// OpenCL v3.0 introduces __opencl_c_generic_address_space
4076+
// feature macro to indicate if generic address space is supported
40754077
if (!Actions.getLangOpts().OpenCLGenericAddressSpace) {
40764078
DiagID = diag::err_opencl_unknown_type_specifier;
40774079
PrevSpec = Tok.getIdentifierInfo()->getNameStart();

clang/test/CodeGenOpenCL/address-spaces-conversions.cl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -O0 -ffake-address-space-map -cl-std=CL2.0 -emit-llvm -o - | FileCheck %s
2+
// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -O0 -ffake-address-space-map -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space -emit-llvm -o - | FileCheck %s
23
// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -O0 -cl-std=CL2.0 -emit-llvm -o - | FileCheck --check-prefix=CHECK-NOFAKE %s
4+
// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -O0 -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space -emit-llvm -o - | FileCheck --check-prefix=CHECK-NOFAKE %s
35
// When -ffake-address-space-map is not used, all addr space mapped to 0 for x86_64.
46

57
// test that we generate address space casts everywhere we need conversions of

clang/test/CodeGenOpenCL/address-spaces-mangling.cl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
// RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map -faddress-space-map-mangling=yes -triple %itanium_abi_triple -emit-llvm -o - | FileCheck -check-prefixes="ASMANG,ASMANG20" %s
33
// RUN: %clang_cc1 %s -ffake-address-space-map -faddress-space-map-mangling=no -triple %itanium_abi_triple -emit-llvm -o - | FileCheck -check-prefixes="NOASMANG,NOASMANG10" %s
44
// RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map -faddress-space-map-mangling=no -triple %itanium_abi_triple -emit-llvm -o - | FileCheck -check-prefixes="NOASMANG,NOASMANG20" %s
5+
// RUN: %clang_cc1 %s -cl-std=CL3.0 -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space -ffake-address-space-map -faddress-space-map-mangling=no -triple %itanium_abi_triple -emit-llvm -o - | FileCheck -check-prefixes="NOASMANG,NOASMANG20" %s
6+
// RUN: %clang_cc1 %s -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space -ffake-address-space-map -faddress-space-map-mangling=yes -triple %itanium_abi_triple -emit-llvm -o - | FileCheck -check-prefixes="ASMANG,ASMANG20" %s
57

68
// We check that the address spaces are mangled the same in both version of OpenCL
79
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL2.0 -emit-llvm -o - | FileCheck -check-prefix=OCL-20 %s
810
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL1.2 -emit-llvm -o - | FileCheck -check-prefix=OCL-12 %s
11+
// 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
12+
// 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-12 %s
913

1014
// We can't name this f as private is equivalent to default
1115
// no specifier given address space so we get multiple definition
@@ -47,7 +51,7 @@ void f(constant int *arg) { }
4751
// OCL-20-DAG: @_Z1fPU3AS2i
4852
// OCL-12-DAG: @_Z1fPU3AS2i
4953

50-
#if __OPENCL_C_VERSION__ >= 200
54+
#if (__OPENCL_C_VERSION__ == 200) || defined(__opencl_c_generic_address_space)
5155
__attribute__((overloadable))
5256
void f(generic int *arg) { }
5357
// ASMANG20: @_Z1fPU3AS4i

clang/test/CodeGenOpenCL/address-spaces.cl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
// RUN: %clang_cc1 %s -O0 -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,SPIR
2+
// RUN: %clang_cc1 %s -O0 -cl-std=CL3.0 -cl-ext=-__opencl_c_generic_address_space -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,SPIR
23
// RUN: %clang_cc1 %s -O0 -DCL20 -cl-std=CL2.0 -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20SPIR
34
// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s
5+
// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s
46
// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -DCL20 -cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20AMDGCN
57
// RUN: %clang_cc1 %s -O0 -triple amdgcn-mesa-mesa3d -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s
8+
// RUN: %clang_cc1 %s -O0 -triple amdgcn-mesa-mesa3d -cl-std=CL3.0 -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s
69
// RUN: %clang_cc1 %s -O0 -triple r600-- -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s
10+
// RUN: %clang_cc1 %s -O0 -triple r600-- -emit-llvm -cl-std=CL3.0 -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s
711

812
// SPIR: %struct.S = type { i32, i32, i32* }
913
// CL20SPIR: %struct.S = type { i32, i32, i32 addrspace(4)* }

clang/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
// RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-std=CL1.2 %s -emit-llvm -o - | FileCheck %s
66
// RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-std=CL2.0 %s -emit-llvm -o - | FileCheck %s
77

8+
// RUN: %clang_cc1 -triple r600 -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
9+
// RUN: %clang_cc1 -triple amdgcn-mesa-mesa3d -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
10+
// RUN: %clang_cc1 -triple amdgcn---opencl -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
11+
// RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
12+
// RUN: %clang_cc1 -triple amdgcn-mesa-mesa3d -cl-ext=+__opencl_c_generic_address_space -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
13+
// RUN: %clang_cc1 -triple amdgcn---opencl -cl-ext=+__opencl_c_generic_address_space -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
14+
// RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-ext=+__opencl_c_generic_address_space -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
15+
// RUN: %clang_cc1 -triple r600 -cl-ext=+cl_khr_fp64,+__opencl_c_fp64 -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
16+
// RUN: %clang_cc1 -triple amdgcn-mesa-mesa3d -cl-ext=+cl_khr_fp64,+__opencl_c_fp64 -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
17+
// RUN: %clang_cc1 -triple amdgcn---opencl -cl-ext=+cl_khr_fp64,+__opencl_c_fp64 -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
18+
// RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-ext=+cl_khr_fp64,+__opencl_c_fp64 -cl-std=CL3.0 %s -emit-llvm -o - | FileCheck %s
19+
820
#ifdef __AMDGCN__
921
#define PTSIZE 8
1022
#else
@@ -58,9 +70,12 @@ void test() {
5870
check(sizeof(double) == 8);
5971
check(__alignof__(double) == 8);
6072
#endif
61-
62-
check(sizeof(void*) == (__OPENCL_C_VERSION__ >= 200 ? 8 : 4));
63-
check(__alignof__(void*) == (__OPENCL_C_VERSION__ >= 200 ? 8 : 4));
73+
check(sizeof(private void*) == 4);
74+
check(__alignof__(private void*) == 4);
75+
#if (__OPENCL_C_VERSION__ == 200) || defined(__opencl_c_generic_address_space)
76+
check(sizeof(generic void*) == 8);
77+
check(__alignof__(generic void*) == 8);
78+
#endif
6479
check(sizeof(global_ptr_t) == PTSIZE);
6580
check(__alignof__(global_ptr_t) == PTSIZE);
6681
check(sizeof(constant_ptr_t) == PTSIZE);

clang/test/CodeGenOpenCL/overload.cl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -cl-std=CL2.0 -emit-llvm -o - -triple spir-unknown-unknown %s | FileCheck %s
2+
// RUN: %clang_cc1 -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space -emit-llvm -o - -triple spir-unknown-unknown %s | FileCheck %s
23

34
typedef short short4 __attribute__((ext_vector_type(4)));
45

clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DCONSTANT -cl-std=clc++
55
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=clc++
66
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=clc++
7+
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DCONSTANT -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space
8+
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space
9+
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space
710

811
/* OpenCLC v2.0 adds a set of restrictions for conversions between pointers to
912
* different address spaces, mainly described in Sections 6.5.5 and 6.5.6.
@@ -17,6 +20,8 @@
1720
* case), and __constant, that should cover all program paths for CL address
1821
* space conversions used in initialisations, assignments, casts, comparisons
1922
* and arithmetic operations.
23+
*
24+
* OpenCLC v3.0 supports generic address if __opencl_c_generic_address_space feature is supported
2025
*/
2126

2227
#ifdef GENERIC

clang/test/SemaOpenCL/address-spaces.cl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
22
// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
3+
// RUN: %clang_cc1 %s -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space -verify -pedantic -fsyntax-only
34
// RUN: %clang_cc1 %s -cl-std=clc++ -verify -pedantic -fsyntax-only
45

56
__constant int ci = 1;

0 commit comments

Comments
 (0)