Skip to content

Commit 0ccbdce

Browse files
gbaraldiAlexisPerry
authored andcommitted
Enable building 16 bit floating point builtins in apple platforms if supported by the compiler (llvm#84192)
Currently we will not build float16/bfloat16 builtins on apple platforms, LLVM will include calls to those builtins and fail to link. I copied the test code we perform for non apple platforms because oddly we branch on it being apple for building builtins
1 parent 426d3b1 commit 0ccbdce

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ function(darwin_get_toolchain_supported_archs output_var)
100100
message(WARNING "Detecting supported architectures from 'ld -v' failed. Returning default set.")
101101
set(ARCHES "i386;x86_64;armv7;armv7s;arm64")
102102
endif()
103-
104103
set(${output_var} ${ARCHES} PARENT_SCOPE)
105104
endfunction()
106105

@@ -135,7 +134,7 @@ function(darwin_test_archs os valid_archs)
135134
endif()
136135
endif()
137136

138-
# The simple program will build for x86_64h on the simulator because it is
137+
# The simple program will build for x86_64h on the simulator because it is
139138
# compatible with x86_64 libraries (mostly), but since x86_64h isn't actually
140139
# a valid or useful architecture for the iOS simulator we should drop it.
141140
if(${os} MATCHES "^(iossim|tvossim|watchossim)$")
@@ -154,7 +153,7 @@ function(darwin_test_archs os valid_archs)
154153

155154
set(working_archs)
156155
foreach(arch ${archs})
157-
156+
158157
set(arch_linker_flags "-arch ${arch} ${os_linker_flags}")
159158
if(TEST_COMPILE_ONLY)
160159
# `-w` is used to surpress compiler warnings which `try_compile_only()` treats as an error.
@@ -269,7 +268,7 @@ function(darwin_find_excluded_builtins_list output_var)
269268
${DARWIN_EXCLUDE_DIR}/${LIB_OS}${smallest_version}-${LIB_ARCH}.txt)
270269
endif()
271270
endif()
272-
271+
273272
set(${output_var}
274273
${${LIB_ARCH}_${LIB_OS}_BUILTINS}
275274
${${LIB_OS}_${LIB_ARCH}_BASE_BUILTINS}
@@ -447,7 +446,15 @@ macro(darwin_add_builtin_libraries)
447446
OS ${os}
448447
ARCH ${arch}
449448
MIN_VERSION ${DARWIN_${os}_BUILTIN_MIN_VER})
450-
449+
check_c_source_compiles("_Float16 foo(_Float16 x) { return x; }"
450+
COMPILER_RT_HAS_${arch}_FLOAT16)
451+
append_list_if(COMPILER_RT_HAS_${arch}_FLOAT16 -DCOMPILER_RT_HAS_FLOAT16 BUILTIN_CFLAGS_${arch})
452+
check_c_source_compiles("__bf16 foo(__bf16 x) { return x; }"
453+
COMPILER_RT_HAS_${arch}_BFLOAT16)
454+
# Build BF16 files only when "__bf16" is available.
455+
if(COMPILER_RT_HAS_${arch}_BFLOAT16)
456+
list(APPEND ${arch}_SOURCES ${BF16_SOURCES})
457+
endif()
451458
darwin_filter_builtin_sources(filtered_sources
452459
${os}_${arch}
453460
EXCLUDE ${arch}_${os}_EXCLUDED_BUILTINS
@@ -548,7 +555,7 @@ macro(darwin_add_embedded_builtin_libraries)
548555
${COMPILER_RT_OUTPUT_LIBRARY_DIR}/macho_embedded)
549556
set(DARWIN_macho_embedded_LIBRARY_INSTALL_DIR
550557
${COMPILER_RT_INSTALL_LIBRARY_DIR}/macho_embedded)
551-
558+
552559
set(CFLAGS_armv7 -target thumbv7-apple-darwin-eabi)
553560
set(CFLAGS_i386 -march=pentium)
554561

0 commit comments

Comments
 (0)