1456 Commits

Author SHA1 Message Date
Siva Chandra Reddy
58a75c6a4b [libc] Introduce a libc internal assertion macro named LIBC_ASSERT.
Few existing call-sites have been modified to use LIBC_ASSERT.

Reviewed By: lntue, michaelrj

Differential Revision: https://reviews.llvm.org/D144161
2023-02-21 21:13:20 +00:00
Petr Hosek
1d7dad8ae0 [libc][CMake] Missing TableGen include
HdrGen CMake build uses TableGen so it should include TableGen module.

Differential Revision: https://reviews.llvm.org/D144435
2023-02-21 19:58:10 +00:00
Joseph Huber
98697f4764 [libc] Fix LIBC_GPU_ARCHITECTURES not being used
Summary:
This variable is supposed to control the architectures to build for. At
some point this was changes out for testing and never fixed.
2023-02-21 13:00:16 -06:00
Jeff Bailey
9ad0ac8eb3 [libc] Add Month enum, refactor mktime_test
Introduce Month enum.

Use designated initializers instead of comments to ensure that tm_data
is initialized correctly.  Use Month enum for initializing .tm_mon to
avoid off-by-one errors.

Co-authored-by: Raman Tenneti <rtenneti@google.com>

Reviewed By: rtenneti

Differential Revision: https://reviews.llvm.org/D144357
2023-02-21 17:24:33 +00:00
Joseph Huber
eb71ecfa10 [libc] Fix GPU include directories not being set properly
Summary:
For some reason, this variable was set after where it was used. Causing
weird behaviour with including the standard headers. Fix it.
2023-02-20 15:43:16 -06:00
Joseph Huber
4a872412d8 [libc] Fix dependencies for generating the GPU binary file
This patch adjusts the way dependencies are handled in the packaed
version of the GPU libc runtime. Previously the files were not getting
updated properly in the install when they changed.

Depends on D144214

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D144280
2023-02-20 09:37:19 -06:00
Joseph Huber
d51d2b5909 [libc] Support add_object_library for the GPU build
This patch unifies the handling of generating the GPU build targets
between the `add_entrypoint_library` and the `add_object_library`
functions. The `_build_gpu_objects` function will create two targets.
One contains a single object file with several GPU binaries embedded in
it, a so-called fatbinary. The other is a direct compile of the
supported target to be used internally only. This patch pulls out some
of the properties logic so that we can handle both more easily. This
patch also required adding an ovverride  `NO_GPU_BUILD` for cases when
we only want to build the source file as normal.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D144214
2023-02-20 09:37:18 -06:00
David Spickett
78cd158cf9 [libc][AArch64] Fix fullbuild when using G++/GCC
The libc uses some functions that GCC does not currently
implement, that come from Arm's ACLE header usually.

These are:
```
__arm_wsr64
__arm_rsr64
__arm_wsr
__arm_rsr
```

