diff options
author | Joseph Huber <huberjn@outlook.com> | 2024-07-01 06:29:48 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-01 06:29:48 -0500 |
commit | ec0e6ef09bdbae42872af1145f9c58c641d0ab8a (patch) | |
tree | 25e9bc8c8e7848de2193860fd7219d6f55b87249 /libc | |
parent | d32d20f3a05abf74ecc11848a672d4cac4fa45cd (diff) | |
download | llvm-ec0e6ef09bdbae42872af1145f9c58c641d0ab8a.zip llvm-ec0e6ef09bdbae42872af1145f9c58c641d0ab8a.tar.gz llvm-ec0e6ef09bdbae42872af1145f9c58c641d0ab8a.tar.bz2 |
[libc] Implement the 'remove' function on the GPU (#97096)
Summary:
Straightforward RPC implementation of the `remove` function for the GPU.
Copies over the string and calls `remove` on it, passing the result
back. This is required for building some `libc++` functionality.
Diffstat (limited to 'libc')
-rw-r--r-- | libc/config/gpu/entrypoints.txt | 1 | ||||
-rw-r--r-- | libc/docs/gpu/support.rst | 1 | ||||
-rw-r--r-- | libc/include/llvm-libc-types/rpc_opcodes_t.h | 1 | ||||
-rw-r--r-- | libc/src/stdio/gpu/CMakeLists.txt | 11 | ||||
-rw-r--r-- | libc/src/stdio/gpu/remove.cpp | 26 | ||||
-rw-r--r-- | libc/utils/gpu/server/rpc_server.cpp | 11 |
6 files changed, 51 insertions, 0 deletions
diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt index 69f1bdb..c8d68d6 100644 --- a/libc/config/gpu/entrypoints.txt +++ b/libc/config/gpu/entrypoints.txt @@ -205,6 +205,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.stdio.putc libc.src.stdio.putchar libc.src.stdio.puts + libc.src.stdio.remove libc.src.stdio.stderr libc.src.stdio.stdin libc.src.stdio.stdout diff --git a/libc/docs/gpu/support.rst b/libc/docs/gpu/support.rst index 1044b00..6e2c8c7 100644 --- a/libc/docs/gpu/support.rst +++ b/libc/docs/gpu/support.rst @@ -227,6 +227,7 @@ puts |check| |check| fputs |check| |check| fputc |check| |check| fwrite |check| |check| +remove |check| |check| putc |check| |check| putchar |check| |check| fclose |check| |check| diff --git a/libc/include/llvm-libc-types/rpc_opcodes_t.h b/libc/include/llvm-libc-types/rpc_opcodes_t.h index faed7b5..fb3bc7b 100644 --- a/libc/include/llvm-libc-types/rpc_opcodes_t.h +++ b/libc/include/llvm-libc-types/rpc_opcodes_t.h @@ -34,6 +34,7 @@ typedef enum { RPC_PRINTF_TO_STDOUT, RPC_PRINTF_TO_STDERR, RPC_PRINTF_TO_STREAM, + RPC_REMOVE, RPC_LAST = 0xFFFF, } rpc_opcode_t; diff --git a/libc/src/stdio/gpu/CMakeLists.txt b/libc/src/stdio/gpu/CMakeLists.txt index 1b1e2a9..8940843 100644 --- a/libc/src/stdio/gpu/CMakeLists.txt +++ b/libc/src/stdio/gpu/CMakeLists.txt @@ -263,6 +263,17 @@ add_entrypoint_object( ) add_entrypoint_object( + remove + SRCS + remove.cpp + HDRS + ../remove.h + DEPENDS + libc.include.stdio + .gpu_file +) + +add_entrypoint_object( stdin SRCS stdin.cpp diff --git a/libc/src/stdio/gpu/remove.cpp b/libc/src/stdio/gpu/remove.cpp new file mode 100644 index 0000000..398be5f --- /dev/null +++ b/libc/src/stdio/gpu/remove.cpp @@ -0,0 +1,26 @@ +//===-- Implementation of remove ------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/stdio/remove.h" +#include "file.h" + +#include <stdio.h> + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(int, remove, (const char *path)) { + int ret; + rpc::Client::Port port = rpc::client.open<RPC_REMOVE>(); + port.send_n(path, internal::string_length(path) + 1); + port.recv( + [&](rpc::Buffer *buffer) { ret = static_cast<int>(buffer->data[0]); }); + port.close(); + return ret; +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/utils/gpu/server/rpc_server.cpp b/libc/utils/gpu/server/rpc_server.cpp index 095f3fa..a05fc845 100644 --- a/libc/utils/gpu/server/rpc_server.cpp +++ b/libc/utils/gpu/server/rpc_server.cpp @@ -343,6 +343,17 @@ rpc_status_t handle_server_impl( handle_printf<lane_size>(*port); break; } + case RPC_REMOVE: { + uint64_t sizes[lane_size] = {0}; + void *args[lane_size] = {nullptr}; + port->recv_n(args, sizes, [&](uint64_t size) { return new char[size]; }); + port->send([&](rpc::Buffer *buffer, uint32_t id) { + buffer->data[0] = static_cast<uint64_t>( + remove(reinterpret_cast<const char *>(args[id]))); + delete[] reinterpret_cast<uint8_t *>(args[id]); + }); + break; + } case RPC_NOOP: { port->recv([](rpc::Buffer *) {}); break; |