[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.
GitOrigin-RevId: 1d810ece2b2c8fab77720493864257f0ea3336a9
diff --git a/shared/rpc_opcodes.h b/shared/rpc_opcodes.h
index 430b53a..e7ec0e7 100644
--- a/shared/rpc_opcodes.h
+++ b/shared/rpc_opcodes.h
@@ -9,6 +9,8 @@
#ifndef LLVM_LIBC_SHARED_RPC_OPCODES_H
#define LLVM_LIBC_SHARED_RPC_OPCODES_H
+#include "rpc.h"
+
#define LLVM_LIBC_RPC_BASE 'c'
#define LLVM_LIBC_OPCODE(n) (LLVM_LIBC_RPC_BASE << 24 | n)
@@ -46,4 +48,12 @@
RPC_LAST = 0xFFFFFFFF,
} rpc_opcode_t;
+#undef LLVM_LIBC_OPCODE
+
+namespace rpc {
+// The implementation of this function currently lives in the utility directory
+// at 'utils/gpu/server/rpc_server.cpp'.
+rpc::Status handle_libc_opcodes(rpc::Server::Port &port, uint32_t num_lanes);
+} // namespace rpc
+
#endif // LLVM_LIBC_SHARED_RPC_OPCODES_H
diff --git a/utils/gpu/loader/Loader.h b/utils/gpu/loader/Loader.h
index 497f811..6c4434a 100644
--- a/utils/gpu/loader/Loader.h
+++ b/utils/gpu/loader/Loader.h
@@ -9,8 +9,6 @@
#ifndef LLVM_LIBC_UTILS_GPU_LOADER_LOADER_H
#define LLVM_LIBC_UTILS_GPU_LOADER_LOADER_H
-#include "utils/gpu/server/llvmlibc_rpc_server.h"
-
#include "include/llvm-libc-types/test_rpc_opcodes_t.h"
#include "shared/rpc.h"
@@ -183,7 +181,7 @@
break;
}
default:
- status = libc_handle_rpc_port(&*port, num_lanes);
+ status = handle_libc_opcodes(*port, num_lanes);
break;
}
diff --git a/utils/gpu/server/CMakeLists.txt b/utils/gpu/server/CMakeLists.txt
index 36a4c2a..b1cada4 100644
--- a/utils/gpu/server/CMakeLists.txt
+++ b/utils/gpu/server/CMakeLists.txt
@@ -23,9 +23,6 @@
LIBC_NAMESPACE=${LIBC_NAMESPACE})
# Install the server and associated header.
-install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/llvmlibc_rpc_server.h
- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
- COMPONENT libc-headers)
install(TARGETS llvmlibc_rpc_server
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
COMPONENT libc)
diff --git a/utils/gpu/server/llvmlibc_rpc_server.h b/utils/gpu/server/llvmlibc_rpc_server.h
deleted file mode 100644
index b7f1737..0000000
--- a/utils/gpu/server/llvmlibc_rpc_server.h
+++ /dev/null
@@ -1,24 +0,0 @@
-//===-- Shared memory RPC server instantiation ------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_UTILS_GPU_SERVER_RPC_SERVER_H
-#define LLVM_LIBC_UTILS_GPU_SERVER_RPC_SERVER_H
-
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int libc_handle_rpc_port(void *port, uint32_t num_lanes);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/utils/gpu/server/rpc_server.cpp b/utils/gpu/server/rpc_server.cpp
index 21af7ad..559e0f0 100644
--- a/utils/gpu/server/rpc_server.cpp
+++ b/utils/gpu/server/rpc_server.cpp
@@ -17,8 +17,6 @@
#include "shared/rpc.h"
#include "shared/rpc_opcodes.h"
-#include "llvmlibc_rpc_server.h"
-
#include "src/__support/arg_list.h"
#include "src/stdio/printf_core/converter.h"
#include "src/stdio/printf_core/parser.h"
@@ -445,15 +443,19 @@
return rpc::SUCCESS;
}
-int libc_handle_rpc_port(void *port, uint32_t num_lanes) {
+namespace rpc {
+// The implementation of this function currently lives in the utility directory
+// at 'utils/gpu/server/rpc_server.cpp'.
+rpc::Status handle_libc_opcodes(rpc::Server::Port &port, uint32_t num_lanes) {
switch (num_lanes) {
case 1:
- return handle_port_impl<1>(*reinterpret_cast<rpc::Server::Port *>(port));
+ return handle_port_impl<1>(port);
case 32:
- return handle_port_impl<32>(*reinterpret_cast<rpc::Server::Port *>(port));
+ return handle_port_impl<32>(port);
case 64:
- return handle_port_impl<64>(*reinterpret_cast<rpc::Server::Port *>(port));
+ return handle_port_impl<64>(port);
default:
return rpc::ERROR;
}
}
+} // namespace rpc