553 Commits

Author SHA1 Message Date
Prashanth
d54d8d7e5a
[libc][docs] Add termios page to the status of implementations docs (#123004)
These changes ensure that the termios header is documented properly with
respect to the issue ( https://github.com/llvm/llvm-project/issues/122006 ) .
2025-01-17 08:59:49 -08:00
Prashanth
9f627cf540
[libc][docs] Add sys/time page to the status of implementations docs (#123000)
These changes ensure that the sys/time header is documented properly
with respect to the issue ( #122006 ) .
2025-01-17 08:38:03 -08:00
Roland McGrath
906cbbbd3c
[libc] Fix hdrgen output for no-argument functions (#123245)
The hdrgen output is C, not C++.
2025-01-16 19:20:53 -08:00
Prashanth
fadb0e9b52
[libc][docs] add sys/wait to documentation and include related functi… (#122598)
These changes ensure that the `sys/wait` header is documented properly
with respect to the issue (#122006 ).

**Changes:**
1. **wait.yaml**: Created a new YAML file for `sys/wait` with functions
(`wait`, `waitid`, `waitpid`) and related macros.
2. **CMakeLists.txt**: Added `sys/wait` to the documentation
directories.
3. **index.rst**: Included `sys/wait` in the documentation index.
2025-01-15 15:45:16 -08:00
Nick Desaulniers
539b15b41a
[libc][docs] stub out pthread.h support (#122497)
Link: #122006
2025-01-14 08:48:38 -08:00
Prashanth
c2771ca284
[libc][docs] Add sys/resource header's implementation status (#122563)
### Add sys/resource header's implementation status ( #122006 )

#### Changes:
1. **CMakeLists.txt**: Added `sys/resource` to the list of documentation
directories.
2. **index.rst**: Included `sys/resource` in the documentation index.
3. **resource.yaml**: Created a new YAML file for `sys/resource` with
functions and macros which manages system resources.

This PR adds documentation support for the `sys/resource` header,
including functions and macros as per the latest POSIX standards.
2025-01-14 08:44:46 -08:00
Prashanth
0afee850de
[libc][docs] Add net/if.h documentation by referring to POSIX standards (#122406)
This pull request introduces the following changes to the project with
reference to issue ( #122006 ):

1. **Documentation Update**:
- Added a new YAML file `if.yaml` under `net` to document network
interface functions and macros.
   - The `if.yaml` file includes the following functions and macros:
     - Functions:
       - `if_freenameindex`
       - `if_indextoname`
       - `if_nameindex`
       - `if_nametoindex`
     - Macros:
       - `IF_NAMESIZE`

2. **CMake Configuration Update**:
- Updated the `CMakeLists.txt` file to create the necessary directory
for the `net` headers.
- Included the `net/if` documentation in the Sphinx build configuration.

3. **Index Update**:
- Updated the `index.rst` file to include a reference to the newly added
`net/if` documentation.

**Purpose**:
- This pull request adds documentation for network interface functions
and macros, ensuring they are included in the project's documentation.
- Updates the CMake configuration to support the new documentation.

**Testing**:
- Verified that the new YAML file is correctly referenced in the
`index.rst`.
- Ensured that the documentation builds without errors and includes the
new network interface documentation.

Co-authored-by: Nick Desaulniers <ndesaulniers@google.com>
2025-01-10 09:27:40 -08:00
Prashanth
dff7ef2353
[libc][docs] Add netinet/in header documentation by referring to POSIX standards (#122411)
This pull request introduces the following changes to the project with
reference to ( #122006 ):

1. **Documentation Update**:
- Added a new YAML file `in.yaml` to document network protocol and
address macros.
   - The `in.yaml` file includes the following macros:
     - `IPPROTO_IP`
     - `IPPROTO_IPV6`
     - `IPPROTO_ICMP`
     - `IPPROTO_RAW`
     - `IPPROTO_TCP`
     - `IPPROTO_UDP`
     - `INADDR_ANY`
     - `INADDR_BROADCAST`
     - `INET_ADDRSTRLEN`
     - `IPV6_JOIN_GROUP`
     - `IPV6_LEAVE_GROUP`
     - `IPV6_MULTICAST_HOPS`
     - `IPV6_MULTICAST_IF`
     - `IPV6_MULTICAST_LOOP`
     - `IPV6_UNICAST_HOPS`
     - `IPV6_V6ONLY`
     - `IN6_IS_ADDR_UNSPECIFIED`
     - `IN6_IS_ADDR_LOOPBACK`
     - `IN6_IS_ADDR_MULTICAST`
     - `IN6_IS_ADDR_LINKLOCAL`
     - `IN6_IS_ADDR_SITELOCAL`
     - `IN6_IS_ADDR_V4MAPPED`
     - `IN6_IS_ADDR_V4COMPAT`
     - `IN6_IS_ADDR_MC_NODELOCAL`
     - `IN6_IS_ADDR_MC_LINKLOCAL`
     - `IN6_IS_ADDR_MC_SITELOCAL`
     - `IN6_IS_ADDR_MC_ORGLOCAL`
     - `IN6_IS_ADDR_MC_GLOBAL`

_I believe, all these macros are necessary and should be documented._

2. **CMake Configuration Update**:
- Updated the `CMakeLists.txt` file to create the necessary directory
for the `netinet` headers.
- Included the `netinet/in` documentation in the Sphinx build
configuration.

3. **Index Update**:
- Updated the `index.rst` file to include a reference to the newly added
`netinet/in` documentation.

**Purpose**:
- This pull request adds documentation for network protocol and address
macros in the `netinet/in` header.
- Updates the CMake configuration to support the new documentation.

**Testing**:
- Verified that the new YAML file is correctly referenced in the
`index.rst`.
- Ensured that the documentation builds without errors and includes the
new network interface documentation.

This pull request ensures that the `netinet/in` header macros are
documented and included in the project's documentation, and updates the
CMake configuration to support these changes.
2025-01-10 09:24:02 -08:00
Prashanth
20f0290af0
[docs][libc] Add AIO documentation refering POSIX and include in build (#122219)
With reference to #122006 , add a new header reference (aio.yaml) to doc
2025-01-10 09:23:42 -08:00
Roland McGrath
cdbba15c6c
[libc] Add --write-if-changed switch to hdrgen/main.py (#122037)
This avoids touching the output file when it hasn't changed.  The
cmake build integration now uses this so that touching a .yaml or
.h.def file in ways that don't affect the generated header output
won't cause unnecessary recompilations.
2025-01-08 11:00:31 -08:00
Michael Jones
ca3fd63369
[libc] clean up the hdrgen docs a bit (#121974)
Since the files have been reorganized, the readme is out of date. This
patch updates it to be more accurate.
2025-01-07 16:29:01 -08:00
Roland McGrath
6ad0dcf67f
[libc] Revamp hdrgen command line and build integration (#121522)
This adds a new main command-line entry point for hdrgen, in the
new main.py.  This new interface is used for generating a header.
The old ways of invoking yaml_to_classes.py for other purposes
are left there for now, but `--e` is renamed to `--entry-point`
for consistency with the new CLI.

The YAML schema is expanded with the `header_template` key where
the corresponding `.h.def` file's path is given relative to where
the YAML file is found.  The build integration no longer gives
the `.h.def` path on the command line.  Instead, the script now
emits a depfile that's used by the cmake rules to track that.
The output file is always explicit in the script command line
rather than sometimes being derived from a directory path.
2025-01-07 15:56:12 -08:00
Nick Desaulniers
98b3191a34
[libc][docgen] regen docgen via cmake (#119628)
Now, `ninja docs-libc-html` will re-run docgen.

Previously, we would run docgen offline, and commit the result.

Now we no longer need to do that; docgen is invoked from the
dependencies of the `docs-libc-html` target on demand. This
commit removes the dynamically generated .rst files (keeping
the static ones that haven't been converted to docgen), and
fixes up some mistakes I failed to cleanup recently since I
didn't have such automation in place to catch such bugs.
2025-01-06 08:52:08 -08:00
Roland McGrath
508929d42a
[libc] Make GpuHeaderFile a subclass (#121445)
Replace copy&paste from HeaderFile to GpuHeaderFile with
subclassing.  Only the __str__ method differs.
2025-01-01 18:16:32 -08:00
Roland McGrath
62cd050b63
[libc] Move hdrgen yaml files into include/ (#121443)
The .yaml files should live next to the corresponding .h.def
files in libc/include/, rather than next to the implementation of
the tool in libc/utils/hdrgen/.  As with the .h.def files, there
is no need for a yaml/ subdirectory under include/.  This simpler
layout is more natural for maintenance and also simplifies build
integration outside the LLVM CMake build.
2025-01-01 17:03:35 -08:00
Roland McGrath
07e13b764d
[libc] Remove unnecessary subdirectory layers in utils/hdrgen (#121363)
Two extra layers of subdirectory for a handful of single-symbol
Python source files did not improve anything, and it complicated
integration of the hdrgen Python outside the LLVM CMake build.
2024-12-30 17:28:59 -08:00
Roland McGrath
9abcca5e25
[libc] Move hdrgen into utils/ subdirectory (#121256) 2024-12-30 15:36:53 -08:00
Nick Desaulniers
d2413d4413
[libc][docs] convert stdio.h to docgen (#120334)
Add info from n3220 and POSIX.1-2024.
2024-12-18 09:05:55 -08:00
Joseph Huber
f6f4744176
[libc] Install RPC server to shared/rpc.h (#120170)
Summary:
This installs the shared header to the users installation. I couldn't
decide if this should be a standalone thing or use the existing support
in `include/` mostly because this is completely separate from hdrgen
stuff and it's C++.
2024-12-17 07:45:13 -06:00
Jinsong Ji
e85a9f5540
libc: Prefix RPC Status code to avoid conflict in windows build (#119991)
Somehow conflict with define in wingdi.h.

Fix build failures:

[ 52%] Building CXX object
projects/offload/plugins-nextgen/common/CMakeFiles/PluginCommon.dir/src/RPC.cpp.obj
In file included from
...llvm\offload\plugins-nextgen\common\src\RPC.cpp:16:
...\llvm\libc\shared\rpc.h(48,3): error: expected identifier
   48 |   ERROR = 0x1000,
      |   ^
c:\Program files (x86)\Windows
Kits\10\include\10.0.22000.0\um\wingdi.h(118,29): note: expanded from
macro 'ERROR'
  118 | #define ERROR               0
      |                             ^
...\llvm\offload\plugins-nextgen\common\src\RPC.cpp(75,17): error:
expected unqualified-id
   75 |     return rpc::ERROR;
      |                 ^
c:\Program files (x86)\Windows
Kits\10\include\10.0.22000.0\um\wingdi.h(118,29): note: expanded from
macro 'ERROR'
  118 | #define ERROR               0
      |                             ^
2 errors generated.
2024-12-15 09:35:44 -05:00
lntue
4eec286b51
[libc] Add MPFR testing infra for float128. (#119499) 2024-12-13 09:32:38 -05:00
Nick Desaulniers
88bcf7283b
[libc][docs] move docgen from json to yaml (#119744)
That way it can more easily be integrated into hdrgen.
2024-12-12 13:17:51 -08:00
Nick Desaulniers
c047a5b3f6
[libc][docgen] simplify posix links (#119595)
Usually posix functions have individual doc pages, and each header has its own
list of required macro definitions. Use a simpler key of "in-latest-posix" to
signal that the URL convention can be followed.

Add support for a "removed-in-posix-2008" key which will link to the 2004 docs
for functions like bcmp, bcopy, bzero, index, and rindex from strings.h.

I don't want to add all of these links for pthreads.h, so automating this will
make documenting these go much faster.
2024-12-12 10:49:55 -08:00
Nick Desaulniers
52db903888 [libc][docs] fix typo
Fixes: #119621
2024-12-12 09:48:59 -08:00
Nick Desaulniers
e17d2b585b
[libc][docgen] support non-top-level headers (#119621)
such as arpa/inet, sys/*
2024-12-12 09:21:04 -08:00
Nick Desaulniers
02e39a13c3
[libc][docs] split "String Functions" into string.h, strings.h, stdlib.h, and inttypes.h (#118860)
bcmp, bcopy, and bzero should be moved from libc/src/string/ to
lib/src/strings/ in order for docgen to use existing conventions to find
whether we implement a function or not.

We should add support to docgen for mentioning glibc extensions (mempcpy) or
extensions from other libcs.
2024-12-10 12:59:46 -08:00
Nick Desaulniers
429f0f1e1c
[libc][docs] add missing c99 docs (#119239)
Looks like we were missing docs for:
- float.h
- wchar.h
- wctype.h

Which AFAICT were added in ISO C99.
2024-12-09 14:02:08 -08:00
Nick Desaulniers
a4e2927ab6
[libc][docs] add c11 threads and uchar (#119250)
FWICT, these were the newly added headers for c11.
2024-12-09 12:35:44 -08:00
Nick Desaulniers
7329086d4e
[libc][docs] stub out assert, errno, and locale (#118852)
[libc][docs] stub out assert, errno, and locale

These were the remaining c89 library headers (besides string.h and
stdlib.h; I
will split strings.rst in a follow up commit).

The macro support detection in docgen doesn't quite work for some of
these
headers. Add the stubs for these headers for now, and fix up docgen
later.

See the "NIST publication":
Link: https://www.open-std.org/jtc1/sc22/wg14/www/projects.html
2024-12-05 14:20:03 -08:00
Nick Desaulniers
a9aff440d9
[libc][docs] reorganize documentation (#118836)
This commit does a few things:
* creates libc/docs/headers/ and moves all user API related headers under it.
* updates paths and docgen
* updates the top level index to put these headers under a new "Implementation
  Status" tab.
* rename some of the files to be foo.rst for foo.h (except strings, which is
  currently a mix of string.h and stdlib.h)
* update the heading of some files to be in the form foo.h.
2024-12-05 13:54:09 -08:00
Nick Desaulniers
fdb90cef75
[libc][docgen] update to POSIX.1-2024 (#118717)
The recently ratified POSIX.1-2024 is newer than POSIX.1-2017.
2024-12-05 08:23:40 -08:00
Nick Desaulniers
659834df0e
docgen refresh (#118709)
- **[libc][docgen] Use Macro for macro table name**
- **fix setjmp json, otherwise can't regen**
- **regen all docs**
2024-12-04 15:43:52 -08:00
Joseph Huber
a2fc276ed2 [libc] Remove complicated header guards on HSA include
Summary:
This is much more standard now, we already require new HSA with what we
use, so no point checking for this.
2024-12-04 16:28:13 -06:00
Nick Desaulniers
e0ae7793fc
[libc] delete hdrgen (#117220)
Thanks to the effort of @RoseZhang03 and @aaryanshukla under the
guidance of
@michaelrj-google and @amykhuang, we now have newhdrgen and no longer
have a
dependency on TableGen and thus LLVM in order to start bootstrapping a
full
build.

This PR removes:
- LIBC_HDRGEN_EXE; the in tree newhdrgen is the only hdrgen that can be
used.
- LIBC_USE_NEW_HEADER_GEN; newhdrgen is the default and only option.
- LIBC_HDRGEN_ONLY; there is no need to have a distinct build step for
old
  hdrgen.
- libc-api-test and libc-api-test-tidy build targets.
- Deletes all .td files.

It does not rename newhdrgen to just hdrgen. Will follow up with a
distinct PR
for that.

Link: #117209
Link: #117254
Fixes: #117208
2024-12-03 12:34:26 -08:00
Joseph Huber
a6ef0debb1 [libc][NFC] Rename RPC opcodes to better reflect their usage
Summary:
RPC_ is a generic prefix here, use LIBC_ to indicate that these are
opcodes used to implement the C library
2024-12-02 15:35:08 -06:00
Joseph Huber
1d810ece2b
[libc] Move libc server handlers to a shared header (#117908)
Summary:
We can simply include this header from the shared directory now and do
not need to have this level of indirection. Simply stash it with the
other libc opcode handlers.

If we were able to move the printf handlers to the shared directory then
this could just be a header as well, which would HEAVILY simplify the
mess associated with building the RPC server first in the projects
build, then copying it to the runtimes build.
2024-11-27 14:57:52 -06:00
Joseph Huber
89d8e70031
[libc] Export a pointer to the RPC client directly (#117913)
Summary:
We currently have an unnecessary level of indirection when initializing
the RPC client. This is a holdover from when the RPC client was not
trivially copyable and simply makes it more complicated. Here we use the
`asm` syntax to give the C++ variable a valid name so that we can just
copy to it directly.

Another advantage to this, is that if users want to piggy-back on the
same RPC interface they need only declare theirs as extern with the same
symbol name, or make it weak to optionally use it if LIBC isn't
avaialb.e
2024-11-27 14:57:38 -06:00
Joseph Huber
38049dc8ee
[libc] Handle differing wavefront sizes correctly in the AMDHSA loader (#117788)
Summary:
The AMDGPU backend can handle wavefront sizes of 32 and 64, with the
native hardware preferring one or the other. The user can override the
hardware with `-mwavefrontsize64` or `-mwavefrontsize32` which
previously wasn't handled. We need to know the wavefront size to know
how much memory to allocate and how to index the RPC buffer. There isn't
a good way to do this with ROCm so we just use the LLVM support for
offloading to check this from the image.
2024-11-27 10:04:00 -06:00
Joseph Huber
d7c20a6f0c [libc][NFC] Move RPC opcodes to the 'shared/' directory as well 2024-11-25 12:04:10 -06:00
Joseph Huber
b4d49fb52e
[libc] Remove RPC server API and use the header directly (#117075)
Summary:
This patch removes much of the `llvmlibc_rpc_server` interface. This
pretty much deletes all of this code and just replaces it with including
`rpc.h` directly. We still maintain the file to let `libc` handle the
opcodes, since those depend on the `printf` impelmentation.

This will need to be cleaned up more, but I don't want to put too much
into a single patch.
2024-11-25 07:13:28 -06:00
Joseph Huber
89614ceb40
[libc] Move RPC interface to libc/shared to export it (#117034)
Summary:
Previous patches have made the `rpc.h` header independent of the `libc`
internals. This allows us to include it directly rather than providing
an indirect C API. This patch only does the work to move the header. A
future patch will pull out the `rpc_server` interface and simply replace
it with a single function that handles the opcodes.
2024-11-22 15:32:25 -06:00
Joseph Huber
676a1e6643
[AMDGPU] Remove uses of deprecreated HSA executable functions (#117241)
Summary:
These functions were deprecated in ROCR 1.3 which was released quite
some time ago. The main functionality that was lost was modifying and
inspecting the code object indepedently of the executable, however we do
all of that custom through our ELF API. This should be within the
versions of other functions we use.
2024-11-22 07:16:40 -06:00
Joseph Huber
27d25d1c12
[libc] Increase RPC opcode to 32-bit and use a class byte (#116905)
Summary:
Currently, the RPC interface uses a basic opcode to communicate with the
server. This currently is 16 bits. There's no reason for this to be 16
bits, because on the GPU a 32-bit write is the same as a 16-bit write
performance wise.

Additionally, I am now making all the `libc` based opcodes qualified
with the 'c' type, mimiciing how Linux handles `ioctls` all coming from
the same driver. This will make it easier to extend the interface when
it's exported directly.
2024-11-19 21:56:10 -06:00
wldfngrs
f7bb12901e
[libc][math][c23] Add tanpif16 function (#115183)
- Implementation of `tan` for 16-bit floating point inputs scaled by pi.
i.e,. `tanpif16()`
- Implementation of Tanpi in MPFRWrapper for MPFR versions < 4.2
- Exhaustive tests for `tanpif16()`
2024-11-08 09:56:31 -05:00
lntue
88a0a318e8
[libc] Use relative inclusion for public headers. (#114324)
We are finalizing the header inclusion policy, and for our public
headers in the `libc/include` folder, they must use relative path in
`"..."` when including each other.

This PR does the cleanup making sure that all the public header
inclusions in `libc/include` folder use relative paths.

---------

Co-authored-by: Nick Desaulniers <nickdesaulniers@users.noreply.github.com>
2024-11-01 14:33:30 -04:00
lntue
296a9ba77d
[libc] Fix memory leak in MPFRWrapper cospif with MPFR pre 4.2. (#114415) 2024-10-31 11:19:54 -04:00
wldfngrs
7395ef5419
[libc][math][c23] Add cospif16 function (#113001)
Implementation of `cos` for half precision floating point inputs scaled
by pi (i.e., `cospi`), correctly rounded for all rounding modes.

---------

Co-authored-by: OverMighty <its.overmighty@gmail.com>
2024-10-29 03:39:57 -07:00
OverMighty
95c24cb9de
[libc][math][c23] Add exp10m1f16 C23 math function (#105706)
Part of #95250.
2024-10-16 16:33:13 +02:00
wldfngrs
ddc3f2dd26
[libc] Add sinpif16 function (#110994)
Half-precision floating point (16-bit) implementation of the
trigonometric function Sin for inputs scaled by pi
2024-10-15 18:40:08 -04:00
Joseph Huber
be0c67c90e
[libc] Remove dependency on cpp::function in rpc.h (#112422)
Summary:
I'm going to attempt to move the `rpc.h` header to a separate folder
that we can install and include outside of `libc`. Before doing this I'm
going to try to trim up the file so there's not as many things I need to
copy to make it work. This dependency on `cpp::functional` is a low
hanging fruit. I only did it so that I could overload the argument of
the work function so that passing the id was optional in the lambda,
that's not a *huge* deal and it makes it more explicit I suppose.
2024-10-15 12:31:06 -07:00