2646 Commits

Author SHA1 Message Date
Joseph Huber
7a5c01dbca
[libc] Search the compiler's path for GPU utility tools (#82712)
Summary:
We need some extra tools for the GPU build. Normally we search for these
from the build itself, but in the case of a `LLVM_PROJECTS_BUILD` or
some other kind of external build, this directory will not be populated.
However, the GPU build already requires that the compiler is an
up-to-date clang, which should always have these present next to the
binary. Simply add this as a fallback search path. Generally we want it
to be the second, because it would pick up someone install and then
become stale.
2024-02-22 18:55:46 -06:00
Joseph Huber
9e84a22e69
[libc] Silence warnings when building GPU tests (#82701)
Summary:
This patch silences two warnings that may occur during the building of
GPU tests. These are not informative or helpful and just make the test
output longer.
2024-02-22 18:22:16 -06:00
Petr Hosek
5bd0c44bd0
[libc] Match the names of BSD sys/queue.h member names (#82696)
While these names are technically internal implemenetation detail,
there's an existing code which relies on these details and using
different names makes LLVM libc implementation incompatible. Since our
goal is for LLVM libc to be a drop in replacement, use the same name as
BSD sys/queue.h version.
2024-02-22 15:22:49 -08:00
Joseph Huber
47b7c91abe
[libc] Rework the GPU build to be a regular target (#81921)
Summary:
This is a massive patch because it reworks the entire build and
everything that depends on it. This is not split up because various bots
would fail otherwise. I will attempt to describe the necessary changes
here.

This patch completely reworks how the GPU build is built and targeted.
Previously, we used a standard runtimes build and handled both NVPTX and
AMDGPU in a single build via multi-targeting. This added a lot of
divergence in the build system and prevented us from doing various
things like building for the CPU / GPU at the same time, or exporting
the startup libraries or running tests without a full rebuild.

The new appraoch is to handle the GPU builds as strict cross-compiling
runtimes. The first step required
https://github.com/llvm/llvm-project/pull/81557 to allow the `LIBC`
target to build for the GPU without touching the other targets. This
means that the GPU uses all the same handling as the other builds in
`libc`.

The new expected way to build the GPU libc is with
`LLVM_LIBC_RUNTIME_TARGETS=amdgcn-amd-amdhsa;nvptx64-nvidia-cuda`.

The second step was reworking how we generated the embedded GPU library
by moving it into the library install step. Where we previously had one
`libcgpu.a` we now have `libcgpu-amdgpu.a` and `libcgpu-nvptx.a`. This
patch includes the necessary clang / OpenMP changes to make that not
break the bots when this lands.

We unfortunately still require that the NVPTX target has an `internal`
target for tests. This is because the NVPTX target needs to do LTO for
the provided version (The offloading toolchain can handle it) but cannot
use it for the native toolchain which is used for making tests.

This approach is vastly superior in every way, allowing us to treat the
GPU as a standard cross-compiling target. We can now install the GPU
utilities to do things like use the offload tests and other fun things.

Some certain utilities need to be built with 
`--target=${LLVM_HOST_TRIPLE}` as well. I think this is a fine
workaround as we
will always assume that the GPU `libc` is a cross-build with a
functioning host.

Depends on https://github.com/llvm/llvm-project/pull/81557
2024-02-22 15:29:29 -06:00
Michael Jones
5b079af169
[libc] add FXBits class (#82065)
The FXBits class is what will be used to modify fixed point numbers on a
bit level. This patch adds a basic implementation as well as basic
tests.
2024-02-22 09:52:16 -08:00
Petr Hosek
9dbedcac12
[build] Check RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES for libc also (#82561)
When checking whether we need to build libc-hdrgen, we need to check
LLVM_ENABLE_RUNTIMES and RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES, just
the former is not sufficient since libc may be enabled only for certain
targets.
2024-02-22 08:28:12 -06:00
Joseph Huber
049e142bad
[libc] Fix startup utilities failing to install in full build mode (#82522)
Summary:
Currently, doing `ninja install` will fail in fullbuild mode due to the
startup utilities not being built by default. This was hidden previously
by the fact that if tests were run, it would build the startup utilities
and thus they would be present.

This patch solves this issue by making the `libc-startup` target a
dependncy on the final library. Furthermore we simply factor out the
library install directory into the base CMake directory next to the
include directory handling. This change makes the `crt` files get
installed in `lib/x86_64-unknown-linu-gnu` instead of just `lib`.

This fixes an error I had where doing a runtimes failed to install its
libraries because the install step always errored.
2024-02-21 17:04:31 -06:00
Nick Desaulniers
646c7e5283
[libc] add more stdbit.h entrypoints to additional targets (#82440)
stdbit.h isn't complete yet, but looking to turn these on on more
targets for
earlier feedback.
2024-02-20 16:29:17 -08:00
Moshe
be8b2d1ea5
Add explicit conversion to fix arm64 builds. (#82429)
Fixes issue preventing builds on ARM-based Macs.

https://github.com/llvm/llvm-project/issues/82205.

Co-authored-by: Moshe Berman <mosheberman@users.noreply.github.com>
2024-02-20 16:52:07 -06:00
Nick Desaulniers
ed4bdb86b0
[libc][__support][bit] add count_zeros (#82076)
Will be useful for implementing C23 stdbit.h's stdc_count_zeros and
stdc_count_ones.
2024-02-20 12:38:23 -08:00
Joseph Huber
5454991c29
[libc] Cleanup of hermetic test flag handling (#82384)
Summary:
This cleans up the handling of hermetic test flags. Primarily done to
simplify the GPU rework patch.
2024-02-20 12:23:48 -06:00
Schrodinger ZHU Yifan
a73e924462
[libc] use LIBC_HAS_BUILTIN instead __has_builtin (#82377)
fix the issue that `__has_builtin` is undefined on some non-clang
targets.
2024-02-20 11:35:27 -05:00
Schrodinger ZHU Yifan
96c5b8cbd1
[libc][c23] add definitions for stdckdint.h (#82059)
See docs at
- https://gustedt.gitlabpages.inria.fr/c23-library/#stdckdint
- https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3047.pdf (Ch7.10)

Compiler header:
-
450462cbac/clang/lib/Headers/stdckdint.h
- New version of GCC
(cd503b0616/gcc/ginclude/stdckdint.h)
also provides this.
2024-02-20 11:20:15 -05:00
Schrodinger ZHU Yifan
8f7ae64ea1
[libc][cpp] add atomic_signal_fence (#82138)
Add `atomic_signal_fence`. This will be useful in
https://gustedt.gitlabpages.inria.fr/c23-library/#memset_explicit.
2024-02-20 10:59:50 -05:00
lntue
f01ed3bc88
[libc][stdfix] Add round functions for fixed point types. (#81994) 2024-02-16 12:45:26 -05:00
Guillaume Chatelet
eb97599335
[libc][NFC] Add missing constexpr (#82007)
This is a fix forward for the Fuchsia build bot
https://lab.llvm.org/buildbot/#/builders/98/builds/33515
2024-02-16 17:57:22 +01:00
Nick Desaulniers
58946ee435
[libc][docs] start documenting c23 support (#81933)
I've been diffing the c17 vs c23 latest publicly available drafts and think I
have most of the library related differences. I haven't yet annotated what we
actually support or not.

Link: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2310.pdf (C17)
Link: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf (C23)
2024-02-16 08:56:24 -08:00
Guillaume Chatelet
a80a01fc25
[reland][libc][NFC] Use user defined literals to build 128 and 256 bit constants (#81998)
- #81835
- Fix for platforms where uint64_t is not available
2024-02-16 16:40:26 +01:00
lntue
10007eef39
[libc][stdfix] Re-enable fixed point abs entry points. (#81995)
#80757 has been merged.
2024-02-16 10:27:02 -05:00
Guillaume Chatelet
2b677fa4b3
[libc][NFC] Simplify BigInt (#81992)
- Add a single `cmp` function to derive all comparison operators
 - Use the `friend` version of the member functions for symmetry
 - Add a `is_neg` function to factor sign extraction
 - Implement binary op through macro expansion
2024-02-16 15:53:55 +01:00
Michael Jones
d0c2c0ab6d
[libc] Move compile options to new cmake file (#81917)
The cmake test generator needed to be updated to support the same flags
as the source. To simplify the code, I moved it to a new file.
2024-02-15 16:07:21 -08:00
lntue
3e77871c22
[libc] Tempporarily disable fixed point entry points until #80757 is merged. (#81945) 2024-02-15 19:05:51 -05:00
lntue
2c45bda802
[libc][stdfix] Add abs functions for signed fixed point types. (#81823) 2024-02-15 18:09:40 -05:00
lntue
55e6c19015
[libc][NFC] Annotate LIBC_INLINE and constexpr to BigInt and DyadicFloat methods. (#81912) 2024-02-15 15:46:18 -05:00
lntue
82a4a41614
[libc][stdfix] Add support for fixed point types in the testing infrastructure. (#81819) 2024-02-15 14:55:20 -05:00
lntue
495c57ffed
[libc] Make add_with_carry and sub_with_borrow constexpr. (#81898) 2024-02-15 14:00:25 -05:00
Guillaume Chatelet
a1d4c69344
Revert "[reland][libc][NFC] Use user defined literals to build 128 and 256 bit constants" (#81882)
Reverts llvm/llvm-project#81835
This is breaking arm32 which does not support 64 bit types.
2024-02-15 18:31:46 +01:00
Schrodinger ZHU Yifan
6cfbf8ccce
[libc] add support for function level attributes (#79891)
See discussion at
https://discourse.llvm.org/t/rfc-support-function-attributes-in-user-interface/76624

Demo macro:
```c++
#if !defined(__LIBC_CONST_ATTR) && defined(__cplusplus) && defined(__GNUC__)
#if __has_attribute(const)
#define __LIBC_CONST_ATTR [[gnu::const]]
#endif
#endif
#if !defined(__LIBC_CONST_ATTR) && defined(__GNUC__)
#if __has_attribute(const)
#define __LIBC_CONST_ATTR __attribute__((const))
#endif
#endif
#if !defined(__LIBC_CONST_ATTR)
#define __LIBC_CONST_ATTR
#endif
```
2024-02-15 12:20:53 -05:00
Guillaume Chatelet
e6b52a2fe6
[libc][NFC] Cleanup unnecessary template parameters in BigInt (#81871) 2024-02-15 17:27:59 +01:00
Guillaume Chatelet
84165864d4
[libc][NFC] Fix missing replacement in BigInt (#81864) 2024-02-15 15:31:38 +01:00
Guillaume Chatelet
97ab3c345d
[libc][NFC] Fix missing constexpr qualifier in cpp::array (#81862) 2024-02-15 15:26:04 +01:00
Guillaume Chatelet
513e4dc1af
[reland][libc][NFC] Use user defined literals to build 128 and 256 bit constants (#81835)
This is a reland of #81746
2024-02-15 14:36:58 +01:00
lntue
95e8a7c863
[libc][stdfix] Use __FRACT_FBIT__ for fixed point support detection instead of compiler version. (#81820)
Now that `__FRACT_FBIT__` and related macros are added in
https://github.com/llvm/llvm-project/pull/81207, it is safer to use them
for fixed point support detection, so that codes that do not use fixed
point types will not fail to build when `-ffixed-point` is missing.
2024-02-15 07:26:30 -06:00
Joseph Huber
4b5c21aa07 [libc][fix] Fix new test that crashes the NVPTX backend 2024-02-14 22:39:12 -06:00
lntue
ff409d39ce
[libc][math] Add C23 ldexpf128 math function and fix DyadicFloat conversions for subnormal ranges and 80-bit floating points. (#81780) 2024-02-14 21:35:00 -05:00
lntue
271e07321b
[libc] Fix fixed point detection and add compile option. (#81788) 2024-02-14 17:12:51 -05:00
lntue
1301bc46ae
[libc] Add is_fixed_point type trait. (#81263) 2024-02-14 14:44:09 -05:00
lntue
0eedc85baa
[libc][stdfix] Add FXRep helper class for fixed point types. (#81272) 2024-02-14 14:26:55 -05:00
Nick Desaulniers
6297479ff0
[libc][stdbit] implement stdc_first_trailing_one (C23) (#81768) 2024-02-14 11:10:48 -08:00
Nick Desaulniers
16e7d6842e
[libc][stdbit] implement stdc_first_trailing_zero (C23) (#81526) 2024-02-14 10:34:28 -08:00
Guillaume Chatelet
78d401b02a
Revert "[libc][NFC] Use user defined literals to build 128 and 256 bit constants." (#81771)
Reverts llvm/llvm-project#81746
2024-02-14 18:52:56 +01:00
Guillaume Chatelet
411554a353
[libc][NFC] Use user defined literals to build 128 and 256 bit constants. (#81746) 2024-02-14 18:35:54 +01:00
Nick Desaulniers
60596716c2
[libc][stdbit] implement stdc_first_leading_one (C23) (#81502) 2024-02-14 09:16:00 -08:00
Nick Desaulniers
0f6f5bfe53
[libc][__support][bit] simplify FLZ (#81678)
`countl_zero(~x)` *is* `countl_one(x)`
2024-02-14 08:52:38 -08:00
Nick Desaulniers
4efbf524ad
[libc][__support][bit] remove compiler has builtin checks (#81679)
We only support building llvmlibc with modern compilers.
https://libc.llvm.org/compiler_support.html#minimum-supported-versions

All versions of the these compilers support these builtins; GCC does not
support the short variants.
2024-02-14 08:47:09 -08:00
Guillaume Chatelet
0323235053
[libc] Add user defined literals to initialize BigInt and __uint128_t constants (#81267)
Adds user defined literal to construct unsigned integer constants. This
is useful when constructing constants for non native C++ types like
`__uint128_t` or our custom `BigInt` type.
2024-02-14 14:08:09 +01:00
lntue
84277fe90f
[libc][stdfix] Generate stdfix.h header with fixed point precision macros according to ISO/IEC TR 18037:2008 standard, and add fixed point type support detection. (#81255)
Fixed point extension standard:
https://standards.iso.org/ittf/PubliclyAvailableStandards/c051126_ISO_IEC_TR_18037_2008.zip
2024-02-13 16:48:14 -05:00
lntue
4e005515ec
[libc] Allow BigInt class to use base word types other than uint64_t. (#81634)
This will allow DyadicFloat class to replace NormalFloat class.
2024-02-13 16:04:21 -05:00
Joseph Huber
c830c1205d [libc] Remove leftover target dependent intrinsic
Summary:
I forgot to remove these because I thought I did it already. This caused
the build to fail when actually linked.
2024-02-13 12:44:26 -06:00
Joseph Huber
63198e0682
[libc] Remove remaining GPU architecture dependent instructions (#81612)
Summary:
Recent patches have added solutions to the remaining sources of
divergence. This patch simply removes the last occures of things like
`has_builtin`, `ifdef` or builtins with feature requirements. The one
exception here is `nanosleep`, but I made changes in the
`__nvvm_reflect` pass to make usage like this actually work at O0.

Depends on https://github.com/llvm/llvm-project/pull/81331
2024-02-13 12:26:45 -06:00