Skip to content

Commit 0ec0f75

Browse files
author
git apple-llvm automerger
committed
Merge commit '94142d9bb08c' from llvm.org/main into next
2 parents d95adec + 94142d9 commit 0ec0f75

File tree

21 files changed

+177
-4
lines changed

21 files changed

+177
-4
lines changed

libclc/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,40 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
420420
-D${CLC_TARGET_DEFINE}
421421
# All libclc builtin libraries see CLC headers
422422
-I${CMAKE_CURRENT_SOURCE_DIR}/clc/include
423+
# Error on undefined macros
424+
-Werror=undef
423425
)
424426

425427
if( NOT "${cpu}" STREQUAL "" )
426428
list( APPEND build_flags -mcpu=${cpu} )
427429
endif()
428430

431+
# Generic address space support.
432+
# Note: when declaring builtins, we must consider that even if a target
433+
# formally/nominally supports the generic address space, in practice that
434+
# target may map it to the same target address space as another address
435+
# space (often the private one). In such cases we must be careful not to
436+
# multiply-define a builtin in a single target address space, as it would
437+
# result in a mangling clash.
438+
# For this reason we must consider the target support of the generic
439+
# address space separately from the *implementation* decision about whether
440+
# to declare certain builtins in that address space.
441+
# Note: we assume that if there is no distinct generic address space, it
442+
# maps to the private address space.
443+
set ( private_addrspace_val 0 )
444+
set ( generic_addrspace_val 0 )
445+
if( ARCH STREQUAL amdgcn OR ARCH STREQUAL r600 OR ARCH STREQUAL amdgcn-amdhsa )
446+
set ( private_addrspace_val 5 )
447+
endif()
448+
if( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64
449+
OR ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
450+
set ( generic_addrspace_val 4 )
451+
endif()
452+
list( APPEND build_flags
453+
-D__CLC_PRIVATE_ADDRSPACE_VAL=${private_addrspace_val}
454+
-D__CLC_GENERIC_ADDRSPACE_VAL=${generic_addrspace_val}
455+
)
456+
429457
set( clc_build_flags ${build_flags} -DCLC_INTERNAL )
430458

431459
add_libclc_builtin_set(

libclc/clc/include/clc/clcfunc.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,18 @@
2323
#define _CLC_DEF __attribute__((always_inline))
2424
#endif
2525

26+
#if __OPENCL_C_VERSION__ == CL_VERSION_2_0 || \
27+
(__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && \
28+
defined(__opencl_c_generic_address_space))
29+
#define _CLC_GENERIC_AS_SUPPORTED 1
30+
#if __CLC_PRIVATE_ADDRSPACE_VAL != __CLC_GENERIC_ADDRSPACE_VAL
31+
#define _CLC_DISTINCT_GENERIC_AS_SUPPORTED 1
32+
#else
33+
#define _CLC_DISTINCT_GENERIC_AS_SUPPORTED 0
34+
#endif
35+
#else
36+
#define _CLC_GENERIC_AS_SUPPORTED 0
37+
#define _CLC_DISTINCT_GENERIC_AS_SUPPORTED 0
38+
#endif
39+
2640
#endif // __CLC_CLCFUNC_H_

libclc/clc/include/clc/math/remquo_decl.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ _CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x,
1717
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x,
1818
__CLC_GENTYPE y,
1919
local __CLC_INTN *q);
20+
#if _CLC_GENERIC_AS_SUPPORTED
21+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x,
22+
__CLC_GENTYPE y,
23+
generic __CLC_INTN *q);
24+
#endif

libclc/clc/include/clc/math/unary_decl_with_int_ptr.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ _CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x,
1212
local __CLC_INTN *iptr);
1313
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x,
1414
private __CLC_INTN *iptr);
15+
#if _CLC_GENERIC_AS_SUPPORTED
16+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x,
17+
generic __CLC_INTN *iptr);
18+
#endif

libclc/clc/include/clc/math/unary_decl_with_ptr.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ _CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x,
1212
local __CLC_GENTYPE *ptr);
1313
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE
1414
__CLC_FUNCTION(__CLC_GENTYPE x, private __CLC_GENTYPE *ptr);
15+
16+
#if _CLC_GENERIC_AS_SUPPORTED
17+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE
18+
__CLC_FUNCTION(__CLC_GENTYPE x, generic __CLC_GENTYPE *ptr);
19+
#endif

libclc/clc/include/clc/math/unary_def_with_int_ptr.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE FUNCTION(__CLC_GENTYPE x,
2626
local __CLC_INTN *iptr) {
2727
return __CLC_FUNCTION(FUNCTION)(x, iptr);
2828
}
29+
30+
#if _CLC_DISTINCT_GENERIC_AS_SUPPORTED
31+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE FUNCTION(__CLC_GENTYPE x,
32+
generic __CLC_INTN *iptr) {
33+
return __CLC_FUNCTION(FUNCTION)(x, iptr);
34+
}
35+
#endif

libclc/clc/include/clc/math/unary_def_with_ptr.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE FUNCTION(__CLC_GENTYPE x,
2626
local __CLC_GENTYPE *ptr) {
2727
return __CLC_FUNCTION(FUNCTION)(x, ptr);
2828
}
29+
30+
#if _CLC_DISTINCT_GENERIC_AS_SUPPORTED
31+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE FUNCTION(__CLC_GENTYPE x,
32+
generic __CLC_GENTYPE *ptr) {
33+
return __CLC_FUNCTION(FUNCTION)(x, ptr);
34+
}
35+
#endif

libclc/clc/lib/generic/math/clc_fract.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@ _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_fract(__CLC_GENTYPE x,
3434

3535
FRACT_DEF(local);
3636
FRACT_DEF(global);
37+
#if _CLC_DISTINCT_GENERIC_AS_SUPPORTED
38+
FRACT_DEF(generic);
39+
#endif
3740

3841
#undef MIN_CONSTANT

libclc/clc/lib/generic/math/clc_frexp.cl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include <clc/clc_convert.h>
10+
#include <clc/clcfunc.h>
1011
#include <clc/internal/clc.h>
1112
#include <clc/math/math.h>
1213
#include <clc/relational/clc_isinf.h>
@@ -28,3 +29,10 @@
2829
#define __CLC_ADDRESS_SPACE local
2930
#include <clc/math/gentype.inc>
3031
#undef __CLC_ADDRESS_SPACE
32+
33+
#if _CLC_DISTINCT_GENERIC_AS_SUPPORTED
34+
#define __CLC_BODY <clc_frexp.inc>
35+
#define __CLC_ADDRESS_SPACE generic
36+
#include <clc/math/gentype.inc>
37+
#undef __CLC_ADDRESS_SPACE
38+
#endif

libclc/clc/lib/generic/math/clc_modf.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_modf(__CLC_GENTYPE x,
2323
CLC_MODF_DEF(local);
2424
CLC_MODF_DEF(global);
2525

26+
#if _CLC_DISTINCT_GENERIC_AS_SUPPORTED
27+
CLC_MODF_DEF(generic);
28+
#endif
29+
2630
#undef CLC_MODF_DEF

0 commit comments

Comments
 (0)