This issue was reported to us (https://github.com/llvm/llvm-project/issues/60473)
and I've then reported that back to GCC (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108642).

Even if these functions are added, clang has some non standard extensions
to them that gcc may not take. So we're looking at a fix in gcc 13 at best,
and that may not be enough for what we're doing with them.

So I've added ifdefs to use alternatives with gcc.

For handling the stack pointer, inline assembly is unfortunately the only option.
I have verified that the single mov is essentially what __arm_rsr64 generates.

For fpsr and fpcr the gcc devs suggested using
https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/AArch64-Built-in-Functions.html#AArch64-Built-in-Functions.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D143261
2023-02-20 08:40:10 +00:00
Michael Jones
f6b724f1f9 [libc] Add basic fuzz target for the printf parser
The goal is to fuzz the entirety of printf, but the plan is to do it in
pieces for simplicity. This test fuzzes just the parser, while later
tests will fuzz the converters. This also adds a mock version of the
arg_list class.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D143784
2023-02-17 11:18:40 -08:00
Michael Jones
47fb6d1c65 [libc] add mock arg list
For testing purposes we need to be able to mock out the ArgList class.
This patch adds a mock version of that class as well as a flag to enable
it.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D144145
2023-02-17 11:18:38 -08:00
Raman Tenneti
fbe210dc7a [libc] Implement htonl and htons
Per spec:
* https://pubs.opengroup.org/onlinepubs/9699919799/functions/htonl.html
* https://pubs.opengroup.org/onlinepubs/9699919799/functions/htons.html

Also adds UInt16Type and UInt32Type to spec.td

Co-authored-by: Jeff Bailey <jbailey@google.com>

Reviewed By: sivachandra, jeffbailey, rtenneti

Differential Revision: https://reviews.llvm.org/D143795
2023-02-16 10:12:18 -08:00
Alex Brachet
d9a04d1d54 [libc] Support running tests for Pigweed
Differential Revision: https://reviews.llvm.org/D144146
2023-02-16 16:39:09 +00:00
Guillaume Chatelet
b67ee5d505 [reland][libc] Separate memcpy implementations per arch
As x86_64 implementations is likely to grow up to a point where it's no more manageable to have all implementations in the same file.
2023-02-15 14:40:07 +00:00
Guillaume Chatelet
15b90805bc Revert "[libc] Separate memcpy implementations per arch"
This is patch is still breaking downstream users...
This reverts commit 97e441dc6cfae31bc56b375e43899946ec7f08a8.
2023-02-15 13:29:07 +00:00
Guillaume Chatelet
97e441dc6c [libc] Separate memcpy implementations per arch
As x86_64 implementations is likely to grow up to a point where it's no more manageable to have all implementations in the same file.
2023-02-15 13:22:01 +00:00
Guillaume Chatelet
c3228714cc [libc][NFC] Make tuning macros start with LIBC_COPT_
Rename preprocessor definitions that control tuning of llvm libc.

Differential Revision: https://reviews.llvm.org/D143913
2023-02-15 10:00:16 +00:00
Tue Ly
6c7894a8e6 [libc][doc] Move docs/math.rst to docs/math/index.rst
Move docs/math.rst to docs/math/index.rst

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D144028
2023-02-14 13:41:44 -05:00
Guillaume Chatelet
9a8d64a66a Revert "[libc] Separate memcpy implementations per arch"
Reverting as it broke downstream users.
This reverts commit 26541d4176346f8510302c74d6f3b958a4e523db.
2023-02-14 16:14:51 +00:00
Guillaume Chatelet
26541d4176 [libc] Separate memcpy implementations per arch
As x86_64 implementations is likely to grow up to a point where it's no more manageable to have all implementations in the same file.
2023-02-14 15:58:08 +00:00
Guillaume Chatelet
8981f20ae9 [libc] refactor logic around embedded memcpy 2023-02-14 15:58:08 +00:00
Guillaume Chatelet
ddfabefe1b [libc] Conform memcpy tuning macro to the new naming scheme 2023-02-14 13:44:11 +00:00
Joseph Huber
5fde2d9951 [libc] Write stub files to a new directory to avoid conflicts
Summary:
This hack with stub files is used to make the final object archive
have human-understandable names. We currently output these into the
current binary directory, which sometimes interferes with the actual
source file. Put these in their own directory to be certain they don't
conflict.
2023-02-13 16:39:59 -06:00
Joseph Huber
67d78e3c6f [libc] Add a loader utility for AMDHSA architectures for testing
This is the first attempt to get some testing support for GPUs in LLVM's
libc. We want to be able to compile for and call generic code while on
the device. This is difficult as most GPU applications also require the
support of large runtimes that may contain their own bugs (e.g. CUDA /
HIP / OpenMP / OpenCL / SYCL). The proposed solution is to provide a
"loader" utility that allows us to execute a "main" function on the GPU.

This patch implements a simple loader utility targeting the AMDHSA
runtime called `amdhsa_loader` that takes a GPU program as its first
argument. It will then attempt to load a predetermined `_start` kernel
inside that image and launch execution. The `_start` symbol is provided
by a `start` utility function that will be linked alongside the
application. Thus, this should allow us to run arbitrary code on the
user's GPU with the following steps for testing.

```
clang++ Start.cpp --target=amdgcn-amd-amdhsa -mcpu=<arch> -ffreestanding -nogpulib -nostdinc -nostdlib -c
clang++ Main.cpp --target=amdgcn-amd-amdhsa -mcpu=<arch> -nogpulib -nostdinc -nostdlib -c
clang++ Start.o Main.o --target=amdgcn-amd-amdhsa -o image
amdhsa_loader image <args, ...>
```

We determine the `-mcpu` value using the `amdgpu-arch` utility provided
either by `clang` or `rocm`. If `amdgpu-arch` isn't found or returns an
error we shouldn't run the tests as the machine does not have a valid
HSA compatible GPU. Alternatively we could make this utility in-source
to avoid the external dependency.

This patch provides a single test for this untility that simply checks
to see if we can compile an application containing a simple `main`
function and execute it.

The proposed solution in the future is to create an alternate
implementation of the LibcTest.cpp source that can be compiled and
launched using this utility. This approach should allow us to use the
same test sources as the other applications.

This is primarily a prototype, suggestions for how to better integrate
this with the existing LibC infastructure would be greatly appreciated.
The loader code should also be cleaned up somewhat. An implementation
for NVPTX will need to be written as well.

Reviewed By: sivachandra, JonChesterfield

Differential Revision: https://reviews.llvm.org/D139839
2023-02-13 13:49:01 -06:00
Guillaume Chatelet
676bca0b6f [libc][NFC] Fix typo in header guards 2023-02-13 15:22:43 +00:00
Guillaume Chatelet
30f515a910 [libc] Fix LIBC_LOOP_NOUNROLL being a noop 2023-02-13 11:15:05 +00:00
Tue Ly
4663d784dd [libc] Update macros/optimization.h build dependency for CMake and Bazel.
Update macros/optimization.h build dependency for CMake and Bazel.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D143805
2023-02-11 01:24:48 -05:00
Tue Ly
a630b8eefb [libc][Obvious] Fix static method declarations for FEnv class on macOS. 2023-02-11 01:17:57 -05:00
Tue Ly
e9e43e31d3 [libc] Fix the regex detecting architecture triplet for macOS.
Summary: See https://github.com/llvm/llvm-project/issues/60666

Reviewers:

Subscribers:
2023-02-11 01:13:43 -05:00
Tue Ly
ae2d8b4971 [libc][math] Update exceptional cases for logf, log10f, log2f, log1pf.
Properly set floating point exceptions and add more exceptional
values for non-FMA x86-64 targets.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D143699
2023-02-10 14:08:50 -05:00
Michael Jones
3a66446a9a [libc] add standalone strtoint/float fuzzers
Fuzzing the string to integer and float functions without relying on the
system libc allows for tests to be run in a wider variety of places.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D143616
2023-02-10 10:46:21 -08:00
Guillaume Chatelet
737e1cd161 [libc] Move likely/unlikely to the optimization header 2023-02-10 15:31:28 +00:00
Guillaume Chatelet
4a96893fc5 [libc] Fix exp2f and prevent misuse of likely/unlikely
Let's make sure that we only accept boolean expressions when using likely/unlikely.

Differential Revision: https://reviews.llvm.org/D143732
2023-02-10 14:01:48 +00:00
Archibald Elliott
d768bf994f [NFC][TargetParser] Replace uses of llvm/Support/Host.h
The forwarding header is left in place because of its use in
`polly/lib/External/isl/interface/extract_interface.cc`, but I have
added a GCC warning about the fact it is deprecated, because it is used
in `isl` from where it is included by Polly.
2023-02-10 09:59:46 +00:00
Siva Chandra Reddy
b67b26acc2 [libc][Obvious] Include MPFRWrapper and testutils only if tests are enabled. 2023-02-10 09:04:41 +00:00
Siva Chandra Reddy
d9283e79d8 [libc] Run libc tests unconditionally, even if there are no source changes.
Before this change, the test binaries were executed only if the deps
changed. This change makes the test binaries run unconditionally. This
is more in line with the rest of LLVM. Future patches will print test
statistics etc., much like the rest of LLVM.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D143627
2023-02-10 08:47:20 +00:00
Michael Jones
848c700b66 [libc][NFC] reorganize structs in printf
Previously the type description structs were defined in the parser. For
the fuzzing targets we'll need to use those, so I've moved them into
core_structs.h. Additionally I've renamed the function for determining
the TypeDesc from a given type. Previously it shared its name with
get_type_desc which is a related but separate function that is a part of
the parser.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D143595
2023-02-09 13:45:42 -08:00
Guillaume Chatelet
6fb61ed549 [libc] Introduce a config macro file 2023-02-09 14:00:23 +00:00
Guillaume Chatelet
406b3f2cbb [libc] Add an optimization macro header 2023-02-09 13:35:49 +00:00
Guillaume Chatelet
e2f8c55664 [libc][NFC] separate macros in several targets 2023-02-09 10:51:19 +00:00
Guillaume Chatelet
e11d911039 [libc] Add documentation for the macros folder 2023-02-09 09:34:08 +00:00
Guillaume Chatelet
a6db871e85 [libc][NFC] Move cpu_features.h to properties subfolder 2023-02-09 09:30:24 +00:00
Guillaume Chatelet
c53e15e841 [libc][NFC] Move compiler_features.h to properties subfolder 2023-02-09 09:26:38 +00:00
Guillaume Chatelet
f100ec2517 [libc][NFC] Move architectures.h to properties subfolder 2023-02-09 09:20:46 +00:00
Siva Chandra Reddy
eb8e1bf92b [libc][obvious] Fix build. 2023-02-09 06:07:44 +00:00
Renyi Chen
6cb14adbfa [libc][math] Implement scalbn, scalbnf, scalbnl.
Implement scalbn via `fptuil::ldexp` for `FLT_RADIX==2` case.
"unimplemented" otherwise.

Reviewed By: lntue, sivachandra

Differential Revision: https://reviews.llvm.org/D143116
2023-02-09 05:55:34 +00:00
Joseph Huber
22a5593b03 [libc] Don't try to use MPFR with the GPU build for now
Summary:
We don't have the infastructure to support MPFR on the GPU. We should
disable this categorically on GPU builds for now.
2023-02-08 08:51:47 -06:00
Guillaume Chatelet
9fdff5415c [libc] Fix sanitizer 2023-02-07 20:56:28 +00:00
Guillaume Chatelet
a2569a76e0 [libc][NFC] Rename macros 2023-02-07 20:43:33 +00:00
Guillaume Chatelet
e2263f1459 [libc][NFC] Move code to sanitizer.h + more consistent naming 2023-02-07 20:43:33 +00:00
Siva Chandra Reddy
af1315c28f [libc][NFC] Move UnitTest and IntegrationTest to the 'test' directory.
This part of the effort to make all test related pieces into the `test`
directory. This helps is excluding test related pieces in a straight
forward manner if LLVM_INCLUDE_TESTS is OFF. Future patches will also move
the MPFR wrapper and testutils into the 'test' directory.
2023-02-07 19:45:51 +00:00