[libc-commits] [libc] [libc] Implement the 'rename' function on the GPU (PR #109814)
via libc-commits
libc-commits at lists.llvm.org
Tue Sep 24 08:14:21 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Joseph Huber (jhuber6)
<details>
<summary>Changes</summary>
Summary:
Straightforward implementation like the other `stdio.h` functions.
---
Full diff: https://github.com/llvm/llvm-project/pull/109814.diff
6 Files Affected:
- (modified) libc/config/gpu/entrypoints.txt (+1)
- (modified) libc/docs/gpu/support.rst (+1)
- (modified) libc/include/llvm-libc-types/rpc_opcodes_t.h (+1)
- (modified) libc/src/stdio/gpu/CMakeLists.txt (+11)
- (added) libc/src/stdio/gpu/rename.cpp (+30)
- (modified) libc/utils/gpu/server/rpc_server.cpp (+18)
``````````diff
diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt
index 9fb89e6fd8d28a..b4cfe47f4505fd 100644
--- a/libc/config/gpu/entrypoints.txt
+++ b/libc/config/gpu/entrypoints.txt
@@ -240,6 +240,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdio.putchar
libc.src.stdio.puts
libc.src.stdio.remove
+ libc.src.stdio.rename
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 44c21c7b4c1ff9..9c151a5fbac1f6 100644
--- a/libc/docs/gpu/support.rst
+++ b/libc/docs/gpu/support.rst
@@ -240,6 +240,7 @@ fputs |check| |check|
fputc |check| |check|
fwrite |check| |check|
remove |check| |check|
+rename |check| |check|
putc |check| |check|
printf |check| |check|
vprintf |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 3b388de6888c5d..1a6c0cd9bc4a14 100644
--- a/libc/include/llvm-libc-types/rpc_opcodes_t.h
+++ b/libc/include/llvm-libc-types/rpc_opcodes_t.h
@@ -38,6 +38,7 @@ typedef enum {
RPC_PRINTF_TO_STDERR_PACKED,
RPC_PRINTF_TO_STREAM_PACKED,
RPC_REMOVE,
+ RPC_RENAME,
RPC_SYSTEM,
RPC_LAST = 0xFFFF,
} rpc_opcode_t;
diff --git a/libc/src/stdio/gpu/CMakeLists.txt b/libc/src/stdio/gpu/CMakeLists.txt
index 86470b8425e956..9cac42ed71fb76 100644
--- a/libc/src/stdio/gpu/CMakeLists.txt
+++ b/libc/src/stdio/gpu/CMakeLists.txt
@@ -294,6 +294,17 @@ add_entrypoint_object(
.vfprintf_utils
)
+add_entrypoint_object(
+ rename
+ SRCS
+ rename.cpp
+ HDRS
+ ../rename.h
+ DEPENDS
+ libc.hdr.types.FILE
+ .gpu_file
+)
+
add_entrypoint_object(
stdin
SRCS
diff --git a/libc/src/stdio/gpu/rename.cpp b/libc/src/stdio/gpu/rename.cpp
new file mode 100644
index 00000000000000..1087228835842e
--- /dev/null
+++ b/libc/src/stdio/gpu/rename.cpp
@@ -0,0 +1,30 @@
+//===-- GPU Implementation of rename --------------------------------------===//
+//
+// 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/rename.h"
+#include "src/__support/CPP/string_view.h"
+#include "src/__support/macros/config.h"
+#include "src/stdio/gpu/file.h"
+
+#include "hdr/types/FILE.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, rename, (const char *oldpath, const char *newpath)) {
+ int ret;
+ rpc::Client::Port port = rpc::client.open<RPC_RENAME>();
+ port.send_n(oldpath, internal::string_length(oldpath) + 1);
+ port.send_n(newpath, internal::string_length(newpath) + 1);
+ port.recv(
+ [&](rpc::Buffer *buffer) { ret = static_cast<int>(buffer->data[0]); });
+ port.close();
+
+ return ret;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/utils/gpu/server/rpc_server.cpp b/libc/utils/gpu/server/rpc_server.cpp
index 8708f946b310ee..aa65dfe69c385c 100644
--- a/libc/utils/gpu/server/rpc_server.cpp
+++ b/libc/utils/gpu/server/rpc_server.cpp
@@ -392,6 +392,24 @@ rpc_status_t handle_server_impl(
});
break;
}
+ case RPC_RENAME: {
+ uint64_t oldsizes[lane_size] = {0};
+ uint64_t newsizes[lane_size] = {0};
+ void *oldpath[lane_size] = {nullptr};
+ void *newpath[lane_size] = {nullptr};
+ port->recv_n(oldpath, oldsizes,
+ [&](uint64_t size) { return new char[size]; });
+ port->recv_n(newpath, newsizes,
+ [&](uint64_t size) { return new char[size]; });
+ port->send([&](rpc::Buffer *buffer, uint32_t id) {
+ buffer->data[0] = static_cast<uint64_t>(
+ rename(reinterpret_cast<const char *>(oldpath[id]),
+ reinterpret_cast<const char *>(newpath[id])));
+ delete[] reinterpret_cast<uint8_t *>(oldpath[id]);
+ delete[] reinterpret_cast<uint8_t *>(newpath[id]);
+ });
+ break;
+ }
case RPC_SYSTEM: {
uint64_t sizes[lane_size] = {0};
void *args[lane_size] = {nullptr};
``````````
</details>
https://github.com/llvm/llvm-project/pull/109814
More information about the libc-commits
mailing list