Skip to content

Commit ea7539b

Browse files
authored
[libclc] Ensure CLC builtins see the generic addrspace (#18585)
Having the macros defined in either the SPIR-V headers or OpenCL headers left it easy for the generic address space macros to be undefined. What's worse is there was no warning or error that this was happening. This commit moves the definition of these macros into a common shared header that all three builtin libraries see. It also ensures the build will fail on the use of any undefined macro. This mirrors how upstream will (likely) eventually place the code, though in all likelihood it will differ slightly.
1 parent 983a865 commit ea7539b

File tree

4 files changed

+18
-32
lines changed

4 files changed

+18
-32
lines changed

libclc/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,8 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
547547
-D${CLC_TARGET_DEFINE}
548548
# All libclc builtin libraries see CLC headers
549549
-I${CMAKE_CURRENT_SOURCE_DIR}/clc/include
550+
# Error on undefined macros
551+
-Werror=undef
550552
)
551553

552554
if( NOT "${cpu}" STREQUAL "" )

libclc/clc/include/clc/clcfunc.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,20 @@
2626
#define _CLC_DEF __attribute__((always_inline))
2727
#endif
2828

29+
#if __OPENCL_C_VERSION__ == CL_VERSION_2_0 || \
30+
(__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && \
31+
defined(__opencl_c_generic_address_space))
32+
#define _CLC_GENERIC_AS_SUPPORTED 1
33+
// Note that we hard-code the assumption that a non-distinct address space means
34+
// that the target maps the generic address space to the private address space.
35+
#ifdef __CLC_DISTINCT_GENERIC_ADDRSPACE__
36+
#define _CLC_DISTINCT_GENERIC_AS_SUPPORTED 1
37+
#else
38+
#define _CLC_DISTINCT_GENERIC_AS_SUPPORTED 0
39+
#endif
40+
#else
41+
#define _CLC_GENERIC_AS_SUPPORTED 0
42+
#define _CLC_DISTINCT_GENERIC_AS_SUPPORTED 0
43+
#endif
44+
2945
#endif // __CLC_CLCFUNC_H_

libclc/generic/include/clc/clc.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,6 @@
2525

2626
#define __CLC_NO_SCHAR
2727

28-
#if __OPENCL_C_VERSION__ == CL_VERSION_2_0 || \
29-
(__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && \
30-
defined(__opencl_c_generic_address_space))
31-
#define _CLC_GENERIC_AS_SUPPORTED 1
32-
// Note that we hard-code the assumption that a non-distinct address space means
33-
// that the target maps the generic address space to the private address space.
34-
#ifdef __CLC_DISTINCT_GENERIC_ADDRSPACE__
35-
#define _CLC_DISTINCT_GENERIC_AS_SUPPORTED 1
36-
#else
37-
#define _CLC_DISTINCT_GENERIC_AS_SUPPORTED 0
38-
#endif
39-
#else
40-
#define _CLC_GENERIC_AS_SUPPORTED 0
41-
#define _CLC_DISTINCT_GENERIC_AS_SUPPORTED 0
42-
#endif
43-
4428
/* Function Attributes */
4529
#include <clc/clcfunc.h>
4630

libclc/libspirv/include/libspirv/spirv.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,6 @@
2020
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
2121
#endif
2222

23-
#if __OPENCL_C_VERSION__ == CL_VERSION_2_0 || \
24-
(__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && \
25-
defined(__opencl_c_generic_address_space))
26-
#define _CLC_GENERIC_AS_SUPPORTED 1
27-
// Note that we hard-code the assumption that a non-distinct address space means
28-
// that the target maps the generic address space to the private address space.
29-
#if __CLC_DISTINCT_GENERIC_ADDRSPACE__
30-
#define _CLC_DISTINCT_GENERIC_AS_SUPPORTED 1
31-
#else
32-
#define _CLC_DISTINCT_GENERIC_AS_SUPPORTED 0
33-
#endif
34-
#else
35-
#define _CLC_GENERIC_AS_SUPPORTED 0
36-
#define _CLC_DISTINCT_GENERIC_AS_SUPPORTED 0
37-
#endif
38-
3923
/* Function Attributes */
4024
#include <clc/clcfunc.h>
4125

0 commit comments

Comments
 (0)