Commit Graph

818 Commits

Author SHA1 Message Date
Tue Ly 614567a7bf [libc] Automatically add -mfma flag for architectures supporting FMA.
Detect if the architecture supports FMA instructions and if
the targets depend on fma.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D123615
2022-06-03 01:21:20 -04:00
Siva Chandra Reddy 70c8d12b79 [libc] Add pthread_create and pthread_join functions.
They do not yet support all the feature/attributes in pthread_attr_t.
Future changes will add such support.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D126718
2022-06-02 01:47:24 +00:00
Siva Chandra Reddy ad89cf4e2d [libc] Keep all thread state information separate from the thread structure.
The state is now stored on the thread's stack memory. This enables
implementing pthread API like pthread_detach which takes the pthread_t
structure argument by value.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D126716
2022-06-01 17:36:58 +00:00
Guillaume Chatelet b2a9ea4420 [libc] Apply no-builtin everywhere, remove unnecessary flags
Note, this is a re-submission of D125894 with `features = ["-header_modules"]`
added to the main BUILD.bazel file.

Some functions like `stpncpy` are implemented in terms of `memset` but are not
currently using `-fno-builtin-memset`. This is somewhat hidden by the fact that
we use `-ffreestanding` globally and that `-ffreestanding` implies
`-fno-builtin` for Clang.

This patch also removes `-mllvm -combiner-global-alias-analysis` that is Clang
specific and that does not bring substantial gains on modern processors.

Also we keep `-mllvm --tail-merge-threshold=0` for aarch64 in CMakeLists.txt
but we omit it in the Bazel config. This is because Bazel consumes the source
files directly and so it can use PGO to take optimal decisions locally.

Differential Revision: https://reviews.llvm.org/D126773
2022-06-01 13:34:36 +00:00
Guillaume Chatelet 4cbfd2e7eb [libc][mem*] Address facility + test enum support
This patch is a subpart of D125768 intented to make the review easier.

The `Address` struct represents a pointer but also adds compile time knowledge
like alignment or temporal/non-temporal that helps with downstream instruction
selection.

Differential Revision: https://reviews.llvm.org/D125966
2022-06-01 09:09:43 +00:00
Guillaume Chatelet 299baac64d [libc] Add support for enum in EXPECT_EQ 2022-06-01 08:42:18 +00:00
Tue Ly 800051487f [libc] Implement FLAGS option for generating all combinations for targets.
Add FLAGS option for add_header_library, add_object_library,
add_entrypoint_object, and add_libc_unittest.

In general, a flag is a string provided for supported functions under the
multi-valued option `FLAGS`.  It should be one of the following forms:
  FLAG_NAME
  FLAG_NAME__NO
  FLAG_NAME__ONLY
A target will inherit all the flags of its upstream dependency.

When we create a target `TARGET_NAME` with a flag using (add_header_library,
add_object_library, ...), its behavior will depend on the flag form as follow:
- FLAG_NAME: The following 2 targets will be generated:
    `TARGET_NAME` that has `FLAG_NAME` in its `FLAGS` property.
    `TARGET_NAME.__NO_FLAG_NAME` that depends on `DEP.__NO_FLAG_NAME` if
       `TARGET_NAME` depends on `DEP` and `DEP` has `FLAG_NAME` in its `FLAGS`
       property.
- FLAG_NAME__ONLY: Only generate 1 target `TARGET_NAME` that has `FLAG_NAME`
    in its `FLAGS` property.
- FLAG_NAME__NO: Only generate 1 target `TARGET_NAME.__NO_FLAG_NAME` that
    depends on `DEP.__NO_FLAG_NAME` if `DEP` is in its DEPENDS list and `DEP`
    has `FLAG_NAME` in its `FLAGS` property.

To show all the targets generated, pass SHOW_INTERMEDIATE_OBJECTS=ON to cmake.
To show all the targets' dependency and flags, pass
`SHOW_INTERMEDIATE_OBJECTS=DEPS` to cmake.

To completely disable a flag FLAG_NAME expansion, set the variable
`SKIP_FLAG_EXPANSION_FLAG_NAME=TRUE`.

