Commit Graph

1448 Commits

Author SHA1 Message Date
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 97e441dc6c.
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 26541d4176.
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
Joseph Huber
fa34b9e032 [libc] Add startup code implementation for GPU targets
This patch introduces startup code for executing `main` on a device
compiled for the GPU. We will primarily use this to run standalone
integration tests on the GPU. The actual execution of this routine will
need to be provided by a `loader` utility to bootstrap execution on the
GPU.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D143212
2023-02-07 11:36:16 -06:00
Siva Chandra Reddy
9b4999cbea [libc] Cleanup the CMake infrastructure to add startup objects.
Instead of using a custom target to copy the startup object file to a
file with the desired name, a normal object library with a special
property is used.

Follow up patches will do more cleanup wrt how the startup objects are
used in integration tests.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D143464
2023-02-07 16:35:46 +00:00
Guillaume Chatelet
29f8e076bd [libc][NFC] Move attributes from common to macros folder 2023-02-07 13:16:53 +00:00
Guillaume Chatelet
8f3c2c5ee6 [libc][NFC] Sort dependencies 2023-02-07 13:16:53 +00:00
Guillaume Chatelet
6009049076 [libc][NFC] Use LIBC_TARGET_IS_GPU instead of defining PACKAGE_FOR_GPU 2023-02-07 13:16:52 +00:00
Guillaume Chatelet
f6d9972291 [libc][NFC] Rename compiler_feature macros 2023-02-07 11:13:43 +00:00
Guillaume Chatelet
6473009502 [libc][NFC] Move sanitizer to macros folder 2023-02-07 11:13:43 +00:00
Guillaume Chatelet
1ae4bd83ce [libc][NFC] Move compiler_features to macros folder 2023-02-07 10:40:13 +00:00