750 Commits

Author SHA1 Message Date
Freddy Ye
f3a4de395c
[X86] Support "f16c" and "avx512fp16" for __builtin_cpu_supports (#78384)
This resolves issue #65320.
This also supports clarify sapphirerapids and cooperlake for
cpu_specific/dispatch.
2024-01-18 09:22:04 +08:00
Alexandre Ganea
61b5bf85f0 [compiler-rt] On Windows, silence warning when building with latest MSVC
This fixes:
```
[3334/7449] Building C object projects\compiler-rt\lib\builtins\CMakeFiles\clang_rt.builtins-x86_64.dir\extendsfdf2.c.obj
C:\git\llvm-project\compiler-rt\lib\builtins\fp_extend_impl.inc(63): warning C4018: '<': signed/unsigned mismatch
```
2024-01-17 07:23:58 -05:00
Alexander Richardson
0266f414f6
[compiler-rt] Drop COMPILER_RT_BUILD_CRT workaround (#78331)
This variable was explicitly removed from the cache to ease transition
from existing build directories but that breaks passing
COMPILER_RT_BUILD_CRT=OFF on the command line. I was surprised to see
the CRT builds being run for my builtins-only build config (I noticed
because one of the tests was failing despite having `REQUIRES: crt`).

If I pass `-DCOMPILER_RT_BUILD_CRT=OFF` to cmake and add some prints
around the `unset` statement it shows the following:
```
-- before unset(): COMPILER_RT_BUILD_CRT=OFF
-- after unset: COMPILER_RT_BUILD_CRT=
-- after cmake_dependent_option COMPILER_RT_BUILD_CRT=ON
```

Drop this temporary workaround now that over 6 months have passed.
2024-01-16 17:11:35 -08:00
Jon Roelofs
45ccc3b968
[compiler-rt][builtins] Add a missing 'const' to the Apple __init_cpu_features_resolver 2024-01-12 13:54:20 -08:00
Vitaly Buka
d7ab65f8f5
Revert "[builtins] Generate __multc3 for z/OS" (#77881)
Reverts llvm/llvm-project#77554  because of #77880
2024-01-11 23:15:15 -08:00
Sean Perry
cc0065a7d0
[builtins] Generate __multc3 for z/OS (#77554)
https://github.com/llvm/llvm-project/pull/68132 ended up removing
__multc3 & __divtc3 from compiler-rt library builds that have
QUAD_PRECISION but not TF_MODE due to missing int128 support. I added support for QUAD_PRECISION to
use the native hex float long double representation.

---------

Co-authored-by: Alexander Richardson <mail@alexrichardson.me>
2024-01-11 20:11:12 -08:00
Dimitry Andric
0b3a89f121
[builtins] Avoid using long double in FreeBSD standalone environment (#76175)
After 05a4212cc76d a number of long double related declarations are
enabled in `int_types.h`, whenever the CPU architecture and platform
support it. However, this does not work with FreeBSD's standalone
environment, which disallows any use of floating point.

In add98b246290 this was made conditional with `CRT_HAS_FLOATING_POINT`,
so extend the block guarded by that define to include all floating point
related declarations.
2024-01-02 19:23:56 +01:00
Aiden Grossman
3ddf368524 [X86] Fix warning in cpu detection due to unsigned comparison
a15532d7647a8a4b7fd2889bd97f6f72f273c4bf landed a patch that added
support for detecting more AMD znver2 CPUs and cleaned up some of the
surrounding code, including the znver3 detection. Since one model group
is 00h-0fh, I adjusted the check to include checking if the value is
greater than zero. Since the value is unsigned, this is always true and
gcc warns on it. This patch removes the comparison with zero to get rid
of the compiler warning.
2023-12-29 17:58:53 -08:00
Dimitry Andric
953ae94149
[builtins] Fix CPU feature detection for FreeBSD on AArch64 (#76532)
[builtins] Fix CPU feature detection for FreeBSD on AArch64

This is a follow-up to #75635 which broke the build for FreeBSD on
AArch64:

```
compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/freebsd.inc:3:16: error: call to undeclared function 'elf_aux_info'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    3 |   int result = elf_aux_info(AT_HWCAP, &hwcap, sizeof hwcap);
      |                ^
```

Using `elf_aux_info()` requires including `<sys/auxv.h>` first. To
prevent redeclaration issues with `hwcap.inc` attempting to define
`HWCAP_xxx` macros before `<sys/auxv.h>` does so, include `<sys/auxv.h>`
before any of the `.inc` files on FreeBSD.
2023-12-29 11:13:40 +01:00
Brad Smith
450be89136
[compiler-rt] Remove a few workarounds for FreeBSD 9.x (#76263)
Support for FreeBSD 11.x was dropped so garbage collect a few FreeBSD
9.x workarounds and make 12.x the oldest supported releases.
2023-12-29 05:10:13 -05:00
Petr Hosek
09e6f12cba
[builtins] Fix CPU feature detection for Zircon (#76276)
This is a follow up to #75635 which broke the build on Fuchsia. We don't
support ifunc on Fuchsia so we shouldn't define __init_cpu_features. For
__init_cpu_features_resolver we have to use _zx_system_get_features as a
Zircon native solution.
2023-12-24 15:10:40 -08:00
Aiden Grossman
a15532d764
[X86] Add CPU detection for more znver2 CPUs (#74955)
This patch adds proper detection support for more znver2 CPUs.

Specifically, this adds in support for CPUs codenamed Renoir, Lucienne,
and Mendocino.

This was originally proposedfor Renoir in
https://reviews.llvm.org/D96220 and
got approved, but slipped through the cracks. However, there is still a
demand for this feature.

In addition to adding support for more znver2 CPUs, this patch also includes
some additional refactoring and comments related to cpu model
information for zen CPUs.

Fixes https://github.com/llvm/llvm-project/issues/74934.
2023-12-21 23:39:28 -08:00
Jon Roelofs
394e481a38
fixup! [builtins] Refactor cpu_model support to reduce #if nesting. NFCI
https://github.com/llvm/llvm-project/pull/75635#issuecomment-1863662913
2023-12-19 17:48:24 -07:00
Jon Roelofs
52e7b6f5c5
fixup! [builtins] Refactor cpu_model support to reduce #if nesting. NFCI
https://github.com/llvm/llvm-project/pull/75635#issuecomment-1863433937

```
/b/s/w/ir/x/w/llvm_build/./bin/clang --target=aarch64-unknown-linux-gnu --sysroot=/b/s/w/ir/x/w/cipd/linux -DHAS_ASM_LSE -DVISIBILITY_HIDDEN  --target=aarch64-unknown-linux-gnu -O2 -g -DNDEBUG -fno-lto -std=c11 -fPIC -fno-builtin -fvisibility=hidden -fomit-frame-pointer -DCOMPILER_RT_HAS_FLOAT16 -MD -MT CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o -MF CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o.d -o CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o -c /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c
In file included from /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c:43:
/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/sysauxv.inc:5:41: error: use of undeclared identifier 'HWCAP_ATOMICS'
    5 |   __aarch64_have_lse_atomics = (hwcap & HWCAP_ATOMICS) != 0;
      |                                         ^
1 error generated.
```
2023-12-19 14:20:27 -07:00
Shoaib Meenai
85d5ed81b1 [compiler-rt] Fix obvious syntax error
This is breaking Android compiler-rt builds.
2023-12-19 12:59:05 -08:00
Jon Roelofs
c88e74c26d
fixup! fixup! [builtins] Refactor cpu_model support to reduce #if nesting. NFCI 2023-12-19 11:46:40 -07:00
Jon Roelofs
a5a17e8fad
fixup! [builtins] Refactor cpu_model support to reduce #if nesting. NFCI 2023-12-19 11:39:13 -07:00
Jon Roelofs
256b214b6b
[builtins][arm64] Implement __init_cpu_features_resolver on Apple platforms (#75636)
This is a re-land of https://github.com/llvm/llvm-project/pull/73685
2023-12-19 11:20:03 -07:00
Jon Roelofs
9237cfa65b
[builtins] Refactor cpu_model support to reduce #if nesting. NFCI
Reviewers: petrhosek, DavidSpickett

Pull Request: https://github.com/llvm/llvm-project/pull/75635
2023-12-19 11:19:51 -07:00
Jon Roelofs
b72e160914
Revert "[builtins] Refactor cpu_model support to reduce #if nesting. NFCI"
This reverts commit 025d048b1cac1183c85acc9d58941b9909f6ec11.

It broke one of the sanitizer bots:

https://lab.llvm.org/buildbot/#/builders/240/builds/20666
2023-12-19 11:17:24 -07:00
Jon Roelofs
b8b40e2fb9
Revert "[builtins][arm64] Implement __init_cpu_features_resolver on Apple platforms (#75636)"
This reverts commit 17aa5201710325ac4b8ccc95bb7954fea8e14849.
2023-12-19 11:17:04 -07:00
Jon Roelofs
17aa520171
[builtins][arm64] Implement __init_cpu_features_resolver on Apple platforms (#75636)
This is a re-land of https://github.com/llvm/llvm-project/pull/73685
2023-12-19 11:11:42 -07:00
Jon Roelofs
025d048b1c
[builtins] Refactor cpu_model support to reduce #if nesting. NFCI
Reviewers: petrhosek, DavidSpickett

Pull Request: https://github.com/llvm/llvm-project/pull/75635
2023-12-19 11:09:50 -07:00
David Spickett
3a31cf8853 Revert "[builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (#73685)"
And its follow up "fixup! [builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (#73685)".

This reverts commit 5b470522cdd6af3796c05ecd7d979a74f9cb43a8 and
212a5e1b9c9221d10bc35cbbbb7123ddffef47e4.

Due to build failures on Windows:
```
C:\Users\Tcwg\llvm-worker\clang-arm64-windows-msvc-2stage\llvm\compiler-rt\lib\builtins\cpu_model.c(1571,2): error: No support for checking hwcap on this platform yet.
 1571 | #error No support for checking hwcap on this platform yet.
      |  ^
```
https://lab.llvm.org/buildbot/#/builders/120/builds/5990
2023-12-15 12:45:50 +00:00
Jon Roelofs
5b470522cd
fixup! [builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (#73685) 2023-12-14 15:13:30 -07:00
Jon Roelofs
212a5e1b9c
[builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (#73685) 2023-12-14 14:57:38 -07:00
Martin Storsjö
76b8975919
[compiler-rt] Fix linking a standalone libatomic for MinGW (#74668)
Whenever linking with -nodefaultlibs for a MinGW target, we manually
need to specify a bunch of libraries - listed in ${MINGW_LIBRARIES}; the
same is already done for sanitizers and libunwind/libcxxabi/libcxx.

Practically speaking, linking with -nodefaultlibs but manually passing
the libraries in ${MINGW_LIBRARIES} restores most of the libraries that
are linked by default, except for the potential compiler builtins and
unwind library; i.e. it has essentially the same effect as linking with
"--unwindlib=none -rtlib=none", except that -rtlib doesn't accept such a
value.

When building only compiler-rt/lib/builtins, not all of compiler-rt,
${MINGW_LIBRARIES} is unset - set it manually here for that case. This
matches what is set in
compiler-rt/cmake/config-ix.cmake, except that the builtins (libgcc or
compiler-rt builtins) is omitted; the only use within lib/buitlins is
for the standalone libatomic, which explicitly already links against the
just-built builtins.
2023-12-07 13:25:24 +02:00
joyhou-hw
0e5da2eceb
[compiler-rt] Fix the HWCAP2_EBF16 and HWCAP2_SVE_EBF16 macro value (#70905)
HWCAP2_EBF16 (1UL << 32)
HWCAP2_SVE_EBF16 (1UL << 33)
this will overflow in aarch64 ilp32 abi, and make func
__init_cpu_features_constructor() wrong.
2023-11-23 10:17:55 +08:00
Jon Roelofs
7939ce39da
[builtins] Move cfi start's after the symbol name [NFC]
... in preparation for diagnosing improperly nested .cfi regions.

See https://reviews.llvm.org/D155245
2023-11-17 14:33:20 -08:00
Alex Richardson
dc298fecb7 [builtins] Build with -Wbuiltin-declaration-mismatch if supported
GCC is able to check that the signatures of the builtins are as expected
and this shows some incorrect signatures on ld80 platforms (i.e. x86).
The *tf* functions should take 128-bit arguments but until the latest fixes
they used 80-bit long double.

Differential Revision: https://reviews.llvm.org/D153814
2023-11-13 11:06:22 -08:00
David Truby
dbb4f90252
[compiler-rt] Don't link builtins against the CRT on Windows (#70675)
compiler-rt/builtins doesn't depend on anything from the CRT but
currently links against it and embeds a `/defaultlib:msvcrt` in the
`.lib` file, forcing anyone linking against it to also link against that
specific CRT. This isn't necessary as the end user can just choose which
CRT they want to use independently.
2023-10-31 12:51:38 +00:00
Sander de Smalen
e79f0506cf [compiler-rt] Don't use 'vg' in CFI directives for SME ABI routines
This broke some builds where GNU assembler doesn't support 'vg'.
2023-10-30 08:27:10 +00:00
Alexander Shaposhnikov
d4b8572f11 [compiler-rt] Fix src_rep_t_clz and clz_in_sig_frac
This is a follow-up to 910a4bf5b.

1. __builtin_clz takes unsigned int, thus for uint16_t
src_rep_t_clz can't use it directly but should subtract 16
(leading 16 bits of the promoted argument are zero).

2. Fix (and simplify) clz_in_sig_frac.

Test plan: ninja check-compiler-rt
(extendhfsf2_test.c and extenddftf2_test.c)
2023-10-28 10:20:57 +00:00
Alex Richardson
b745ce9525 [builtins] Revert accidental change to PPC implementation in 05a4212cc76d
This commit was supposed to only change the generic implementation.
Should fix the build bot errors.
2023-10-24 17:28:49 -07:00
Alexander Richardson
05a4212cc7
[builtins] Avoid using long double in generic sources (#69754)
Use of long double can be error-prone since it could be one of 80-bit
extended precision float, IEEE 128-bit float, or IBM 128-bit float.
Instead use an explicit xf_float typedef for the remaining cases where
long double is being used in the implementation. This patch does not
touch
the PPC specializations which still use long double.
2023-10-25 01:15:47 +01:00
Rainer Orth
ad7611dafe
[builtins] Fix floattitf.c etc. compilation on Solaris/SPARC (#70058)
69660ccf2ae402b02799efed072afd8ecf5a6eb0 broke the [Solaris/sparcv9
buildbot](https://lab.llvm.org/staging/#/builders/12/builds/264):
`compiler-rt/lib/builtins/int_to_fp.h` unconditionally uses `*int128_t`
which don't exist on 32-bit SPARC.

As suggested in https://github.com/llvm/llvm-project/pull/67540, this
patch fixes this by moving the `CRT_HAS_TF_MODE` guard up which does the
necessary checks.

Tested on `sparcv9-sun-solaris2.11`.
2023-10-24 19:14:33 +02:00
Alexander Richardson
d2ce3e9621
[builtins] Support building the 128-bit float functions on ld80 platforms (#68132)
GCC provides these functions (e.g. __addtf3, etc.) in libgcc on x86_64.
Since Clang supports float128, we can also enable the existing code by
using float128 for fp_t if either __FLOAT128__ or __SIZEOF_FLOAT128__ is
defined instead of only supporting these builtins for platforms with
128-bit IEEE long doubles.
This commit defines a new tf_float typedef that matches a float with
attribute((mode(TF)) on each given architecture.

There are more tests that could be enabled for x86, but to keep the diff
smaller, I restricted test changes to ones that started failing as part
of this refactoring.

This change has been tested on x86 (natively) and
aarch64,powerpc64,riscv64 and sparc64 via qemu-user.

This supersedes https://reviews.llvm.org/D98261 and should also cover
the changes from https://github.com/llvm/llvm-project/pull/68041.
2023-10-24 17:32:01 +01:00
Kazu Hirata
d36ddaa665 [compiler-rt] Fix a warning
This patch fixes:

  compiler-rt/lib/builtins/int_to_fp_impl.inc:22:18: error: expression
  is not an integer constant expression; folding it to a constant is a
  GNU extension [-Werror,-Wgnu-folding-constant]

by using enum for constants.
2023-10-20 23:03:55 -07:00
nicole mazzuca
51835dfadb
[MSVC] fix the build (#69634)
MSVC in C mode apparently doesn't consider `const int` to be
sufficiently constant expression

This was broken in #66903.
2023-10-20 14:43:18 -07:00
Kazu Hirata
4d8ea66d74 [compiler-rt] Fix a warning
This patch fixes:

  compiler-rt/lib/builtins/cpu_model.c:590:5: error: unannotated
  fall-through between switch labels [-Werror,-Wimplicit-fallthrough]

by adding a missing "break;".
2023-10-19 00:29:10 -07:00
Freddy Ye
278e533ee9
[X86] Support -march=pantherlake,clearwaterforest (#69277) 2023-10-19 15:11:15 +08:00
Kazu Hirata
781424c872 [compiler-rt] Fix a warning
This patch fixes:

  compiler-rt/lib/builtins/int_to_fp_impl.inc:36:10: error: expression
  is not an integer constant expression; folding it to a constant is a
  GNU extension [-Werror,-Wgnu-folding-constant]
2023-10-18 12:16:41 -07:00
Alex Bradbury
69660ccf2a
[builtins] Convert more int to fp functions to use common implementation (#67540)
Builds on #66903, converting the rest of the low-hanging fruit to use
the common implementation.

See https://github.com/llvm/llvm-project/pull/67540#issuecomment-1766499179 for links to Alive2 comparisons of before/after.
2023-10-18 14:13:43 +01:00
Sander de Smalen
975ec8368f
[compiler-rt] Only build SME ABI routines for baremetal or platforms that have sys/auxv.h (#69423)
This avoids link failures on other platorms that don't (yet) have an
implementation of __aarch64_sme_accessible.
2023-10-18 10:39:43 +01:00
Alexander Shaposhnikov
d85f5a6216 [compiler-rt] Fix build of builtins on Windows
Fix Windows build after 910a4bf5b70ae14e
(the breakage was found by the buildbot
https://lab.llvm.org/buildbot/#/builders/127/builds/56796)
2023-10-16 23:49:46 +00:00
Alexander Shaposhnikov
910a4bf5b7
[compiler-rt] Implement __extendxftf2 and __trunctfxf2 for x86_64 (#66918)
This patch implements __extendxftf2 (long double -> f128) and
__trunctfxf2 (f128 -> long double) on x86_64.
This is a preparation to unblock https://reviews.llvm.org/D53608,
We intentionally do not modify compiler-rt/lib/builtins/fp_lib.h in this
PR
(in particular, to limit the scope and avoid exposing other functions on
X86_64 in this PR).
Instead, TODOs were added to use fp_lib.h once it is available.

Test plan:
1. ninja check-compiler-rt (verified on X86_64 and on Aarch64)
In particular, new tests (extendxftf2_test.c and trunctfxf2_test.c) were
added.
2. compared the results of conversions with what other compilers (gcc)
produce.
2023-10-16 16:12:33 -07:00
Alex Bradbury
6dfea561ba
[builtins] Start to refactor int to fp conversion functions to use a common implementation (#66903)
After this patch, the softfp implementations of floatdidf and floatundidf
use a common implementation (int_to_fp.h and int_to_fp_impl.inc). This
roughly follows the pattern used for a wide range of other builtins,
e.g. fp_trunc_impl.inc.

Currently there is substantial copy and paste for the various int to fp
conversion functions, with just a few constants being changed. This is a
barrier to maintainability, and it's also not attractive to copy this
approach as we introduce additional int to fp conversion functions for
bf16 and half (which we currently lack, but need - see
<https://reviews.llvm.org/D157509>).

I've opted to conservatively start by replacing just two functions,
leaving a follow-up patch to replace others that follow the same
pattern. Also, for better or worse I've left the logic in float[un]didf
largely unchanged other than using a similar approach to
fp_trunc_impl.inc to remove the constants that are tied to a specific
output floating point format.
2023-10-15 16:14:55 +01:00
Sander de Smalen
311bc6683d
[AArch64][compiler-rt] Only build SME ABI routines when compiler supports asm. (#68991)
This also adds the .variant_pcs directive to some functions from which
it was previously missing.
2023-10-14 16:35:03 +01:00
Sander de Smalen
f445be9790 Reland "[compiler-rt][aarch64] Add SME ABI support routines." (#68875)
Resolved issue with green dragon build by fixing relocations for
MachO/Darwin which doesn't compile without @page/@pageoff directives.

Also silenced a warning about constructor(90) priority being < 101,
which is reserved for the implementation. In this case, we're compiling
the implementation so we should be able to use 90.

This reverts commit 072713add4408199d4bce7b3b02cc74a4a382ee0.
2023-10-12 13:56:58 +00:00
Henrik G. Olsson
072713add4
Revert "[compiler-rt][aarch64] Add SME ABI support routines." (#68875)
This reverts commit 2b05fa8f0be7e38f4b4364ea855a3d200ded7480. It caused build errors in compiler-rt.
2023-10-12 13:11:25 +02:00