Reviewed By: michaelrj, sivachandra

Differential Revision: https://reviews.llvm.org/D125174
2022-06-01 00:54:07 -04:00
Michael Jones ba7e1cddda [libc] add fprintf and file_writer
This patch adds the file_writer header, which just provides a wrapper
for File->write, as well as fprintf to use it. There are no unit tests
for file_writer since it's too simple to need them, but fprintf does
have a simple test of writing to a file.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D125939
2022-05-31 13:59:19 -07:00
Siva Chandra Reddy 9b8ca3c1f1 [libc] Add global stdout and stderr objects.
They are added as entrypoint object targets. The header-gen
infrastructure has been extended to enable handling standard required
global objects. The libc-api-test has also been extended to verify the
global object declarations.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D126329
2022-05-27 05:43:49 +00:00
Siva Chandra Reddy 2a5d5078d5 [libc] Add the pthread_mutex_t type.
Simple implementations of the functions pthread_mutex_init,
pthread_mutex_destroy, pthread_mutex_lock and pthread_mutex_unlock have
have also been added. Future patches will extend these functions to add
features required by the POSIX specification.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D126235
2022-05-24 22:48:14 +00:00
Alex Brachet 8725dc5e2f [libc][docs] Use same formatting for headers in source_layout
utils looks different from the other directory names
in the docs, see
https://libc.llvm.org/source_layout.html#the-utils-directory

Differential revision: https://reviews.llvm.org/D126211
2022-05-23 21:47:22 +00:00
Guillaume Chatelet 0443bfabe7 Revert "[libc] Apply no-builtin everywhere, remove unnecessary flags"
This reverts commit 94d6dd9057.
2022-05-20 14:37:17 +00:00
Alex Brachet b1183305f8 [libc] Add strlcat
Differential Revision: https://reviews.llvm.org/D125978
2022-05-19 21:48:39 +00:00
Guillaume Chatelet 94d6dd9057 [libc] Apply no-builtin everywhere, remove unnecessary flags
Some functions like `stpncpy` are implemented in terms of `memset` but are not
currently using `-fno-builtin-memset`. This is somewhat hidden by the fact that
we use `-ffreestanding` globally and that `-ffreestanding` implies
`-fno-builtin` for Clang.

This patch also removes `-mllvm -combiner-global-alias-analysis` that is Clang
specific and that does not bring substantial gains on modern processors.

Also we keep `-mllvm --tail-merge-threshold=0` for aarch64 in CMakeLists.txt
but we omit it in the Bazel config. This is because Bazel consumes the source
files directly and so it can use PGO to take optimal decisions locally.

Differential Revision: https://reviews.llvm.org/D125894
2022-05-19 09:08:42 +00:00
Michael Jones 72f6dfb378 [libc][windows] fix strlcpy tests
Generally, size_t is an alias for unsigned long long. In the strlcpy
tests, the return value of strlcpy (a size_t) is compared to an unsigned
long. On Linux unsigned long and unsigned long long are both 64 bits,
but on windows unsigned long is 32 bits. Since the macros require
identical types for both sides, this caused a build failure on windows.
This patch changes the constants to be explicit size_t values.

Differential Revision: https://reviews.llvm.org/D125917
2022-05-18 14:11:53 -07:00
Michael Jones f8ae591fc9 [libc] fix missing semicolon in bsd_ext.td
Fix typo in previous commit

