Commit Graph

772 Commits

Author SHA1 Message Date
Dani
a7ef83f005 [AArch64][SME] Add BTI and No Exec Stack markers to sme-abi.S (#84895)
Adding BTI landing pads compiler-rt is built with -mbranch-protectoin.
Tabulators are changed to 2 spaces for consistency.
2024-03-12 12:36:05 +01:00
Daniel Thornburgh
c22828991e Revert "[builtins] Disable COMPILER_RT_CRT_USE_EH_FRAME_REGISTRY by d… (#84580)
…efault (#83201)"

This reverts commit 062cfada64. See issue
#84574.
2024-03-08 15:13:20 -08:00
Shilei Tian
8300f30a92 [SelectionDAG] Add STRICT_BF16_TO_FP and STRICT_FP_TO_BF16 (#80056)
This patch adds the support for `STRICT_BF16_TO_FP` and
`STRICT_FP_TO_BF16`.
2024-03-04 01:08:49 -05:00
Shilei Tian
2c5d01c2cf Revert "[SelectionDAG] Add STRICT_BF16_TO_FP and STRICT_FP_TO_BF16 (#80056)"
This reverts commit b0c158bd94.

The changes in `compiler-rt` broke tests.
2024-03-04 00:33:31 -05:00
Shilei Tian
b0c158bd94 [SelectionDAG] Add STRICT_BF16_TO_FP and STRICT_FP_TO_BF16 (#80056)
This patch adds the support for `STRICT_BF16_TO_FP` and
`STRICT_FP_TO_BF16`.
2024-03-04 00:01:50 -05:00
Fangrui Song
062cfada64 [builtins] Disable COMPILER_RT_CRT_USE_EH_FRAME_REGISTRY by default (#83201)
Most of GCC's Linux targets have a link spec
`%{!static|static-pie:--eh-frame-hdr}` that doesn't pass --eh-frame-hdr
for `-static` links. `-static` links are supposed to utilize
`__register_frame_info` (called by `crtbeginT.o`, not by crtbegin.o or
crtbeginS.o) as a replacement.

compiler-rt crtbegin (not used with GCC) has some ehframe code, which is
not utilized because Clang driver unconditionally passes --eh-frame-hdr
for Linux targets, even for -static. In addition, LLVM libunwind
implements `__register_frame_info` as an empty stub.

Furthermore, in a non-static link, the `__register_frame_info`
references can cause an undesired weak dynamic symbol.

For now, just disable the config by default.
2024-02-27 16:32:53 -08:00
Freddy Ye
1fe6be8794 [X86] Support APXF to enable __builtin_cpu_supports. (#80636)
For referring, APX's spec:
https://cdrdv2.intel.com/v1/dl/getContent/784266
APX's index in libgcc:
https://github.com/gcc-mirror/gcc/blob/master/gcc/common/config/i386/i386-cpuinfo.h#L267
2024-02-23 15:18:42 +08:00
Alexander Richardson
99c457dc2e Unbreak *tf builtins for hexfloat (#82208)
This re-lands cc0065a7d0 in a way that 
keeps existing targets working.

---------

Original commit message:
#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: Sean Perry <perry@ca.ibm.com>
2024-02-21 20:59:56 +00:00
Jooyung Han
ec516ff3e6 Fix __isOSVersionAtLeast for Android (#80496)
Allow pre-release APIs on pre-release devices.

The current implementation requires __ANDROID_API_FUTURE__ to use new
APIs on pre-release system. This makes it hard to maintain the codebase
because it should be switched a concrete version (e.g. __ANDROID_API_X__
on release of X).

Instead, we can just allow pre-release APIs on pre-release system
without mandating the major version of __ANDROID_API_FUTURE__.

Note that this doesn't make API guards just no-op in pre-release builds.
We can still rely on its compile-time checks and it still works as
expected with release builds. Even with pre-release builds, it's the
same as before because we would pass __ANDROID_API_FUTURE__ to make the
calls anyway.
2024-02-20 21:46:25 -08:00
Freddy Ye
72105605d1 [X86] Support more ISAs to enable __builtin_cpu_supports (#79086)
This patch will also expand supports for attribute/target, while
the priority of newly supported ISAs will be set to zero.
2024-02-04 21:21:12 +08:00
Martin Storsjö
248aeac1ad [compiler-rt] Remove duplicate MS names for chkstk symbols (#80450)
Prior to 885d7b759b, the builtins library
contained two chkstk implementations for each of i386 and x86_64, one
that was used in mingw environments, and one unused (with a symbol name
not matching anything that is used anywhere). Some of the functions
additionally had other, also unused, aliases.

After cleaning this up in 885d7b759b, the
unused symbol names were removed.

At the same time, symbol aliases were added for the names as they are
used by MSVC; the functions are functionally equivalent, but have
different names between mingw and MSVC style environments.

By adding a symbol alias (so that one object file contains two different
symbols for the same function), users can run into problems with
duplicate definitions, if they themselves define one of the symbols (for
various reasons), but need to link in the other one.

This happens for Wine, which provides their own definition of
"__chkstk", but when built in mingw mode does need compiler-rt to
provide the mingw specific symbol names; see
https://github.com/mstorsjo/llvm-mingw/issues/397.

To avoid the issue, remove the extra MS style names. They weren't
entirely usable as such for MSVC style environments anyway, as
compiler-rt builtins don't build these object files at all, when built
in MSVC mode; thus, the effort to provide them for MSVC style
environments in 885d7b759b was a
half-hearted step towards that.

If we really do want to provide those functions (as an alternative to
the ones provided by MSVC itself), we should do it in a separate object
file (even if the function implementation is the same), so that users
who have a definition of one of them but need a definition of the other,
won't have conflicts.

Additionally, if we do want to provide them for MSVC, those files
actually should be built when building the builtins in MSVC mode as well
(see compiler-rt/lib/builtins/CMakeLists.txt).

If we do that, there's a risk that an MSVC style build ends up linking
in and preferring our implementation over the one provided by MSVC,
which would be suboptimal. Our implementation always probes the
requested amount of stack, while the MSVC one checks the amount of
allocated stack and only probes as much as really is needed.

In short - this reverts the situation to what it was in the 17.x release
series (except for unused functions that have been removed).
2024-02-03 14:52:49 +01:00
Jon Roelofs
659419ac2f [builtins][FMV] Remove dead include from fmv/apple.inc. NFC 2024-02-02 13:41:21 -08:00
Peter Waller
2e2b6b53f5 [AArch64][compiler-rt] Avoid use of libc header in sme-libc-routines (#79454)
The use of `#include <stdlib.h>` introduces a libc dependency. In many
build environments such a file can be found under e.g. /usr/include, but
this does not necessarily correspond to the libc in use, which may not
be available until after the builtins have been built.

So far as I understand, it's not valid to have a dependency on libc from
builtins; there are a handful of such includes in builtins, but they are
protected by ifdefs.

Instead, use <stddef.h>, which provides `size_t` and is provided by the
compiler's resource headers and so should always be available.
2024-01-29 11:07:02 +00:00
Jon Roelofs
9b48aa203a [compiler-rt][builtins][FMV] Early exit in the Apple __init_cpu_features_resolver(). NFC 2024-01-26 09:22:20 -08:00
Tom Stellard
f6ca6ed528 Revert "compiler-rt: Fix FLOAT16 feature detection"
This reverts commit aaa93ce732.

This commit was not properly reviewed.
2024-01-24 12:38:09 -08:00
Tom Stellard
aaa93ce732 compiler-rt: Fix FLOAT16 feature detection
CMAKE_TRY_COMPILE_TARGET_TYPE defaults to EXECUTABLE, which causes
any feature detection code snippet without a main function to fail,
so we need to make sure it gets explicitly set to STATIC_LIBRARY.

Bug: https://github.com/ROCm/rocFFT/issues/439
Bug: https://github.com/ROCm/rocBLAS/issues/1350
Bug: https://bugs.gentoo.org/916069
Closes: https://github.com/llvm/llvm-project/pull/69842

Reviewed by: thesamesam, mgorny
2024-01-24 15:09:15 +00:00
Alexandros Lamprineas
179ba129f5 [AArch64][FMV] Support feature MOPS in Function Multi Versioning. (#78788)
The patch adds support for FEAT_MOPS (Memory Copy and Memory Set
instructions) in Function Multi Versioning. The bits [19:16] of the
system register ID_AA64ISAR2_EL1 indicate whether FEAT_MOPS is
implemented in AArch64 state. This information is accessible via ELF
hwcaps.
2024-01-23 15:48:12 +00:00
Dinar Temirbulatov
3112578597 [AArch64][compiler-rt] Add memcpy, memset, memmove, memchr builtins. (#77496)
Add naive implementation of memcpy, memset, memmove, memchr for SME
targets.
Co-authored-by: David Sherwood <david.sherwood@arm.com>
2024-01-23 11:26:20 +00:00
Douglas Yung
bffd80d6df Revert "[AArch64][compiler-rt] Add memcpy, memset, memmove, memchr builtins. (#77496)"
This reverts commit 3ab8d2aac7.

This change is causing issues running lit tests on many bots including:
- https://lab.llvm.org/buildbot/#/builders/197/builds/12119
- https://lab.llvm.org/buildbot/#/builders/184/builds/9792
- https://lab.llvm.org/buildbot/#/builders/93/builds/18455
- https://lab.llvm.org/buildbot/#/builders/231/builds/19858
- https://lab.llvm.org/buildbot/#/builders/121/builds/38426
- https://lab.llvm.org/buildbot/#/builders/230/builds/23990
- https://lab.llvm.org/buildbot/#/builders/57/builds/32391
- https://lab.llvm.org/buildbot/#/builders/247/builds/13502
- https://lab.llvm.org/buildbot/#/builders/275/builds/3601
- https://lab.llvm.org/buildbot/#/builders/269/builds/4211
- https://lab.llvm.org/buildbot/#/builders/18/builds/14161
- https://lab.llvm.org/buildbot/#/builders/19/builds/23893
- https://lab.llvm.org/buildbot/#/builders/37/builds/30295
- https://lab.llvm.org/buildbot/#/builders/77/builds/33979
2024-01-22 18:21:09 -08:00
Dinar Temirbulatov
3ab8d2aac7 [AArch64][compiler-rt] Add memcpy, memset, memmove, memchr builtins. (#77496)
Add naive implementation of memcpy, memset, memmove, memchr for SME
targets.
Co-authored-by: David Sherwood <david.sherwood@arm.com>
2024-01-22 23:40:53 +00:00
Jon Roelofs
c083b38007 [builtins][FMV][Apple] Use builtin atomic load/store, instead of libdispatch (#78807) 2024-01-22 09:10:16 -08:00
trevyn
d1a2f11feb [builtins] Mark int_lib.h builtins as static (#69305)
Mark the following symbols as `static` to prevent duplicate definitions:

`__builtin_ctz`
`__builtin_clz`
`__builtin_clzll`
`__builtin_sadd_overflow`

>Without these then all of these functions show up in all object files
which include int_lib.h on Windows. This'll help prevent duplicate
symbols by ensuring they're not exported.

See:

https://github.com/rust-lang/compiler-builtins/issues/167
https://reviews.llvm.org/D34599
2024-01-19 06:02:00 -08:00
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 05a4212cc7 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 add98b2462 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
a15532d764 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 025d048b1c.

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 17aa520171.
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 5b470522cd and
212a5e1b9c.

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