[builtins] Only build float16/bfloat16 code if actually supported
authorAlex Richardson <alexrichardson@google.com>
Fri, 3 Mar 2023 13:54:08 +0000 (13:54 +0000)
committerAlex Richardson <alexrichardson@google.com>
Wed, 8 Mar 2023 14:58:15 +0000 (14:58 +0000)
commit489bda6a9c0ec9d2644b7bb0c230294d38f7296e
treee3768c4afa6657e13bb6a07e8092778f86813bdf
parentb7217a8fc94d33f44ec8a2e695e75f70a6eeea1e
[builtins] Only build float16/bfloat16 code if actually supported

When building compiler-rt builtins for x86_64 they library will by default
also be built for i386. We unconditionally add the Float16 compile flags
since the check for Float16 support will be done using x86_64 compiler
flags, but i386 does not actually support it. Fix this by moving the
COMPILER_RT_HAS_FLOAT16 and COMPILER_RT_HAS_FLOAT16 checks to a
per-target-architecture check inside the loop (using
`check_c_source_compiles` and `cmake_{push,pop}_check_state`).

Many of the checks in the builtin-config-ix file should probably also be
changed to per-target-arch checks, but so far only the Float16 one has
caused issues. This is an alternative to D136044 which added a special case
for i386 FreeBSD.

Fixes: https://github.com/llvm/llvm-project/issues/57224
Differential Revision: https://reviews.llvm.org/D145237
compiler-rt/cmake/builtin-config-ix.cmake
compiler-rt/lib/builtins/CMakeLists.txt