Differential Revision: https://reviews.llvm.org/D125913
2022-05-18 11:22:26 -07:00
Alex Brachet 6adbcd2b10 [libc] Add String to bsd headers 2022-05-18 18:01:02 +00:00
Alex Brachet fc2c8b2371 [libc] Add strlcpy
Differential Revision: https://reviews.llvm.org/D125806
2022-05-18 17:45:05 +00:00
Michael Jones 9f1d905f39 [libc] add snprintf
After adding sprintf, snprintf is simple. The functions are very
similar. The tests only cover the behavior of the max length since the
sprintf tests should cover the other behavior.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D125826
2022-05-17 13:32:59 -07:00
Michael Jones ff6fe39eca [libc] add sprintf
This adds the sprintf entrypoint, as well as unit tests. Currently
sprintf only supports %%, %s, and %c, but the other conversions are on
the way.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D125573
2022-05-17 11:32:20 -07:00
Michael Jones 6a22b185d6 [libc] add printf converter
This adds the main pieces of the last piece of printf, the converter.
This takes the completed format section from the parser and then
converts it to a string for the writer, which is why it was the last
piece to be written. So far it supports chars and strings, but more
pieces are coming. Additionally, it supports replacing all of the
conversion functions with user supplied versions at compile time to
allow for additional functionality.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D125327
2022-05-12 13:10:05 -07:00
Michael Jones 12aae7d9a6 [libc][docs] Add doc for libc stdio functions
This patch adds a document describing the status of the string functions
in LLVM-libc.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D123823
2022-05-12 13:02:23 -07:00
Michael Jones dd7f30464b [libc] fix uint includes and libc bazel
This patch fixes the includes for the new UInt class so that the api
test now passes, additionally it fixes the bazel files to account for
the new dependencies.

Differential Revision: https://reviews.llvm.org/D125490
2022-05-12 11:40:52 -07:00
Michael Jones 1170951c73 [libc] add uint128 implementation
Some platforms don't support proper 128 bit integers, but some
algorithms use them, such as any that use long doubles. This patch
modifies the existing UInt class to support the necessary operators.
This does not put this new class into use, that will be in followup
patches.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D124959
2022-05-12 11:16:53 -07:00
Tue Ly 6d92f4022d [libc][Obvious] Fix cmake usage of list PREPEND (unavailable pre-3.15). 2022-05-08 13:58:05 -04:00
Tue Ly 13f358376a [libc] Add LINK_LIBRARIES option to add_fp_unittest and add_libc_unittest.
This is needed to prepare for adding FLAGS option.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D125055
2022-05-08 17:33:45 +00:00
Michael Jones 945fa672c6 [libc][NFC] add index mode to printf parser
This patch is a followup to the previous patch which implemented the
main printf parsing logic as well as sequential mode. This patch adds
index mode.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D123424
2022-05-06 12:06:08 -07:00
Michael Jones 270ca878d9 [libc] Update windows entrypoint list
The entrypoint list for windows hasn't been updated in a while, this
adds all of the entrypoints that are working for windows now.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D125058
2022-05-06 11:30:50 -07:00
Michael Jones e072a123d3 [libc] add printf writer
The printf implmentation is made up of three main pieces, the parser,
the converter, and the writer. This patch adds the implementation for
the writer, as well as the function for writing to a string, along with
tests.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D124421
2022-05-03 10:15:04 -07:00
Michael Jones 5d1dbe1119 [libc] fix strtold tests on 32 bit systems
This patch fixes the string to long double tests for systems that use
long double is double, and don't support uint128.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D124803
2022-05-03 10:07:21 -07:00
Siva Chandra Reddy 9db0037bf1 [libc] Add implementations of feof, ferror and clearerr.
The corresponding _unlocked functions have also been added.

Reviewed By: lntue, michaelrj

Differential Revision: https://reviews.llvm.org/D124311
2022-04-29 23:04:35 +00:00
Dominic Chen ce6bfd102a [libc] Support 32-bit ARM platform tests
Set LONG_DOUBLE_IS_DOUBLE, add ifdefs for 128-bit integer types

Differential Revision: https://reviews.llvm.org/D124204
2022-04-28 12:00:28 -07:00
Dominic Chen 684b1f03e3 Fix [libc] Minor test signedness fixes
Add namespace specifier

Differential Revision: https://reviews.llvm.org/D124468
2022-04-26 17:14:52 -07:00
Dominic Chen de94cf5286 [libc] Minor test signedness fixes
Resolve compiler warnings about signed conversion

