Commit Graph

162 Commits

Author SHA1 Message Date
Alfred Persson Forsberg
67770cbb98
[libc][NFC] Fix features.h.def file header 2023-10-19 20:00:26 +02:00
alfredfo
74b0465fe9
[libc] Add simple features.h with implementation macro (#69402)
In the future this should probably be autogenerated so it defines
library version.

See: Discussion in #libc
https://discord.com/channels/636084430946959380/636732994891284500/1163979080979460176
2023-10-19 04:08:13 +02:00
Joseph Huber
ddc30ff802
[libc] Implement the 'ungetc' function on the GPU (#69248)
Summary:
This function follows closely with the pattern of all the other
functions. That is, making a new opcode and forwarding the call to the
host. However, this also required modifying the test somewhat. It seems
that not all `libc` implementations follow the same error rules as are
tested here, and it is not explicit in the standard, so we simply
disable these EOF checks when targeting the GPU.
2023-10-17 13:02:31 -05:00
Joseph Huber
6273b6d9dc
[libc] Change RPC opcode enum definition (#67439)
Summary:
This enum previously manually specified the value. This just made it
unnecessarily difficult to add new ones without changing everything.
This patch also makes it compatible with C by removing the `:`
annotation and instead using the `LAST` method.
2023-09-26 15:24:28 -05:00
Joseph Huber
7ac8e26fc7
[libc] Implement fseek, fflush, and ftell on the GPU (#67160)
Summary:
This patch adds the necessary entrypoints to handle the `fseek`,
`fflush`, and `ftell` functions. These are all very straightfoward, we
simply make RPC calls to the associated function on the other end.
Implementing it this way allows us to more or less borrow the state of
the stream from the server as we intentionally maintain no internal
state on the GPU device. However, this does not implement the `errno`
functinality so that must be ignored.
2023-09-26 09:46:46 -05:00
Joseph Huber
791b279924
[libc] Change the puts implementation on the GPU (#67189)
Summary:
Normally, the implementation of `puts` simply writes a second newline
charcter after printing the first string. However, because the GPU does
everything in batches of the SIMT group size, this will end up with very
poor output where you get the strings printed and then 1-64 newline
characters all in a row. Optimizations like to turn `printf` calls into
`puts` so it's a good idea to make this produce the expected output.

The least invasive way I could do this was to add a new opcode. It's a
little bloated, but it avoids an unneccessary and slow send operation to
configure this.
2023-09-25 11:17:22 -05:00
Jeff Bailey
c618e13161
[libc] Pull more definitions from linux/stat.h (#67071)
For file handling, we need more definitions from
linux/stat.h, so this pulls them in. It also adjusts other definitions
to match the kernel's exactly [NFC] so that it's easy to verify that
there's been no divergence one day when it's time to use linux/stat.h
directly.

Tested:
check-libc
2023-09-21 22:34:54 -07:00
Joseph Huber
f548d19fc8
[libc] Fix and simplify the implementation of 'fread' on the GPU (#66948)
Summary:
Previously, the `fread` operation was wrong in cases when we read less
data than was requested. That is, if we tried to read N bytes while the
file was in EOF, it would still copy N bytes of garbage. This is fixed
by only copying over the sizes we got from locally opening it rather
than just using the provided size.

Additionally, this patch simplifies the interface. The output functions
have special variants for writing to stdout / stderr. This is primarily
an optimization for these common cases so we can avoid sending the
stream as an argument which has a high delay. Because for input, we
already need to start with a `send` to tell the server how much data to
read, it costs us nothing to send the file along with it so this is
redundant. Re-use the file encoding scheme from the other
implementations, the one that stores the stream type in the LSBs of the
FILE pointer.
2023-09-21 14:28:06 -05:00
Mikhail R. Gadelha
8d7ca08b9f
[libc] Update siginfo_t to match kernel definition (#66560)
This patch updates the siginfo_t struct definition to match the
definition from the kernel here:

https://github.com/torvalds/linux/blob/master/include/uapi/asm-generic/siginfo.h

In particular, there are two main changes:

1. swap position of si_code and si_errno: si_code show come after
si_errno in all systems except MIPS. Since we don't MIPS, the order is
fixed for now, but can be easily \#ifdef'd if MIPS support is
implemented in the future.

2. We add a union of structs that are filled depending on the signal
raised.

This change was required for the fork and spawn integration tests in
rv32, since they fork/clone the running process, call
wait/waitid/waitpid, and read the status, which was wrong in rv32
because wait/waitid/waitpid are implemented in rv32 using SYS_waitid.

SYS_waitid takes a pointer to a siginfo_t and fills the proper fields in
the struct. The previous siginfo_t definition was being incorrectly
filled due to not taking into account the signal raised.
2023-09-21 10:59:03 -04:00
Jeff Bailey
acfb99d9fd
[libc] Specify path for making include/ subdirs (#66589)
When doing a clean build from vscode, it makes the subdirectories in the
source tree rather than in the build folder. Elsehwere in LLVM, they
prefix the MAKE_DIRECTORY calls, so this appears to be the correct
approach.
2023-09-18 21:00:51 -07:00
Joseph Huber
a1be5d69df
[libc] Implement more input functions on the GPU (#66288)
Summary:
This patch implements the `fgets`, `getc`, `fgetc`, and `getchar`
functions on the GPU. Their implementations are straightforward enough.
One thing worth noting is that the implementation of `fgets` will be
extremely slow due to the high latency to read a single char. A faster
solution would be to make a new RPC call to call `fgets` (due to the
special rule that newline or null breaks the stream). But this is left
out because performance isn't the primary concern here.
2023-09-14 15:39:29 -05:00
Mikhail R. Gadelha
75398f28eb [libc] Make time_t 64 bits long on all platforms but arm32
This patch changes the size of time_t to be an int64_t. This still
follows the POSIX standard which only requires time_t to be an integer.

Making time_t a 64-bit integer also fixes two cases in 32 bits platforms
that use SYS_clock_nanosleep_time64 and SYS_clock_gettime64, as the name
of these calls implies, they require a 64-bit time_t. For instance, in rv32,
the 32-bit version of these syscalls is not available.

We also follow glibc here, where time_t is still a 32-bit integer in
arm32.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D159125
2023-09-13 10:49:39 -03:00
Joseph Huber
ef169f5707
[libc] Improve the implementation of the rand() function (#66131)
Summary:
This patch improves the implementation of the standard `rand()` function
by implementing it in terms of the xorshift64star pRNG as described in
https://en.wikipedia.org/wiki/Xorshift#xorshift*. This is a good,
general purpose random number generator that is sufficient for most
applications that do not require an extremely long period. This patch
also correctly initializes the seed to be `1` as described by the
standard. We also increase the `RAND_MAX` value to be `INT_MAX` as the
standard only specifies that it can be larger than 32768.
2023-09-12 16:52:20 -05:00
Mikhail R. Gadelha
9ff0a447d0 [libc] Fix setrlimit/getrlimit on 32-bit systems
libc uses SYS_prlimit64 (which takes a struct rlimit64) to implement
setrlimt and getrlimit (which take a struct rlimit). In 64-bit bits
systems this is not an issue since the members of struct rlimit64 and
struct rlimit are 64 bits long, however, in 32-bit systems the members
of struct rlimit are only 32 bits long, causing wrong values being
passed to SYS_prlimit64.

This patch changes rlim_t to be __UINT64_TYPE__ (which also changes
rlimit as a side-effect), fixing the problem of mismatching types in
the syscall.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D159104
2023-09-07 16:02:32 -03:00
Joseph Huber
07102a1194 [libc] Implement the 'abort' function on the GPU
This function implements the `abort` function on the GPU. The
implementation here closely mirros the `exit` call where we first
synchornize with the RPC server to make sure it's listening and then we
exit on the GPU.

I was unsure if this should be a simple `__builtin_assert` on the GPU. I
elected to go with an RPC approach to make this a more "true" `abort`
call. That is, it should invoke some signal handlers and exit with the
proper code according to the implemented C library on the server.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D159210
2023-08-31 08:40:15 -05:00
Joseph Huber
20f4f295da [libc] Fix 'clock()' testing on the GPU
Summary:
We should check for the GPU architectures first, since `__linux__` can
be set potentially during these compilations. Also the test needs to be
a hermetic test.
2023-08-30 16:58:11 -05:00
Joseph Huber
30307a7bb7 [libc] Implement the 'clock()' function on the GPU
This patch implements the `clock()` function on the GPU. This function
is supposed to return a timestamp that can be converted into seconds
using the `CLOCKS_PER_SEC` macro. The GPU has a fixed frequency timer
that can be used for this purpose. However, there are some
considerations.

First is that AMDGPU does not have a statically known fixed frequency. I
know internally that the gfx10xx and gfx11xx series use a 100 MHz clock
which will probably remain for the future. Gfx9xx typically uses a 25
MHz clock except for the Vega 10 GPU. The only way to know for sure is
to look it up from the runtime. For this purpose, I elected to default
it to some known values and assign these to an exteranlly visible symbol
that can be initialized if needed. If we do not have a good guess we
just return zero.

Second is that the `CLOCKS_PER_SEC` macro only gives about a microsecond
of resolution. POSIX demands that it's 1,000,000 so it's best that we
keep with this tradition as almost all targets seem to respect this. The
reason this is important is because on the GPU we will almost assuredly
be copying the host's macro value (see the wrapper header) so we should
go with the POSIX version that's most likely to be set. (We could
probably make a warning if the included header doesn't match the
expected value).

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D159118
2023-08-30 16:16:34 -05:00
Joseph Huber
6a6f3c99a2 [libc] Remove hard dependencies on linux from macros headers
Currently all of this logic expects to include and link with the headers
in the `linux/` directory. This patch adds a wrapper macro to optionally
add the appropriate dependency if it exists. This is preliminary to
adding some GPU specific versions of these files.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D159021
2023-08-29 11:38:34 -05:00
Petr Hosek
dd070394a3 [libc] Fix the libc header installation path
This results in headers being installed in the wrong location.

Differential Revision: https://reviews.llvm.org/D158895
2023-08-29 05:21:14 +00:00
Alfred Persson Forsberg
d3e045934a
Revert "[libc] Add limits.h"
limits.h currently interferes with Clang's limits.h. include_next
emits a warning because it is a GNU extension. Will re add this once
we figure out a good solution.

This reverts commits 13bbca8d69,
002cba0329, and
0fb3066873.
2023-08-17 06:21:50 +02:00
Alfred Persson Forsberg
13bbca8d69
[libc] [NFC] explain compiler macros in limits.h
Differential Revision: https://reviews.llvm.org/D158128
2023-08-17 01:23:30 +02:00
Alfred Persson Forsberg
002cba0329 [libc] limits.h: include compiler limits if not already included
The LLVM-libc build itself will override include paths and prefer it's
own limits.h over the compiler's limits.h. Because we rely on the
compiler limits.h for numerical limits in LLVM-libc it needs to be
include_next:ed if not already included. The other method to work
around this is to define all numeric macros in place.

Signed-off-by: Alfred Persson Forsberg <cat@catcream.org>

Reviewed By: thesamesam

Differential Revision: https://reviews.llvm.org/D158040
2023-08-16 02:59:21 +01:00
Alfred Persson Forsberg
1acbc21d46 [libc] Define __UTS_NAME_LENGTH for __APPLE__
Before cae84d8acf all __linux__ checks were incorrectly __unix__ checks. __unix__ being true on macOS systems therefore meant that macOS would use 65 as __UTS_NAME_LENGTH.

This commit correctly specifices __UTS_NAME_LENGTH to match XNU as 256.
https://opensource.apple.com/source/xnu/xnu-201/bsd/sys/utsname.h.auto.html

Reviewed By: thesamesam

Differential Revision: https://reviews.llvm.org/D157824
2023-08-14 01:56:32 +01:00
Alfred Persson Forsberg
0fb3066873 [libc] Add limits.h
This header contains implementation specific constants.

The compiler already provides its own limits.h with numerical limits
conforming to freestanding ISO C. But it is missing extensions like
POSIX, and does for example not include <linux/limits.h> which is
expected on a Linux system, therefore, an LLVM libc implementation of
limits.h is needed for hosted (__STDC_HOSTED__) environments.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D156961
2023-08-14 01:35:44 +01:00
Michael Jones
16d5c24226 [libc] Add v variants of printf functions
The v variants of the printf functions take their variadic arguments as
a va_list instead of as individual arguments. They are otherwise
identical to the corresponding printf variants. This patch adds them
(vprintf, vfprintf, vsprintf, and vsnprintf) as well as tests.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D157138
2023-08-04 14:50:24 -07:00
Mikhail R. Gadelha
c9783d2bda [libc] Add support to compile some syscalls on 32 bit platform
This patch adds a bunch of ifdefs to handle the 32 bit versions of
some syscalls, which often only append a 64 to the name of the syscall
(with exception of SYS_lseek -> SYS_llseek and SYS_futex ->
SYS_futex_time64)

This patch also tries to handle cases where wait4 is not available
(as in riscv32): to implement wait, wait4 and waitpid when wait4 is
not available, we check for alternative wait calls and ultimately rely
on waitid to implement them all.

In riscv32, only waitid is available, so we need it to support this
platform.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D148371
2023-08-03 10:08:01 -03:00
Joseph Huber
334bbc0d67 [libc] Add support for the 'fread' function on the GPU
This patch adds support for `fread` on the GPU via the RPC mechanism.
Here we simply pass the size of the read to the server and then copy it
back to the client via the RPC channel. This should allow us to do the
basic operations on files now. This will obviously be slow for large
sizes due ot the number of RPC calls involved, this could be optimized
further by having a special RPC call that can initiate a memcpy between
the two pointers.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D155121
2023-07-26 13:51:35 -05:00
Alfred Persson Forsberg
c1ce7c8341 [libc] pthread.h.def: add PTHREAD_MUTEX_INITIALIZER
Adds PTHREAD_MUTEX_INITIALIZER for compiler-rt's builtins/emutls.c

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D156276
2023-07-25 16:47:15 -07:00
Joseph Huber
c381a94753 [libc] Remove test RPC opcodes from the exported header
This patch does the noisy work of removing the test opcodes from the
exported interface to an interface that is only visible in `libc`. The
benefit of this is that we both test the exported RPC registration more
directly, and we do not need to give this interface to users.

I have decided to export any opcode that is not a "core" libc feature as
having its MSB set in the opcode. We can think of these as non-libc
"extensions".

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D154848
2023-07-21 15:36:36 -05:00
Joseph Huber
e537c83975 [libc] Add basic support for calling host functions from the GPU
This patch adds the `rpc_host_call` function as a GPU extension. This is
exported from the `libc` project to use the RPC interface to call a
function pointer via RPC any copying the arguments by-value. The
interface can only support a single void pointer argument much like
pthreads. The function call here is the bare-bones version of what's
required for OpenMP reverse offloading. Full support will require
interfacing with the mapping table, nowait support, etc.

I decided to test this interface in `libomptarget` as that will be the
primary consumer and it would be more difficult to make a test in `libc`
due to the testing infrastructure not really having a concept of the
"host" as it runs directly on the GPU as if it were a CPU target.

Reviewed By: jplehr

Differential Revision: https://reviews.llvm.org/D155003
2023-07-19 10:11:46 -05:00
Joseph Huber
2a65d0388c [libc] Add support for creating wrapper headers for offloading in clang
This is an alternate approach to the patches proposed in D153897 and
D153794. Rather than exporting a single header that can be included on
the GPU in all circumstances, this patch chooses to instead generate a
separate set of headers that only provides the declarations. This can
then be used by external tooling to set up what's on the GPU. This
leaves room for header hacks for offloading languages without needing to
worry about the `libc` implementation.

Currently this generates a set of headers that only contain the
declarations. These will then be installed to a new clang resource
directory called `llvm_libc_wrappers/` which will house the shim code.
We can then automaticlaly include this from `clang` when offloading to
wrap around the headers while specifying what's on the GPU.

Reviewed By: jdoerfert, JonChesterfield

Differential Revision: https://reviews.llvm.org/D154036
2023-07-07 16:02:33 -05:00
Joseph Huber
6ca6cdb23e Revert "[libc] Add support for creating wrapper headers for offloading in clang"
This reverts commit a4a26374aa.

This was causing some problems with the CPU build and CUDA buildbot.
Revert until I can figure out what those issues are and fix them. I
believe it is just some CMake.
2023-07-06 18:26:41 -05:00
Joseph Huber
a4a26374aa [libc] Add support for creating wrapper headers for offloading in clang
This is an alternate approach to the patches proposed in D153897 and
D153794. Rather than exporting a single header that can be included on
the GPU in all circumstances, this patch chooses to instead generate a
separate set of headers that only provides the declarations. This can
then be used by external tooling to set up what's on the GPU. This
leaves room for header hacks for offloading languages without needing to
worry about the `libc` implementation.

Currently this generates a set of headers that only contain the
declarations. These will then be installed to a new clang resource
directory called `llvm_libc_wrappers/` which will house the shim code.
We can then automaticlaly include this from `clang` when offloading to
wrap around the headers while specifying what's on the GPU.

Reviewed By: jdoerfert, JonChesterfield

Differential Revision: https://reviews.llvm.org/D154036
2023-07-06 18:10:49 -05:00
Joseph Huber
c850ea1498 [libc] Support fopen / fclose on the GPU
This patch adds the necessary support for the fopen and fclose functions
to work on the GPU via RPC. I added a new test that enables testing this
with the minimal features we have on the GPU. I will update it once we
have `fread` and `fwrite` to actually check the outputted strings. For
now I just relied on checking manually via the outpuot temp file.

Reviewed By: JonChesterfield, sivachandra

Differential Revision: https://reviews.llvm.org/D154519
2023-07-05 18:31:58 -05:00
Alfred Persson Forsberg
cae84d8acf [libc] Correct usage of __unix__ and __linux__
Reviewed By: michaelrj, thesamesam

Differential Revision: https://reviews.llvm.org/D153729
2023-07-03 01:08:15 +01:00
Petr Hosek
f3b64887de [libc] Place headers in the right include directory
When LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is enabled, place headers
in `include/<target>` directory, otherwise use `include/`.

Differential Revision: https://reviews.llvm.org/D152592
2023-06-22 06:22:32 +00:00
Joseph Huber
dcdfc963d7 [libc] Export GPU extensions to libc for external use
The GPU port of the LLVM C library needs to export a few extensions to
the interface such that users can interface with it. This patch adds the
necessary logic to define a GPU extension. Currently, this only exports
a `rpc_reset_client` function. This allows us to use the server in
D147054 to set up the RPC interface outside of `libc`.

Depends on https://reviews.llvm.org/D147054

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D152283
2023-06-15 11:02:24 -05:00
Tue Ly
055be3c30c [libc] Enable hermetic floating point tests again.
Fixing an issue with LLVM libc's fenv.h defined rounding mode macros
differently from system libc, making get_round() return different values from
fegetround().  Also letting math tests to skip rounding modes that cannot be
set.  This should allow math tests to be run on platforms in which fenv.h is not
implemented yet.

This allows us to re-enable hermatic floating point tests in
https://reviews.llvm.org/D151123 and reverting https://reviews.llvm.org/D152742.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D152873
2023-06-14 10:53:35 -04:00
Michael Jones
d3074f16a6 [libc] Add qsort_r
This patch adds the reentrent qsort entrypoint, qsort_r. This is done by
extending the qsort functionality and moving it to a shared utility
header. For this reason the qsort_r tests focus mostly on the places
where it differs from qsort, since they share the same sorting code.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D152467
2023-06-12 11:12:17 -07:00
Siva Chandra Reddy
4f1fe19df3 [libc] Make ErrnoSetterMatcher handle logging floating point values.
Along the way, couple of additional things have been done:

1. Move `ErrnoSetterMatcher.h` to `test/UnitTest` as all other matchers live
   there now.
2. `ErrnoSetterMatcher` ignores matching `errno` on GPUs.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D151129
2023-05-26 06:24:51 +00:00
Mikhail R. Gadelha
4c9c1a4e4f [libc] Enable linux directory entries syscalls in riscv64
This patch updates the struct dirent to be on par with glibc (by adding
a missing d_type member) and update the readdir call to use SYS_getdents64
instead of SYS_getdents.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D147738
2023-05-04 19:07:16 -03:00
Michael Jones
ee17fd7d46 [libc] add socket function
This patch adds the function "socket" from the header "sys/socket". It's
a simple syscall wrapper, and I plan on adding the related functions in
a followup patch.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D149622
2023-05-03 11:01:11 -07:00
Joseph Huber
72bfe2c05a [libc] Support the string conversion methods on the GPU
This patch enables us to use the existing `libc` support for string
conversion functions on the GPU. This required setting the `fenv_t` and
long double configuration. As far as I am aware, long doubles are
converted to doubles on the GPU and the floating point environment is
just an `uint32_t`.

This code is still untested as we are still working out how to run the
unit tests on the GPU.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D149306
2023-04-27 20:31:58 -05:00
Joseph Huber
d9f033146b [libc] Ignore 'errno' on the GPU and support 'atoi'
The 'errno' value is most likely not useful on the GPU and it prevents
us from providing certain functions on the GPU that depend on it, like
`atoi`. This patch makes the necessary changes to support `errno` by
simple replacing it with a consumer class.

Supporting `errno` on the GPU is possible in some aspects. The first
approach would be to use a buffer of shared memory that has enough space
for all threads. Another option would be to change code generation to
support `thread_local` using `address_space(5)` memory allocated at
kernel launch. The former could look like the following, which could be
implemented in a later patch:

```
template <typename T>
using SharedBuffer = T[gpu::MAX_THREADS] [[clang::address_space(3)]];
template <typename T> struct ErrnoSetter {
  constexpr ErrnoSetter(SharedBuffer<T> &storage) : storage(storage) {}
  SharedBuffer<T> &storage;
  void operator=(const T &val) { storage[gpu::get_thread_id()] = val; }
};

static SharedBuffer<int> thread_local_buffer [[clang::loader_uninitialized]];
ErrnoSetter<int> __llvmlibc_internal_errno(thread_local_buffer);
```

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D149107
2023-04-25 12:41:20 -05:00
Noah Goldstein
0432b85d8e [LIBC] Implement remainder of posix 'sched.h' minus SCHED_SPORADIC
Includes macros:
    linux/SCHED_OTHER // posix req
    linux/SCHED_FIFO // posix req
    linux/SCHED_RR // posix req
    linux/SCHED_BATCH
    linux/SCHED_ISO
    linux/SCHED_IDLE
    linux/SCHED_DEADLINE

Includes types:
    struct sched_param { int sched_priority; }

Includes functions:
    sched_setparam
    sched_getparam
    sched_setscheduler
    sched_getscheduler
    sched_get_priority_max
    sched_get_priority_min
    sched_rr_get_interval

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D148069
2023-04-20 14:53:41 -05:00
Michael Jones
e0de24cb0d [libc] Re-enable wctob with fixes
The stdio test failures were due to headers potentially not being built
in the correct order. This should set up the dependencies correctly.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D146551
2023-03-29 12:49:29 -07:00
Joseph Huber
465f4ac9d7 [libc] Install GPU headers to gpu-none-llvm/ subfolder
The GPU support for the `libc` generates all its own headers. Since
these headers use the same names as the system headers we need to make
sure that they are separate. Currently, we either use the system headers
on the GPU or the GPU headers on the system. This patch makes them
explicitly separate. A follow-up patch will then make `clang` look in
this folder by default.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D146970
2023-03-28 14:27:35 -05:00
Mikhail R. Gadelha
0f6fd1b704 [libc] Add support for setjmp and longjmp in riscv
This patch implements setjmp and longjmp in riscv using inline asm. The
following changes were required:

* Omit frame pointer: otherwise gcc won't allow us to use s0
* Use __attribute__((naked)): otherwise both gcc and clang will generate
function prologue and epilogue in both functions. This doesn't happen
in x86_64, so we guard it to only riscv

Furthermore, using __attribute__((naked)) causes two problems: we
can't use `return 0` (both gcc and clang) and the function arguments in
the function body (clang only), so we had to use a0 and a1 directly.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145584
2023-03-24 16:16:31 -03:00
Michael Jones
07cdf4a10d [libc][obvious] fix missing type headers
forgot to add wint_t and wchar_t type headers to the wchar
headergen definition.

Differential Revision: https://reviews.llvm.org/D146472
2023-03-20 16:43:09 -07:00
Michael Jones
46b5087227 [libc] add basic wide char functions
This patch adds the wchar header, as well as the functions to convert to
and from wide chars. The header also sets up the definitions for wint
and wchar.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145995
2023-03-20 16:36:21 -07:00