1- // ===-- Shared memory RPC server instantiation ------------------*- C++ -* -===//
1+ // ===-- RPC server handling ---------------------------------------------- -===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
55// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66//
77// ===----------------------------------------------------------------------===//
88
9+ #ifndef LLVM_LIBC_SHARED_RPC_SERVER_H
10+ #define LLVM_LIBC_SHARED_RPC_SERVER_H
11+
912// Workaround for missing __has_builtin in < GCC 10.
1013#ifndef __has_builtin
1114#define __has_builtin (x ) 0
1215#endif
1316
17+ // Configs for using the LLVM libc writer interface.
18+ #define LIBC_COPT_USE_C_ASSERT
19+ #define LIBC_COPT_MEMCPY_USE_EMBEDDED_TINY
20+ #define LIBC_COPT_ARRAY_ARG_LIST
21+ #define LIBC_COPT_PRINTF_DISABLE_WRITE_INT
22+ #define LIBC_COPT_PRINTF_DISABLE_INDEX_MODE
23+ #define LIBC_COPT_PRINTF_DISABLE_STRERROR
24+
25+ // The 'long double' type is 8 byte
26+ #define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64
27+
1428#include " shared/rpc.h"
1529#include " shared/rpc_opcodes.h"
1630
2438#include < stdlib.h>
2539
2640namespace LIBC_NAMESPACE {
41+ namespace internal {
2742
2843// Minimal replacement for 'std::vector' that works for trivial types.
2944template <typename T> class TempVector {
@@ -88,15 +103,15 @@ struct TempStorage {
88103 TempVector<char *> storage;
89104};
90105
91- enum Stream {
92- File = 0 ,
93- Stdin = 1 ,
94- Stdout = 2 ,
95- Stderr = 3 ,
96- };
97-
98106// Get the associated stream out of an encoded number.
99- LIBC_INLINE ::FILE *to_stream (uintptr_t f) {
107+ static inline ::FILE *to_stream (uintptr_t f) {
108+ enum Stream {
109+ File = 0 ,
110+ Stdin = 1 ,
111+ Stdout = 2 ,
112+ Stderr = 3 ,
113+ };
114+
100115 ::FILE *stream = reinterpret_cast <FILE *>(f & ~0x3ull );
101116 Stream type = static_cast <Stream>(f & 0x3ull );
102117 if (type == Stdin)
@@ -109,7 +124,8 @@ LIBC_INLINE ::FILE *to_stream(uintptr_t f) {
109124}
110125
111126template <bool packed, uint32_t num_lanes>
112- static void handle_printf (rpc::Server::Port &port, TempStorage &temp_storage) {
127+ static inline void handle_printf (rpc::Server::Port &port,
128+ TempStorage &temp_storage) {
113129 FILE *files[num_lanes] = {nullptr };
114130 // Get the appropriate output stream to use.
115131 if (port.get_opcode () == LIBC_PRINTF_TO_STREAM ||
@@ -282,7 +298,7 @@ static void handle_printf(rpc::Server::Port &port, TempStorage &temp_storage) {
282298}
283299
284300template <uint32_t num_lanes>
285- rpc::Status handle_port_impl (rpc::Server::Port &port) {
301+ static inline rpc::Status handle_port_impl (rpc::Server::Port &port) {
286302 TempStorage temp_storage;
287303
288304 switch (port.get_opcode ()) {
@@ -498,21 +514,24 @@ rpc::Status handle_port_impl(rpc::Server::Port &port) {
498514 return rpc::RPC_SUCCESS;
499515}
500516
517+ } // namespace internal
501518} // namespace LIBC_NAMESPACE
502519
503520namespace rpc {
504- // The implementation of this function currently lives in the utility directory
505- // at 'utils/gpu/server/rpc_server.cpp'.
506- rpc::Status handle_libc_opcodes (rpc::Server::Port &port, uint32_t num_lanes) {
521+ // Handles any opcode generated from the 'libc' client code.
522+ static inline rpc::Status handle_libc_opcodes (rpc::Server::Port &port,
523+ uint32_t num_lanes) {
507524 switch (num_lanes) {
508525 case 1 :
509- return LIBC_NAMESPACE::handle_port_impl<1 >(port);
526+ return LIBC_NAMESPACE::internal:: handle_port_impl<1 >(port);
510527 case 32 :
511- return LIBC_NAMESPACE::handle_port_impl<32 >(port);
528+ return LIBC_NAMESPACE::internal:: handle_port_impl<32 >(port);
512529 case 64 :
513- return LIBC_NAMESPACE::handle_port_impl<64 >(port);
530+ return LIBC_NAMESPACE::internal:: handle_port_impl<64 >(port);
514531 default :
515532 return rpc::RPC_ERROR;
516533 }
517534}
518535} // namespace rpc
536+
537+ #endif // LLVM_LIBC_SHARED_RPC_SERVER_H
0 commit comments