Differential Revision: https://reviews.llvm.org/D124468
2022-04-26 17:10:33 -07:00
Siva Chandra 3f5287125a [libc] Add stdio entrypoints to aarch64 fullbuild. 2022-04-26 00:25:12 -07:00
Siva Chandra e161d36cea [libc][Obvious] Add deps of fopencookie_test only if it is enabled. 2022-04-26 00:10:29 -07:00
Michael Jones ef6614e4a2 [libc] Fix PrintfMatcher Cmake Rule
The PrintfMatcher depends on printf which is in stdio. Stdio is
currently fullbuild only, but the matcher wasn't, causing failing builds
when fullbuild was off. This patch adds the fullbuild condition to the
PrintfMatcher cmake.

Differential Revision: https://reviews.llvm.org/D124304
2022-04-22 14:40:21 -07:00
Michael Jones ff1374785f [libc] Add Printf FormatSection Matcher
This patch changes the printf parser tests to use a more robust matcher.
This allows for better debugging of parsing issues. This does not affect
the actual printf code at all, only the tests.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D124130
2022-04-22 14:21:39 -07:00
Siva Chandra Reddy 19a6dd33ee [libc] Add the implementation of the GNU extension function fopencookie.
Reviewed By: lntue, michaelrj

Differential Revision: https://reviews.llvm.org/D124141
2022-04-22 08:02:25 +00:00
Dominic Chen e8572aca0c [libc] Use correct mnemonic for arm64_32 architecture
arm64_32 is an ILP32 platform

Differential Revision: https://reviews.llvm.org/D124134
2022-04-21 15:13:07 -07:00
Siva Chandra Reddy 22f9dca113 [libc] Add the implementation of the fflush function.
Note that the underlying flush implementation does not yet fully implement
the POSIX standard. It is complete with respect to the C standard
however. A future change will add the POSIX behavior. It should not affect
the implementation of the fflush function however as the POSIX behavior
will be added in a lower layer.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D124073
2022-04-20 19:43:39 +00:00
Siva Chandra Reddy 945e0220fd [libc] Add GNU extention functions fread_unlocked and fwrite_unlocked.
POSIX locking and unlocking functions flockfile and funlockfile have
also been added. The locking is not recursive yet. A future patch will
make the underlying lock a recursive lock.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D123986
2022-04-20 15:39:27 +00:00
Siva Chandra Reddy e6d56802f8 [libc][docs] Update the fuzzing doc to better reflect the current state.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D123923
2022-04-20 15:33:20 +00:00
Siva Chandra Reddy f8cdbeb471 [libc][docs] Remove the description of a "www" directory.
We plan to use the "docs" directory as the home for our "www" pages,
similar to how it is for the libcxx project.
2022-04-18 07:16:21 +00:00
Siva Chandra Reddy 6b4ee566e9 [libc] Add a doc describing the current status of libc runtimes build.
A section briefly mentioning the planned future enhancements has also
been included.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D123761
2022-04-18 06:48:43 +00:00
Michael Jones f14334ffa1 [libc][docs] Add doc for libc string functions
This patch adds a document describing the status of the string functions
in LLVM-libc.

Reviewed By: sivachandra, jeffbailey

Differential Revision: https://reviews.llvm.org/D123645
2022-04-14 13:03:01 -07:00
Tue Ly 5c6db1dc9b [libc] Fix nested namespace issues with multiply_add.h.
The FMA header was included inside namespaces in multiply_add.h.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D123539
2022-04-11 17:30:02 -04:00
Siva Chandra Reddy 0258f56646 [libc] Add a definition of pthread_attr_t and its getters and setters.
Not all attributes have been added to phtread_attr_t in this patch. They
will be added gradually in future patches.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D123423
2022-04-11 16:08:49 +00:00
Michael Jones 4f4752ee6f [libc][NFC] implement printf parser
This patch adds the sequential mode implementation of the printf parser,
as well as unit tests for it. In addition it adjusts the surrounding
files to accomodate changes in the design found in the implementation
process.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D123339
2022-04-08 14:21:13 -07:00
Tue Ly c5f8a0a1e9 [libc] Add support for x86-64 targets that do not have FMA instructions.
Make FMA flag checks more accurate for x86-64 targets, and refactor
polyeval to use multiply and add instead when FMA instructions are not
available.

Reviewed By: michaelrj, sivachandra

Differential Revision: https://reviews.llvm.org/D123335
2022-04-08 14:12:24 -04:00