mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 02:33:06 +01:00
[ORC] Move Orc RPC code into Shared, rename some RPC types.
Moves all headers from Orc/RPC to Orc/Shared, and from the llvm::orc::rpc namespace into llvm::orc::shared. Also renames RPCTypeName to SerializationTypeName and Function to RPCFunction. In addition to being a more reasonable home for this code, this will make it easier for the upcoming Orc runtime to re-use the Serialization system for creating and parsing wrapper-function binary blobs.
This commit is contained in:
parent
8395b2b8fd
commit
cf3fe0c756
@ -13,8 +13,8 @@
|
||||
#ifndef LLVM_EXECUTIONENGINE_ORC_ORCRPCTARGETPROCESSCONTROL_H
|
||||
#define LLVM_EXECUTIONENGINE_ORC_ORCRPCTARGETPROCESSCONTROL_H
|
||||
|
||||
#include "llvm/ExecutionEngine/Orc/RPC/RPCUtils.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RPC/RawByteChannel.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/RPCUtils.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/RawByteChannel.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcess/OrcRPCTPCServer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcessControl.h"
|
||||
#include "llvm/Support/MSVCErrorWorkarounds.h"
|
||||
|
@ -54,7 +54,7 @@ namespace remote {
|
||||
/// OrcRemoteTargetServer class) via an RPC system (see RPCUtils.h) to carry out
|
||||
/// its actions.
|
||||
class OrcRemoteTargetClient
|
||||
: public rpc::SingleThreadedRPCEndpoint<rpc::RawByteChannel> {
|
||||
: public shared::SingleThreadedRPCEndpoint<shared::RawByteChannel> {
|
||||
public:
|
||||
/// Remote-mapped RuntimeDyld-compatible memory manager.
|
||||
class RemoteRTDyldMemoryManager : public RuntimeDyld::MemoryManager {
|
||||
@ -703,7 +703,7 @@ public:
|
||||
/// Channel is the ChannelT instance to communicate on. It is assumed that
|
||||
/// the channel is ready to be read from and written to.
|
||||
static Expected<std::unique_ptr<OrcRemoteTargetClient>>
|
||||
Create(rpc::RawByteChannel &Channel, ExecutionSession &ES) {
|
||||
Create(shared::RawByteChannel &Channel, ExecutionSession &ES) {
|
||||
Error Err = Error::success();
|
||||
auto Client = std::unique_ptr<OrcRemoteTargetClient>(
|
||||
new OrcRemoteTargetClient(Channel, ES, Err));
|
||||
@ -805,9 +805,10 @@ public:
|
||||
Error terminateSession() { return callB<utils::TerminateSession>(); }
|
||||
|
||||
private:
|
||||
OrcRemoteTargetClient(rpc::RawByteChannel &Channel, ExecutionSession &ES,
|
||||
OrcRemoteTargetClient(shared::RawByteChannel &Channel, ExecutionSession &ES,
|
||||
Error &Err)
|
||||
: rpc::SingleThreadedRPCEndpoint<rpc::RawByteChannel>(Channel, true),
|
||||
: shared::SingleThreadedRPCEndpoint<shared::RawByteChannel>(Channel,
|
||||
true),
|
||||
ES(ES) {
|
||||
ErrorAsOutParameter EAO(&Err);
|
||||
|
||||
|
@ -16,8 +16,8 @@
|
||||
#define LLVM_EXECUTIONENGINE_ORC_ORCREMOTETARGETRPCAPI_H
|
||||
|
||||
#include "llvm/ExecutionEngine/JITSymbol.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RPC/RPCUtils.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RPC/RawByteChannel.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/RPCUtils.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/RawByteChannel.h"
|
||||
|
||||
namespace llvm {
|
||||
namespace orc {
|
||||
@ -73,10 +73,9 @@ private:
|
||||
|
||||
} // end namespace remote
|
||||
|
||||
namespace rpc {
|
||||
namespace shared {
|
||||
|
||||
template <>
|
||||
class RPCTypeName<JITSymbolFlags> {
|
||||
template <> class SerializationTypeName<JITSymbolFlags> {
|
||||
public:
|
||||
static const char *getName() { return "JITSymbolFlags"; }
|
||||
};
|
||||
@ -100,7 +99,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template <> class RPCTypeName<remote::DirectBufferWriter> {
|
||||
template <> class SerializationTypeName<remote::DirectBufferWriter> {
|
||||
public:
|
||||
static const char *getName() { return "DirectBufferWriter"; }
|
||||
};
|
||||
@ -133,7 +132,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace rpc
|
||||
} // end namespace shared
|
||||
|
||||
namespace remote {
|
||||
|
||||
@ -167,20 +166,20 @@ private:
|
||||
namespace eh {
|
||||
|
||||
/// Registers EH frames on the remote.
|
||||
class RegisterEHFrames
|
||||
: public rpc::Function<RegisterEHFrames,
|
||||
void(JITTargetAddress Addr, uint32_t Size)> {
|
||||
public:
|
||||
static const char *getName() { return "RegisterEHFrames"; }
|
||||
};
|
||||
class RegisterEHFrames
|
||||
: public shared::RPCFunction<RegisterEHFrames,
|
||||
void(JITTargetAddress Addr, uint32_t Size)> {
|
||||
public:
|
||||
static const char *getName() { return "RegisterEHFrames"; }
|
||||
};
|
||||
|
||||
/// Deregisters EH frames on the remote.
|
||||
class DeregisterEHFrames
|
||||
: public rpc::Function<DeregisterEHFrames,
|
||||
void(JITTargetAddress Addr, uint32_t Size)> {
|
||||
public:
|
||||
static const char *getName() { return "DeregisterEHFrames"; }
|
||||
};
|
||||
class DeregisterEHFrames
|
||||
: public shared::RPCFunction<DeregisterEHFrames,
|
||||
void(JITTargetAddress Addr, uint32_t Size)> {
|
||||
public:
|
||||
static const char *getName() { return "DeregisterEHFrames"; }
|
||||
};
|
||||
|
||||
} // end namespace eh
|
||||
|
||||
@ -189,36 +188,38 @@ namespace exec {
|
||||
|
||||
/// Call an 'int32_t()'-type function on the remote, returns the called
|
||||
/// function's return value.
|
||||
class CallIntVoid
|
||||
: public rpc::Function<CallIntVoid, int32_t(JITTargetAddress Addr)> {
|
||||
public:
|
||||
static const char *getName() { return "CallIntVoid"; }
|
||||
};
|
||||
class CallIntVoid
|
||||
: public shared::RPCFunction<CallIntVoid, int32_t(JITTargetAddress Addr)> {
|
||||
public:
|
||||
static const char *getName() { return "CallIntVoid"; }
|
||||
};
|
||||
|
||||
/// Call an 'int32_t(int32_t)'-type function on the remote, returns the called
|
||||
/// function's return value.
|
||||
class CallIntInt
|
||||
: public rpc::Function<CallIntInt, int32_t(JITTargetAddress Addr, int)> {
|
||||
public:
|
||||
static const char *getName() { return "CallIntInt"; }
|
||||
};
|
||||
class CallIntInt
|
||||
: public shared::RPCFunction<CallIntInt,
|
||||
int32_t(JITTargetAddress Addr, int)> {
|
||||
public:
|
||||
static const char *getName() { return "CallIntInt"; }
|
||||
};
|
||||
|
||||
/// Call an 'int32_t(int32_t, char**)'-type function on the remote, returns the
|
||||
/// called function's return value.
|
||||
class CallMain
|
||||
: public rpc::Function<CallMain, int32_t(JITTargetAddress Addr,
|
||||
std::vector<std::string> Args)> {
|
||||
public:
|
||||
static const char *getName() { return "CallMain"; }
|
||||
};
|
||||
class CallMain
|
||||
: public shared::RPCFunction<CallMain,
|
||||
int32_t(JITTargetAddress Addr,
|
||||
std::vector<std::string> Args)> {
|
||||
public:
|
||||
static const char *getName() { return "CallMain"; }
|
||||
};
|
||||
|
||||
/// Calls a 'void()'-type function on the remote, returns when the called
|
||||
/// function completes.
|
||||
class CallVoidVoid
|
||||
: public rpc::Function<CallVoidVoid, void(JITTargetAddress FnAddr)> {
|
||||
public:
|
||||
static const char *getName() { return "CallVoidVoid"; }
|
||||
};
|
||||
class CallVoidVoid
|
||||
: public shared::RPCFunction<CallVoidVoid, void(JITTargetAddress FnAddr)> {
|
||||
public:
|
||||
static const char *getName() { return "CallVoidVoid"; }
|
||||
};
|
||||
|
||||
} // end namespace exec
|
||||
|
||||
@ -226,60 +227,62 @@ namespace exec {
|
||||
namespace mem {
|
||||
|
||||
/// Creates a memory allocator on the remote.
|
||||
class CreateRemoteAllocator
|
||||
: public rpc::Function<CreateRemoteAllocator,
|
||||
void(ResourceIdMgr::ResourceId AllocatorID)> {
|
||||
public:
|
||||
static const char *getName() { return "CreateRemoteAllocator"; }
|
||||
};
|
||||
class CreateRemoteAllocator
|
||||
: public shared::RPCFunction<CreateRemoteAllocator,
|
||||
void(ResourceIdMgr::ResourceId AllocatorID)> {
|
||||
public:
|
||||
static const char *getName() { return "CreateRemoteAllocator"; }
|
||||
};
|
||||
|
||||
/// Destroys a remote allocator, freeing any memory allocated by it.
|
||||
class DestroyRemoteAllocator
|
||||
: public rpc::Function<DestroyRemoteAllocator,
|
||||
void(ResourceIdMgr::ResourceId AllocatorID)> {
|
||||
public:
|
||||
static const char *getName() { return "DestroyRemoteAllocator"; }
|
||||
};
|
||||
class DestroyRemoteAllocator
|
||||
: public shared::RPCFunction<DestroyRemoteAllocator,
|
||||
void(ResourceIdMgr::ResourceId AllocatorID)> {
|
||||
public:
|
||||
static const char *getName() { return "DestroyRemoteAllocator"; }
|
||||
};
|
||||
|
||||
/// Read a remote memory block.
|
||||
class ReadMem
|
||||
: public rpc::Function<ReadMem, std::vector<uint8_t>(JITTargetAddress Src,
|
||||
uint64_t Size)> {
|
||||
public:
|
||||
static const char *getName() { return "ReadMem"; }
|
||||
};
|
||||
class ReadMem
|
||||
: public shared::RPCFunction<
|
||||
ReadMem, std::vector<uint8_t>(JITTargetAddress Src, uint64_t Size)> {
|
||||
public:
|
||||
static const char *getName() { return "ReadMem"; }
|
||||
};
|
||||
|
||||
/// Reserve a block of memory on the remote via the given allocator.
|
||||
class ReserveMem
|
||||
: public rpc::Function<ReserveMem,
|
||||
JITTargetAddress(ResourceIdMgr::ResourceId AllocID,
|
||||
uint64_t Size, uint32_t Align)> {
|
||||
public:
|
||||
static const char *getName() { return "ReserveMem"; }
|
||||
};
|
||||
class ReserveMem
|
||||
: public shared::RPCFunction<
|
||||
ReserveMem, JITTargetAddress(ResourceIdMgr::ResourceId AllocID,
|
||||
uint64_t Size, uint32_t Align)> {
|
||||
public:
|
||||
static const char *getName() { return "ReserveMem"; }
|
||||
};
|
||||
|
||||
/// Set the memory protection on a memory block.
|
||||
class SetProtections
|
||||
: public rpc::Function<SetProtections,
|
||||
void(ResourceIdMgr::ResourceId AllocID,
|
||||
JITTargetAddress Dst, uint32_t ProtFlags)> {
|
||||
public:
|
||||
static const char *getName() { return "SetProtections"; }
|
||||
};
|
||||
class SetProtections
|
||||
: public shared::RPCFunction<
|
||||
SetProtections, void(ResourceIdMgr::ResourceId AllocID,
|
||||
JITTargetAddress Dst, uint32_t ProtFlags)> {
|
||||
public:
|
||||
static const char *getName() { return "SetProtections"; }
|
||||
};
|
||||
|
||||
/// Write to a remote memory block.
|
||||
class WriteMem
|
||||
: public rpc::Function<WriteMem, void(remote::DirectBufferWriter DB)> {
|
||||
public:
|
||||
static const char *getName() { return "WriteMem"; }
|
||||
};
|
||||
class WriteMem
|
||||
: public shared::RPCFunction<WriteMem,
|
||||
void(remote::DirectBufferWriter DB)> {
|
||||
public:
|
||||
static const char *getName() { return "WriteMem"; }
|
||||
};
|
||||
|
||||
/// Write to a remote pointer.
|
||||
class WritePtr : public rpc::Function<WritePtr, void(JITTargetAddress Dst,
|
||||
JITTargetAddress Val)> {
|
||||
public:
|
||||
static const char *getName() { return "WritePtr"; }
|
||||
};
|
||||
class WritePtr
|
||||
: public shared::RPCFunction<WritePtr, void(JITTargetAddress Dst,
|
||||
JITTargetAddress Val)> {
|
||||
public:
|
||||
static const char *getName() { return "WritePtr"; }
|
||||
};
|
||||
|
||||
} // end namespace mem
|
||||
|
||||
@ -287,45 +290,46 @@ namespace mem {
|
||||
namespace stubs {
|
||||
|
||||
/// Creates an indirect stub owner on the remote.
|
||||
class CreateIndirectStubsOwner
|
||||
: public rpc::Function<CreateIndirectStubsOwner,
|
||||
void(ResourceIdMgr::ResourceId StubOwnerID)> {
|
||||
public:
|
||||
static const char *getName() { return "CreateIndirectStubsOwner"; }
|
||||
};
|
||||
class CreateIndirectStubsOwner
|
||||
: public shared::RPCFunction<CreateIndirectStubsOwner,
|
||||
void(ResourceIdMgr::ResourceId StubOwnerID)> {
|
||||
public:
|
||||
static const char *getName() { return "CreateIndirectStubsOwner"; }
|
||||
};
|
||||
|
||||
/// RPC function for destroying an indirect stubs owner.
|
||||
class DestroyIndirectStubsOwner
|
||||
: public rpc::Function<DestroyIndirectStubsOwner,
|
||||
void(ResourceIdMgr::ResourceId StubsOwnerID)> {
|
||||
public:
|
||||
static const char *getName() { return "DestroyIndirectStubsOwner"; }
|
||||
};
|
||||
class DestroyIndirectStubsOwner
|
||||
: public shared::RPCFunction<DestroyIndirectStubsOwner,
|
||||
void(ResourceIdMgr::ResourceId StubsOwnerID)> {
|
||||
public:
|
||||
static const char *getName() { return "DestroyIndirectStubsOwner"; }
|
||||
};
|
||||
|
||||
/// EmitIndirectStubs result is (StubsBase, PtrsBase, NumStubsEmitted).
|
||||
class EmitIndirectStubs
|
||||
: public rpc::Function<
|
||||
EmitIndirectStubs,
|
||||
std::tuple<JITTargetAddress, JITTargetAddress, uint32_t>(
|
||||
ResourceIdMgr::ResourceId StubsOwnerID,
|
||||
uint32_t NumStubsRequired)> {
|
||||
public:
|
||||
static const char *getName() { return "EmitIndirectStubs"; }
|
||||
};
|
||||
class EmitIndirectStubs
|
||||
: public shared::RPCFunction<
|
||||
EmitIndirectStubs,
|
||||
std::tuple<JITTargetAddress, JITTargetAddress, uint32_t>(
|
||||
ResourceIdMgr::ResourceId StubsOwnerID,
|
||||
uint32_t NumStubsRequired)> {
|
||||
public:
|
||||
static const char *getName() { return "EmitIndirectStubs"; }
|
||||
};
|
||||
|
||||
/// RPC function to emit the resolver block and return its address.
|
||||
class EmitResolverBlock : public rpc::Function<EmitResolverBlock, void()> {
|
||||
public:
|
||||
static const char *getName() { return "EmitResolverBlock"; }
|
||||
};
|
||||
class EmitResolverBlock
|
||||
: public shared::RPCFunction<EmitResolverBlock, void()> {
|
||||
public:
|
||||
static const char *getName() { return "EmitResolverBlock"; }
|
||||
};
|
||||
|
||||
/// EmitTrampolineBlock result is (BlockAddr, NumTrampolines).
|
||||
class EmitTrampolineBlock
|
||||
: public rpc::Function<EmitTrampolineBlock,
|
||||
std::tuple<JITTargetAddress, uint32_t>()> {
|
||||
public:
|
||||
static const char *getName() { return "EmitTrampolineBlock"; }
|
||||
};
|
||||
class EmitTrampolineBlock
|
||||
: public shared::RPCFunction<EmitTrampolineBlock,
|
||||
std::tuple<JITTargetAddress, uint32_t>()> {
|
||||
public:
|
||||
static const char *getName() { return "EmitTrampolineBlock"; }
|
||||
};
|
||||
|
||||
} // end namespace stubs
|
||||
|
||||
@ -334,44 +338,44 @@ namespace utils {
|
||||
|
||||
/// GetRemoteInfo result is (Triple, PointerSize, PageSize, TrampolineSize,
|
||||
/// IndirectStubsSize).
|
||||
class GetRemoteInfo
|
||||
: public rpc::Function<
|
||||
GetRemoteInfo,
|
||||
std::tuple<std::string, uint32_t, uint32_t, uint32_t, uint32_t>()> {
|
||||
public:
|
||||
static const char *getName() { return "GetRemoteInfo"; }
|
||||
};
|
||||
class GetRemoteInfo
|
||||
: public shared::RPCFunction<
|
||||
GetRemoteInfo,
|
||||
std::tuple<std::string, uint32_t, uint32_t, uint32_t, uint32_t>()> {
|
||||
public:
|
||||
static const char *getName() { return "GetRemoteInfo"; }
|
||||
};
|
||||
|
||||
/// Get the address of a remote symbol.
|
||||
class GetSymbolAddress
|
||||
: public rpc::Function<GetSymbolAddress,
|
||||
JITTargetAddress(std::string SymbolName)> {
|
||||
public:
|
||||
static const char *getName() { return "GetSymbolAddress"; }
|
||||
};
|
||||
class GetSymbolAddress
|
||||
: public shared::RPCFunction<GetSymbolAddress,
|
||||
JITTargetAddress(std::string SymbolName)> {
|
||||
public:
|
||||
static const char *getName() { return "GetSymbolAddress"; }
|
||||
};
|
||||
|
||||
/// Request that the host execute a compile callback.
|
||||
class RequestCompile
|
||||
: public rpc::Function<
|
||||
RequestCompile, JITTargetAddress(JITTargetAddress TrampolineAddr)> {
|
||||
public:
|
||||
static const char *getName() { return "RequestCompile"; }
|
||||
};
|
||||
class RequestCompile
|
||||
: public shared::RPCFunction<
|
||||
RequestCompile, JITTargetAddress(JITTargetAddress TrampolineAddr)> {
|
||||
public:
|
||||
static const char *getName() { return "RequestCompile"; }
|
||||
};
|
||||
|
||||
/// Notify the remote and terminate the session.
|
||||
class TerminateSession : public rpc::Function<TerminateSession, void()> {
|
||||
public:
|
||||
static const char *getName() { return "TerminateSession"; }
|
||||
};
|
||||
class TerminateSession : public shared::RPCFunction<TerminateSession, void()> {
|
||||
public:
|
||||
static const char *getName() { return "TerminateSession"; }
|
||||
};
|
||||
|
||||
} // namespace utils
|
||||
|
||||
class OrcRemoteTargetRPCAPI
|
||||
: public rpc::SingleThreadedRPCEndpoint<rpc::RawByteChannel> {
|
||||
: public shared::SingleThreadedRPCEndpoint<shared::RawByteChannel> {
|
||||
public:
|
||||
// FIXME: Remove constructors once MSVC supports synthesizing move-ops.
|
||||
OrcRemoteTargetRPCAPI(rpc::RawByteChannel &C)
|
||||
: rpc::SingleThreadedRPCEndpoint<rpc::RawByteChannel>(C, true) {}
|
||||
OrcRemoteTargetRPCAPI(shared::RawByteChannel &C)
|
||||
: shared::SingleThreadedRPCEndpoint<shared::RawByteChannel>(C, true) {}
|
||||
};
|
||||
|
||||
} // end namespace remote
|
||||
|
@ -46,7 +46,7 @@ namespace remote {
|
||||
|
||||
template <typename ChannelT, typename TargetT>
|
||||
class OrcRemoteTargetServer
|
||||
: public rpc::SingleThreadedRPCEndpoint<rpc::RawByteChannel> {
|
||||
: public shared::SingleThreadedRPCEndpoint<shared::RawByteChannel> {
|
||||
public:
|
||||
using SymbolLookupFtor =
|
||||
std::function<JITTargetAddress(const std::string &Name)>;
|
||||
@ -57,7 +57,8 @@ public:
|
||||
OrcRemoteTargetServer(ChannelT &Channel, SymbolLookupFtor SymbolLookup,
|
||||
EHFrameRegistrationFtor EHFramesRegister,
|
||||
EHFrameRegistrationFtor EHFramesDeregister)
|
||||
: rpc::SingleThreadedRPCEndpoint<rpc::RawByteChannel>(Channel, true),
|
||||
: shared::SingleThreadedRPCEndpoint<shared::RawByteChannel>(Channel,
|
||||
true),
|
||||
SymbolLookup(std::move(SymbolLookup)),
|
||||
EHFramesRegister(std::move(EHFramesRegister)),
|
||||
EHFramesDeregister(std::move(EHFramesDeregister)) {
|
||||
|
@ -10,10 +10,10 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_EXECUTIONENGINE_ORC_RPC_FDRAWBYTECHANNEL_H
|
||||
#define LLVM_EXECUTIONENGINE_ORC_RPC_FDRAWBYTECHANNEL_H
|
||||
#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_FDRAWBYTECHANNEL_H
|
||||
#define LLVM_EXECUTIONENGINE_ORC_SHARED_FDRAWBYTECHANNEL_H
|
||||
|
||||
#include "llvm/ExecutionEngine/Orc/RPC/RawByteChannel.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/RawByteChannel.h"
|
||||
|
||||
#include "llvm/Support/FormatVariadic.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
@ -26,9 +26,9 @@
|
||||
|
||||
namespace llvm {
|
||||
namespace orc {
|
||||
namespace rpc {
|
||||
namespace shared {
|
||||
|
||||
/// RPC channel that reads from and writes from file descriptors.
|
||||
/// Serialization channel that reads from and writes from file descriptors.
|
||||
class FDRawByteChannel final : public RawByteChannel {
|
||||
public:
|
||||
FDRawByteChannel(int InFD, int OutFD) : InFD(InFD), OutFD(OutFD) {}
|
||||
@ -85,8 +85,8 @@ private:
|
||||
int InFD, OutFD;
|
||||
};
|
||||
|
||||
} // namespace rpc
|
||||
} // namespace shared
|
||||
} // namespace orc
|
||||
} // namespace llvm
|
||||
|
||||
#endif // LLVM_EXECUTIONENGINE_ORC_RPC_FDRAWBYTECHANNEL_H
|
||||
#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_FDRAWBYTECHANNEL_H
|
@ -14,8 +14,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_EXECUTIONENGINE_ORC_RPC_RPCUTILS_H
|
||||
#define LLVM_EXECUTIONENGINE_ORC_RPC_RPCUTILS_H
|
||||
#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_RPCUTILS_H
|
||||
#define LLVM_EXECUTIONENGINE_ORC_SHARED_RPCUTILS_H
|
||||
|
||||
#include <map>
|
||||
#include <thread>
|
||||
@ -23,14 +23,14 @@
|
||||
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ExecutionEngine/Orc/OrcError.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RPC/RPCSerialization.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/Serialization.h"
|
||||
#include "llvm/Support/MSVCErrorWorkarounds.h"
|
||||
|
||||
#include <future>
|
||||
|
||||
namespace llvm {
|
||||
namespace orc {
|
||||
namespace rpc {
|
||||
namespace shared {
|
||||
|
||||
/// Base class of all fatal RPC errors (those that necessarily result in the
|
||||
/// termination of the RPC session).
|
||||
@ -56,7 +56,7 @@ public:
|
||||
/// function id it cannot parse the call.
|
||||
template <typename FnIdT, typename SeqNoT>
|
||||
class BadFunctionCall
|
||||
: public ErrorInfo<BadFunctionCall<FnIdT, SeqNoT>, RPCFatalError> {
|
||||
: public ErrorInfo<BadFunctionCall<FnIdT, SeqNoT>, RPCFatalError> {
|
||||
public:
|
||||
static char ID;
|
||||
|
||||
@ -68,8 +68,10 @@ public:
|
||||
}
|
||||
|
||||
void log(raw_ostream &OS) const override {
|
||||
OS << "Call to invalid RPC function id '" << FnId << "' with "
|
||||
"sequence number " << SeqNo;
|
||||
OS << "Call to invalid RPC function id '" << FnId
|
||||
<< "' with "
|
||||
"sequence number "
|
||||
<< SeqNo;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -89,12 +91,12 @@ char BadFunctionCall<FnIdT, SeqNoT>::ID = 0;
|
||||
/// a result parser for this sequence number it can't do that.
|
||||
template <typename SeqNoT>
|
||||
class InvalidSequenceNumberForResponse
|
||||
: public ErrorInfo<InvalidSequenceNumberForResponse<SeqNoT>, RPCFatalError> {
|
||||
: public ErrorInfo<InvalidSequenceNumberForResponse<SeqNoT>,
|
||||
RPCFatalError> {
|
||||
public:
|
||||
static char ID;
|
||||
|
||||
InvalidSequenceNumberForResponse(SeqNoT SeqNo)
|
||||
: SeqNo(std::move(SeqNo)) {}
|
||||
InvalidSequenceNumberForResponse(SeqNoT SeqNo) : SeqNo(std::move(SeqNo)) {}
|
||||
|
||||
std::error_code convertToErrorCode() const override {
|
||||
return orcError(OrcErrorCode::UnexpectedRPCCall);
|
||||
@ -103,6 +105,7 @@ public:
|
||||
void log(raw_ostream &OS) const override {
|
||||
OS << "Response has unknown sequence number " << SeqNo;
|
||||
}
|
||||
|
||||
private:
|
||||
SeqNoT SeqNo;
|
||||
};
|
||||
@ -131,17 +134,18 @@ public:
|
||||
std::error_code convertToErrorCode() const override;
|
||||
void log(raw_ostream &OS) const override;
|
||||
const std::string &getSignature() const { return Signature; }
|
||||
|
||||
private:
|
||||
std::string Signature;
|
||||
};
|
||||
|
||||
template <typename DerivedFunc, typename FnT> class Function;
|
||||
template <typename DerivedFunc, typename FnT> class RPCFunction;
|
||||
|
||||
// RPC Function class.
|
||||
// DerivedFunc should be a user defined class with a static 'getName()' method
|
||||
// returning a const char* representing the function's name.
|
||||
template <typename DerivedFunc, typename RetT, typename... ArgTs>
|
||||
class Function<DerivedFunc, RetT(ArgTs...)> {
|
||||
class RPCFunction<DerivedFunc, RetT(ArgTs...)> {
|
||||
public:
|
||||
/// User defined function type.
|
||||
using Type = RetT(ArgTs...);
|
||||
@ -154,8 +158,9 @@ public:
|
||||
static std::string Name = [] {
|
||||
std::string Name;
|
||||
raw_string_ostream(Name)
|
||||
<< RPCTypeName<RetT>::getName() << " " << DerivedFunc::getName()
|
||||
<< "(" << llvm::orc::rpc::RPCTypeNameSequence<ArgTs...>() << ")";
|
||||
<< SerializationTypeName<RetT>::getName() << " "
|
||||
<< DerivedFunc::getName() << "("
|
||||
<< SerializationTypeNameSequence<ArgTs...>() << ")";
|
||||
return Name;
|
||||
}();
|
||||
return Name.data();
|
||||
@ -199,10 +204,10 @@ private:
|
||||
namespace detail {
|
||||
|
||||
/// Provides a typedef for a tuple containing the decayed argument types.
|
||||
template <typename T> class FunctionArgsTuple;
|
||||
template <typename T> class RPCFunctionArgsTuple;
|
||||
|
||||
template <typename RetT, typename... ArgTs>
|
||||
class FunctionArgsTuple<RetT(ArgTs...)> {
|
||||
class RPCFunctionArgsTuple<RetT(ArgTs...)> {
|
||||
public:
|
||||
using Type = std::tuple<std::decay_t<std::remove_reference_t<ArgTs>>...>;
|
||||
};
|
||||
@ -287,34 +292,28 @@ class ResultTraits<Expected<RetT>> : public ResultTraits<RetT> {};
|
||||
|
||||
// Determines whether an RPC function's defined error return type supports
|
||||
// error return value.
|
||||
template <typename T>
|
||||
class SupportsErrorReturn {
|
||||
template <typename T> class SupportsErrorReturn {
|
||||
public:
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
template <>
|
||||
class SupportsErrorReturn<Error> {
|
||||
template <> class SupportsErrorReturn<Error> {
|
||||
public:
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class SupportsErrorReturn<Expected<T>> {
|
||||
template <typename T> class SupportsErrorReturn<Expected<T>> {
|
||||
public:
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
// RespondHelper packages return values based on whether or not the declared
|
||||
// RPC function return type supports error returns.
|
||||
template <bool FuncSupportsErrorReturn>
|
||||
class RespondHelper;
|
||||
template <bool FuncSupportsErrorReturn> class RespondHelper;
|
||||
|
||||
// RespondHelper specialization for functions that support error returns.
|
||||
template <>
|
||||
class RespondHelper<true> {
|
||||
template <> class RespondHelper<true> {
|
||||
public:
|
||||
|
||||
// Send Expected<T>.
|
||||
template <typename WireRetT, typename HandlerRetT, typename ChannelT,
|
||||
typename FunctionIdT, typename SequenceNumberT>
|
||||
@ -330,9 +329,8 @@ public:
|
||||
|
||||
// Serialize the result.
|
||||
if (auto Err =
|
||||
SerializationTraits<ChannelT, WireRetT,
|
||||
Expected<HandlerRetT>>::serialize(
|
||||
C, std::move(ResultOrErr)))
|
||||
SerializationTraits<ChannelT, WireRetT, Expected<HandlerRetT>>::
|
||||
serialize(C, std::move(ResultOrErr)))
|
||||
return Err;
|
||||
|
||||
// Close the response message.
|
||||
@ -354,14 +352,11 @@ public:
|
||||
return Err2;
|
||||
return C.send();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// RespondHelper specialization for functions that do not support error returns.
|
||||
template <>
|
||||
class RespondHelper<false> {
|
||||
template <> class RespondHelper<false> {
|
||||
public:
|
||||
|
||||
template <typename WireRetT, typename HandlerRetT, typename ChannelT,
|
||||
typename FunctionIdT, typename SequenceNumberT>
|
||||
static Error sendResult(ChannelT &C, const FunctionIdT &ResponseId,
|
||||
@ -376,8 +371,8 @@ public:
|
||||
|
||||
// Serialize the result.
|
||||
if (auto Err =
|
||||
SerializationTraits<ChannelT, WireRetT, HandlerRetT>::serialize(
|
||||
C, *ResultOrErr))
|
||||
SerializationTraits<ChannelT, WireRetT, HandlerRetT>::serialize(
|
||||
C, *ResultOrErr))
|
||||
return Err;
|
||||
|
||||
// End the response message.
|
||||
@ -398,18 +393,17 @@ public:
|
||||
return Err2;
|
||||
return C.send();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
// Send a response of the given wire return type (WireRetT) over the
|
||||
// channel, with the given sequence number.
|
||||
template <typename WireRetT, typename HandlerRetT, typename ChannelT,
|
||||
typename FunctionIdT, typename SequenceNumberT>
|
||||
Error respond(ChannelT &C, const FunctionIdT &ResponseId,
|
||||
SequenceNumberT SeqNo, Expected<HandlerRetT> ResultOrErr) {
|
||||
Error respond(ChannelT &C, const FunctionIdT &ResponseId, SequenceNumberT SeqNo,
|
||||
Expected<HandlerRetT> ResultOrErr) {
|
||||
return RespondHelper<SupportsErrorReturn<WireRetT>::value>::
|
||||
template sendResult<WireRetT>(C, ResponseId, SeqNo, std::move(ResultOrErr));
|
||||
template sendResult<WireRetT>(C, ResponseId, SeqNo,
|
||||
std::move(ResultOrErr));
|
||||
}
|
||||
|
||||
// Send an empty response message on the given channel to indicate that
|
||||
@ -418,8 +412,8 @@ template <typename WireRetT, typename ChannelT, typename FunctionIdT,
|
||||
typename SequenceNumberT>
|
||||
Error respond(ChannelT &C, const FunctionIdT &ResponseId, SequenceNumberT SeqNo,
|
||||
Error Err) {
|
||||
return RespondHelper<SupportsErrorReturn<WireRetT>::value>::
|
||||
sendResult(C, ResponseId, SeqNo, std::move(Err));
|
||||
return RespondHelper<SupportsErrorReturn<WireRetT>::value>::sendResult(
|
||||
C, ResponseId, SeqNo, std::move(Err));
|
||||
}
|
||||
|
||||
// Converts a given type to the equivalent error return type.
|
||||
@ -453,7 +447,8 @@ public:
|
||||
template <typename FnT> class AsyncHandlerTraits;
|
||||
|
||||
template <typename ResultT, typename... ArgTs>
|
||||
class AsyncHandlerTraits<Error(std::function<Error(Expected<ResultT>)>, ArgTs...)> {
|
||||
class AsyncHandlerTraits<Error(std::function<Error(Expected<ResultT>)>,
|
||||
ArgTs...)> {
|
||||
public:
|
||||
using Type = Error(ArgTs...);
|
||||
using ResultType = Expected<ResultT>;
|
||||
@ -490,9 +485,9 @@ class AsyncHandlerTraits<Error(ResponseHandlerT, ArgTs...)>
|
||||
// specialized for function types) and inherits from the appropriate
|
||||
// speciilization for the given non-function type's call operator.
|
||||
template <typename HandlerT>
|
||||
class HandlerTraits : public HandlerTraits<decltype(
|
||||
&std::remove_reference<HandlerT>::type::operator())> {
|
||||
};
|
||||
class HandlerTraits
|
||||
: public HandlerTraits<
|
||||
decltype(&std::remove_reference<HandlerT>::type::operator())> {};
|
||||
|
||||
// Traits for handlers with a given function type.
|
||||
template <typename RetT, typename... ArgTs>
|
||||
@ -524,7 +519,7 @@ public:
|
||||
template <typename HandlerT>
|
||||
static std::enable_if_t<
|
||||
std::is_void<typename HandlerTraits<HandlerT>::ReturnType>::value, Error>
|
||||
run(HandlerT &Handler, ArgTs &&... Args) {
|
||||
run(HandlerT &Handler, ArgTs &&...Args) {
|
||||
Handler(std::move(Args)...);
|
||||
return Error::success();
|
||||
}
|
||||
@ -577,8 +572,8 @@ private:
|
||||
|
||||
// Handler traits for free functions.
|
||||
template <typename RetT, typename... ArgTs>
|
||||
class HandlerTraits<RetT(*)(ArgTs...)>
|
||||
: public HandlerTraits<RetT(ArgTs...)> {};
|
||||
class HandlerTraits<RetT (*)(ArgTs...)> : public HandlerTraits<RetT(ArgTs...)> {
|
||||
};
|
||||
|
||||
// Handler traits for class methods (especially call operators for lambdas).
|
||||
template <typename Class, typename RetT, typename... ArgTs>
|
||||
@ -714,9 +709,8 @@ public:
|
||||
typename HandlerTraits<HandlerT>::Type>::ArgType;
|
||||
HandlerArgType Result((typename HandlerArgType::value_type()));
|
||||
|
||||
if (auto Err =
|
||||
SerializationTraits<ChannelT, Expected<FuncRetT>,
|
||||
HandlerArgType>::deserialize(C, Result))
|
||||
if (auto Err = SerializationTraits<ChannelT, Expected<FuncRetT>,
|
||||
HandlerArgType>::deserialize(C, Result))
|
||||
return Err;
|
||||
if (auto Err = C.endReceiveMessage())
|
||||
return Err;
|
||||
@ -786,7 +780,7 @@ public:
|
||||
using MethodT = RetT (ClassT::*)(ArgTs...);
|
||||
MemberFnWrapper(ClassT &Instance, MethodT Method)
|
||||
: Instance(Instance), Method(Method) {}
|
||||
RetT operator()(ArgTs &&... Args) {
|
||||
RetT operator()(ArgTs &&...Args) {
|
||||
return (Instance.*Method)(std::move(Args)...);
|
||||
}
|
||||
|
||||
@ -804,10 +798,9 @@ public:
|
||||
template <typename ArgT, typename... ArgTs>
|
||||
class ReadArgs<ArgT, ArgTs...> : public ReadArgs<ArgTs...> {
|
||||
public:
|
||||
ReadArgs(ArgT &Arg, ArgTs &... Args)
|
||||
: ReadArgs<ArgTs...>(Args...), Arg(Arg) {}
|
||||
ReadArgs(ArgT &Arg, ArgTs &...Args) : ReadArgs<ArgTs...>(Args...), Arg(Arg) {}
|
||||
|
||||
Error operator()(ArgT &ArgVal, ArgTs &... ArgVals) {
|
||||
Error operator()(ArgT &ArgVal, ArgTs &...ArgVals) {
|
||||
this->Arg = std::move(ArgVal);
|
||||
return ReadArgs<ArgTs...>::operator()(ArgVals...);
|
||||
}
|
||||
@ -872,8 +865,8 @@ public:
|
||||
template <template <class, class> class P, typename T1Sig, typename T2Sig>
|
||||
class RPCArgTypeCheck {
|
||||
public:
|
||||
using T1Tuple = typename FunctionArgsTuple<T1Sig>::Type;
|
||||
using T2Tuple = typename FunctionArgsTuple<T2Sig>::Type;
|
||||
using T1Tuple = typename RPCFunctionArgsTuple<T1Sig>::Type;
|
||||
using T2Tuple = typename RPCFunctionArgsTuple<T2Sig>::Type;
|
||||
|
||||
static_assert(std::tuple_size<T1Tuple>::value >=
|
||||
std::tuple_size<T2Tuple>::value,
|
||||
@ -937,18 +930,18 @@ template <typename ImplT, typename ChannelT, typename FunctionIdT,
|
||||
typename SequenceNumberT>
|
||||
class RPCEndpointBase {
|
||||
protected:
|
||||
class OrcRPCInvalid : public Function<OrcRPCInvalid, void()> {
|
||||
class OrcRPCInvalid : public RPCFunction<OrcRPCInvalid, void()> {
|
||||
public:
|
||||
static const char *getName() { return "__orc_rpc$invalid"; }
|
||||
};
|
||||
|
||||
class OrcRPCResponse : public Function<OrcRPCResponse, void()> {
|
||||
class OrcRPCResponse : public RPCFunction<OrcRPCResponse, void()> {
|
||||
public:
|
||||
static const char *getName() { return "__orc_rpc$response"; }
|
||||
};
|
||||
|
||||
class OrcRPCNegotiate
|
||||
: public Function<OrcRPCNegotiate, FunctionIdT(std::string)> {
|
||||
: public RPCFunction<OrcRPCNegotiate, FunctionIdT(std::string)> {
|
||||
public:
|
||||
static const char *getName() { return "__orc_rpc$negotiate"; }
|
||||
};
|
||||
@ -994,7 +987,6 @@ public:
|
||||
[this](const std::string &Name) { return handleNegotiate(Name); });
|
||||
}
|
||||
|
||||
|
||||
/// Negotiate a function id for Func with the other end of the channel.
|
||||
template <typename Func> Error negotiateFunction(bool Retry = false) {
|
||||
return getRemoteFunctionId<Func>(true, Retry).takeError();
|
||||
@ -1006,7 +998,7 @@ public:
|
||||
/// or an Error (if Func::ReturnType is void). The handler will be called
|
||||
/// with an error if the return value is abandoned due to a channel error.
|
||||
template <typename Func, typename HandlerT, typename... ArgTs>
|
||||
Error appendCallAsync(HandlerT Handler, const ArgTs &... Args) {
|
||||
Error appendCallAsync(HandlerT Handler, const ArgTs &...Args) {
|
||||
|
||||
static_assert(
|
||||
detail::RPCArgTypeCheck<CanSerializeCheck, typename Func::Type,
|
||||
@ -1036,8 +1028,8 @@ public:
|
||||
|
||||
// Install the user handler.
|
||||
PendingResponses[SeqNo] =
|
||||
detail::createResponseHandler<ChannelT, typename Func::ReturnType>(
|
||||
std::move(Handler));
|
||||
detail::createResponseHandler<ChannelT, typename Func::ReturnType>(
|
||||
std::move(Handler));
|
||||
}
|
||||
|
||||
// Open the function call message.
|
||||
@ -1065,7 +1057,7 @@ public:
|
||||
Error sendAppendedCalls() { return C.send(); };
|
||||
|
||||
template <typename Func, typename HandlerT, typename... ArgTs>
|
||||
Error callAsync(HandlerT Handler, const ArgTs &... Args) {
|
||||
Error callAsync(HandlerT Handler, const ArgTs &...Args) {
|
||||
if (auto Err = appendCallAsync<Func>(std::move(Handler), Args...))
|
||||
return Err;
|
||||
return C.send();
|
||||
@ -1104,7 +1096,7 @@ public:
|
||||
/// /* Handle Args */ ;
|
||||
///
|
||||
template <typename... ArgTs>
|
||||
static detail::ReadArgs<ArgTs...> readArgs(ArgTs &... Args) {
|
||||
static detail::ReadArgs<ArgTs...> readArgs(ArgTs &...Args) {
|
||||
return detail::ReadArgs<ArgTs...>(Args...);
|
||||
}
|
||||
|
||||
@ -1128,8 +1120,7 @@ public:
|
||||
|
||||
/// Remove the handler for the given function.
|
||||
/// A handler must currently be registered for this function.
|
||||
template <typename Func>
|
||||
void removeHandler() {
|
||||
template <typename Func> void removeHandler() {
|
||||
auto IdItr = LocalFunctionIds.find(Func::getPrototype());
|
||||
assert(IdItr != LocalFunctionIds.end() &&
|
||||
"Function does not have a registered handler");
|
||||
@ -1140,12 +1131,9 @@ public:
|
||||
}
|
||||
|
||||
/// Clear all handlers.
|
||||
void clearHandlers() {
|
||||
Handlers.clear();
|
||||
}
|
||||
void clearHandlers() { Handlers.clear(); }
|
||||
|
||||
protected:
|
||||
|
||||
FunctionIdT getInvalidFunctionId() const {
|
||||
return FnIdAllocator.getInvalidId();
|
||||
}
|
||||
@ -1168,12 +1156,12 @@ protected:
|
||||
template <typename Func, typename HandlerT>
|
||||
void addAsyncHandlerImpl(HandlerT Handler) {
|
||||
|
||||
static_assert(detail::RPCArgTypeCheck<
|
||||
CanDeserializeCheck, typename Func::Type,
|
||||
typename detail::AsyncHandlerTraits<
|
||||
typename detail::HandlerTraits<HandlerT>::Type
|
||||
>::Type>::value,
|
||||
"");
|
||||
static_assert(
|
||||
detail::RPCArgTypeCheck<
|
||||
CanDeserializeCheck, typename Func::Type,
|
||||
typename detail::AsyncHandlerTraits<
|
||||
typename detail::HandlerTraits<HandlerT>::Type>::Type>::value,
|
||||
"");
|
||||
|
||||
FunctionIdT NewFnId = FnIdAllocator.template allocate<Func>();
|
||||
LocalFunctionIds[Func::getPrototype()] = NewFnId;
|
||||
@ -1197,8 +1185,8 @@ protected:
|
||||
// Unlock the pending results map to prevent recursive lock.
|
||||
Lock.unlock();
|
||||
abandonPendingResponses();
|
||||
return make_error<
|
||||
InvalidSequenceNumberForResponse<SequenceNumberT>>(SeqNo);
|
||||
return make_error<InvalidSequenceNumberForResponse<SequenceNumberT>>(
|
||||
SeqNo);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1241,7 +1229,7 @@ protected:
|
||||
if (DoNegotiate) {
|
||||
auto &Impl = static_cast<ImplT &>(*this);
|
||||
if (auto RemoteIdOrErr =
|
||||
Impl.template callB<OrcRPCNegotiate>(Func::getPrototype())) {
|
||||
Impl.template callB<OrcRPCNegotiate>(Func::getPrototype())) {
|
||||
RemoteFunctionIds[Func::getPrototype()] = *RemoteIdOrErr;
|
||||
if (*RemoteIdOrErr == getInvalidFunctionId())
|
||||
return make_error<CouldNotNegotiate>(Func::getPrototype());
|
||||
@ -1264,9 +1252,8 @@ protected:
|
||||
return [this, Handler](ChannelT &Channel,
|
||||
SequenceNumberT SeqNo) mutable -> Error {
|
||||
// Start by deserializing the arguments.
|
||||
using ArgsTuple =
|
||||
typename detail::FunctionArgsTuple<
|
||||
typename detail::HandlerTraits<HandlerT>::Type>::Type;
|
||||
using ArgsTuple = typename detail::RPCFunctionArgsTuple<
|
||||
typename detail::HandlerTraits<HandlerT>::Type>::Type;
|
||||
auto Args = std::make_shared<ArgsTuple>();
|
||||
|
||||
if (auto Err =
|
||||
@ -1298,9 +1285,9 @@ protected:
|
||||
SequenceNumberT SeqNo) mutable -> Error {
|
||||
// Start by deserializing the arguments.
|
||||
using AHTraits = detail::AsyncHandlerTraits<
|
||||
typename detail::HandlerTraits<HandlerT>::Type>;
|
||||
typename detail::HandlerTraits<HandlerT>::Type>;
|
||||
using ArgsTuple =
|
||||
typename detail::FunctionArgsTuple<typename AHTraits::Type>::Type;
|
||||
typename detail::RPCFunctionArgsTuple<typename AHTraits::Type>::Type;
|
||||
auto Args = std::make_shared<ArgsTuple>();
|
||||
|
||||
if (auto Err =
|
||||
@ -1319,11 +1306,11 @@ protected:
|
||||
|
||||
using HTraits = detail::HandlerTraits<HandlerT>;
|
||||
using FuncReturn = typename Func::ReturnType;
|
||||
auto Responder =
|
||||
[this, SeqNo](typename AHTraits::ResultType RetVal) -> Error {
|
||||
return detail::respond<FuncReturn>(C, ResponseId, SeqNo,
|
||||
std::move(RetVal));
|
||||
};
|
||||
auto Responder = [this,
|
||||
SeqNo](typename AHTraits::ResultType RetVal) -> Error {
|
||||
return detail::respond<FuncReturn>(C, ResponseId, SeqNo,
|
||||
std::move(RetVal));
|
||||
};
|
||||
|
||||
return HTraits::unpackAndRunAsync(Handler, Responder, *Args);
|
||||
};
|
||||
@ -1356,17 +1343,16 @@ class MultiThreadedRPCEndpoint
|
||||
MultiThreadedRPCEndpoint<ChannelT, FunctionIdT, SequenceNumberT>,
|
||||
ChannelT, FunctionIdT, SequenceNumberT> {
|
||||
private:
|
||||
using BaseClass =
|
||||
detail::RPCEndpointBase<
|
||||
MultiThreadedRPCEndpoint<ChannelT, FunctionIdT, SequenceNumberT>,
|
||||
ChannelT, FunctionIdT, SequenceNumberT>;
|
||||
using BaseClass = detail::RPCEndpointBase<
|
||||
MultiThreadedRPCEndpoint<ChannelT, FunctionIdT, SequenceNumberT>,
|
||||
ChannelT, FunctionIdT, SequenceNumberT>;
|
||||
|
||||
public:
|
||||
MultiThreadedRPCEndpoint(ChannelT &C, bool LazyAutoNegotiation)
|
||||
: BaseClass(C, LazyAutoNegotiation) {}
|
||||
|
||||
/// Add a handler for the given RPC function.
|
||||
/// This installs the given handler functor for the given RPC Function, and
|
||||
/// This installs the given handler functor for the given RPCFunction, and
|
||||
/// makes the RPC function available for negotiation/calling from the remote.
|
||||
template <typename Func, typename HandlerT>
|
||||
void addHandler(HandlerT Handler) {
|
||||
@ -1377,7 +1363,7 @@ public:
|
||||
template <typename Func, typename ClassT, typename RetT, typename... ArgTs>
|
||||
void addHandler(ClassT &Object, RetT (ClassT::*Method)(ArgTs...)) {
|
||||
addHandler<Func>(
|
||||
detail::MemberFnWrapper<ClassT, RetT, ArgTs...>(Object, Method));
|
||||
detail::MemberFnWrapper<ClassT, RetT, ArgTs...>(Object, Method));
|
||||
}
|
||||
|
||||
template <typename Func, typename HandlerT>
|
||||
@ -1389,7 +1375,7 @@ public:
|
||||
template <typename Func, typename ClassT, typename RetT, typename... ArgTs>
|
||||
void addAsyncHandler(ClassT &Object, RetT (ClassT::*Method)(ArgTs...)) {
|
||||
addAsyncHandler<Func>(
|
||||
detail::MemberFnWrapper<ClassT, RetT, ArgTs...>(Object, Method));
|
||||
detail::MemberFnWrapper<ClassT, RetT, ArgTs...>(Object, Method));
|
||||
}
|
||||
|
||||
/// Return type for non-blocking call primitives.
|
||||
@ -1405,7 +1391,7 @@ public:
|
||||
/// result. In multi-threaded mode the appendCallNB method, which does not
|
||||
/// return the sequence numeber, should be preferred.
|
||||
template <typename Func, typename... ArgTs>
|
||||
Expected<NonBlockingCallResult<Func>> appendCallNB(const ArgTs &... Args) {
|
||||
Expected<NonBlockingCallResult<Func>> appendCallNB(const ArgTs &...Args) {
|
||||
using RTraits = detail::ResultTraits<typename Func::ReturnType>;
|
||||
using ErrorReturn = typename RTraits::ErrorReturnType;
|
||||
using ErrorReturnPromise = typename RTraits::ReturnPromiseType;
|
||||
@ -1428,7 +1414,7 @@ public:
|
||||
/// The same as appendCallNBWithSeq, except that it calls C.send() to
|
||||
/// flush the channel after serializing the call.
|
||||
template <typename Func, typename... ArgTs>
|
||||
Expected<NonBlockingCallResult<Func>> callNB(const ArgTs &... Args) {
|
||||
Expected<NonBlockingCallResult<Func>> callNB(const ArgTs &...Args) {
|
||||
auto Result = appendCallNB<Func>(Args...);
|
||||
if (!Result)
|
||||
return Result;
|
||||
@ -1449,7 +1435,7 @@ public:
|
||||
template <typename Func, typename... ArgTs,
|
||||
typename AltRetT = typename Func::ReturnType>
|
||||
typename detail::ResultTraits<AltRetT>::ErrorReturnType
|
||||
callB(const ArgTs &... Args) {
|
||||
callB(const ArgTs &...Args) {
|
||||
if (auto FutureResOrErr = callNB<Func>(Args...))
|
||||
return FutureResOrErr->get();
|
||||
else
|
||||
@ -1472,10 +1458,9 @@ class SingleThreadedRPCEndpoint
|
||||
SingleThreadedRPCEndpoint<ChannelT, FunctionIdT, SequenceNumberT>,
|
||||
ChannelT, FunctionIdT, SequenceNumberT> {
|
||||
private:
|
||||
using BaseClass =
|
||||
detail::RPCEndpointBase<
|
||||
SingleThreadedRPCEndpoint<ChannelT, FunctionIdT, SequenceNumberT>,
|
||||
ChannelT, FunctionIdT, SequenceNumberT>;
|
||||
using BaseClass = detail::RPCEndpointBase<
|
||||
SingleThreadedRPCEndpoint<ChannelT, FunctionIdT, SequenceNumberT>,
|
||||
ChannelT, FunctionIdT, SequenceNumberT>;
|
||||
|
||||
public:
|
||||
SingleThreadedRPCEndpoint(ChannelT &C, bool LazyAutoNegotiation)
|
||||
@ -1501,13 +1486,13 @@ public:
|
||||
template <typename Func, typename ClassT, typename RetT, typename... ArgTs>
|
||||
void addAsyncHandler(ClassT &Object, RetT (ClassT::*Method)(ArgTs...)) {
|
||||
addAsyncHandler<Func>(
|
||||
detail::MemberFnWrapper<ClassT, RetT, ArgTs...>(Object, Method));
|
||||
detail::MemberFnWrapper<ClassT, RetT, ArgTs...>(Object, Method));
|
||||
}
|
||||
|
||||
template <typename Func, typename... ArgTs,
|
||||
typename AltRetT = typename Func::ReturnType>
|
||||
typename detail::ResultTraits<AltRetT>::ErrorReturnType
|
||||
callB(const ArgTs &... Args) {
|
||||
callB(const ArgTs &...Args) {
|
||||
bool ReceivedResponse = false;
|
||||
using ResultType = typename detail::ResultTraits<AltRetT>::ErrorReturnType;
|
||||
auto Result = detail::ResultTraits<AltRetT>::createBlankErrorReturnValue();
|
||||
@ -1547,13 +1532,12 @@ public:
|
||||
};
|
||||
|
||||
/// Asynchronous dispatch for a function on an RPC endpoint.
|
||||
template <typename RPCClass, typename Func>
|
||||
class RPCAsyncDispatch {
|
||||
template <typename RPCClass, typename Func> class RPCAsyncDispatch {
|
||||
public:
|
||||
RPCAsyncDispatch(RPCClass &Endpoint) : Endpoint(Endpoint) {}
|
||||
|
||||
template <typename HandlerT, typename... ArgTs>
|
||||
Error operator()(HandlerT Handler, const ArgTs &... Args) const {
|
||||
Error operator()(HandlerT Handler, const ArgTs &...Args) const {
|
||||
return Endpoint.template appendCallAsync<Func>(std::move(Handler), Args...);
|
||||
}
|
||||
|
||||
@ -1571,7 +1555,6 @@ RPCAsyncDispatch<RPCEndpointT, Func> rpcAsyncDispatch(RPCEndpointT &Endpoint) {
|
||||
/// waited on as a group.
|
||||
class ParallelCallGroup {
|
||||
public:
|
||||
|
||||
ParallelCallGroup() = default;
|
||||
ParallelCallGroup(const ParallelCallGroup &) = delete;
|
||||
ParallelCallGroup &operator=(const ParallelCallGroup &) = delete;
|
||||
@ -1579,7 +1562,7 @@ public:
|
||||
/// Make as asynchronous call.
|
||||
template <typename AsyncDispatcher, typename HandlerT, typename... ArgTs>
|
||||
Error call(const AsyncDispatcher &AsyncDispatch, HandlerT Handler,
|
||||
const ArgTs &... Args) {
|
||||
const ArgTs &...Args) {
|
||||
// Increment the count of outstanding calls. This has to happen before
|
||||
// we invoke the call, as the handler may (depending on scheduling)
|
||||
// be run immediately on another thread, and we don't want the decrement
|
||||
@ -1618,70 +1601,57 @@ private:
|
||||
uint32_t NumOutstandingCalls = 0;
|
||||
};
|
||||
|
||||
/// Convenience class for grouping RPC Functions into APIs that can be
|
||||
/// Convenience class for grouping RPCFunctions into APIs that can be
|
||||
/// negotiated as a block.
|
||||
///
|
||||
template <typename... Funcs>
|
||||
class APICalls {
|
||||
template <typename... Funcs> class APICalls {
|
||||
public:
|
||||
|
||||
/// Test whether this API contains Function F.
|
||||
template <typename F>
|
||||
class Contains {
|
||||
template <typename F> class Contains {
|
||||
public:
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
/// Negotiate all functions in this API.
|
||||
template <typename RPCEndpoint>
|
||||
static Error negotiate(RPCEndpoint &R) {
|
||||
template <typename RPCEndpoint> static Error negotiate(RPCEndpoint &R) {
|
||||
return Error::success();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Func, typename... Funcs>
|
||||
class APICalls<Func, Funcs...> {
|
||||
template <typename Func, typename... Funcs> class APICalls<Func, Funcs...> {
|
||||
public:
|
||||
|
||||
template <typename F>
|
||||
class Contains {
|
||||
template <typename F> class Contains {
|
||||
public:
|
||||
static const bool value = std::is_same<F, Func>::value |
|
||||
APICalls<Funcs...>::template Contains<F>::value;
|
||||
};
|
||||
|
||||
template <typename RPCEndpoint>
|
||||
static Error negotiate(RPCEndpoint &R) {
|
||||
template <typename RPCEndpoint> static Error negotiate(RPCEndpoint &R) {
|
||||
if (auto Err = R.template negotiateFunction<Func>())
|
||||
return Err;
|
||||
return APICalls<Funcs...>::negotiate(R);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <typename... InnerFuncs, typename... Funcs>
|
||||
class APICalls<APICalls<InnerFuncs...>, Funcs...> {
|
||||
public:
|
||||
|
||||
template <typename F>
|
||||
class Contains {
|
||||
template <typename F> class Contains {
|
||||
public:
|
||||
static const bool value =
|
||||
APICalls<InnerFuncs...>::template Contains<F>::value |
|
||||
APICalls<Funcs...>::template Contains<F>::value;
|
||||
APICalls<InnerFuncs...>::template Contains<F>::value |
|
||||
APICalls<Funcs...>::template Contains<F>::value;
|
||||
};
|
||||
|
||||
template <typename RPCEndpoint>
|
||||
static Error negotiate(RPCEndpoint &R) {
|
||||
template <typename RPCEndpoint> static Error negotiate(RPCEndpoint &R) {
|
||||
if (auto Err = APICalls<InnerFuncs...>::negotiate(R))
|
||||
return Err;
|
||||
return APICalls<Funcs...>::negotiate(R);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // end namespace rpc
|
||||
} // end namespace shared
|
||||
} // end namespace orc
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_EXECUTIONENGINE_ORC_RPC_RPCUTILS_H
|
||||
#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_RPCUTILS_H
|
@ -1,4 +1,4 @@
|
||||
//===- llvm/ExecutionEngine/Orc/RPC/RawByteChannel.h ----------------*- C++ -*-===//
|
||||
//===- RawByteChannel.h -----------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
@ -6,11 +6,11 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_EXECUTIONENGINE_ORC_RPC_RAWBYTECHANNEL_H
|
||||
#define LLVM_EXECUTIONENGINE_ORC_RPC_RAWBYTECHANNEL_H
|
||||
#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_RAWBYTECHANNEL_H
|
||||
#define LLVM_EXECUTIONENGINE_ORC_SHARED_RAWBYTECHANNEL_H
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RPC/RPCSerialization.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/Serialization.h"
|
||||
#include "llvm/Support/Endian.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include <cstdint>
|
||||
@ -20,9 +20,9 @@
|
||||
|
||||
namespace llvm {
|
||||
namespace orc {
|
||||
namespace rpc {
|
||||
namespace shared {
|
||||
|
||||
/// Interface for byte-streams to be used with RPC.
|
||||
/// Interface for byte-streams to be used with ORC Serialization.
|
||||
class RawByteChannel {
|
||||
public:
|
||||
virtual ~RawByteChannel() = default;
|
||||
@ -115,8 +115,7 @@ class SerializationTraits<
|
||||
public:
|
||||
static Error serialize(ChannelT &C, bool V) {
|
||||
uint8_t Tmp = V ? 1 : 0;
|
||||
if (auto Err =
|
||||
C.appendBytes(reinterpret_cast<const char *>(&Tmp), 1))
|
||||
if (auto Err = C.appendBytes(reinterpret_cast<const char *>(&Tmp), 1))
|
||||
return Err;
|
||||
return Error::success();
|
||||
}
|
||||
@ -135,7 +134,7 @@ class SerializationTraits<
|
||||
ChannelT, std::string, StringRef,
|
||||
std::enable_if_t<std::is_base_of<RawByteChannel, ChannelT>::value>> {
|
||||
public:
|
||||
/// RPC channel serialization for std::strings.
|
||||
/// Serialization channel serialization for std::strings.
|
||||
static Error serialize(RawByteChannel &C, StringRef S) {
|
||||
if (auto Err = serializeSeq(C, static_cast<uint64_t>(S.size())))
|
||||
return Err;
|
||||
@ -161,13 +160,13 @@ class SerializationTraits<
|
||||
ChannelT, std::string, std::string,
|
||||
std::enable_if_t<std::is_base_of<RawByteChannel, ChannelT>::value>> {
|
||||
public:
|
||||
/// RPC channel serialization for std::strings.
|
||||
/// Serialization channel serialization for std::strings.
|
||||
static Error serialize(RawByteChannel &C, const std::string &S) {
|
||||
return SerializationTraits<ChannelT, std::string, StringRef>::serialize(C,
|
||||
S);
|
||||
}
|
||||
|
||||
/// RPC channel deserialization for std::strings.
|
||||
/// Serialization channel deserialization for std::strings.
|
||||
static Error deserialize(RawByteChannel &C, std::string &S) {
|
||||
uint64_t Count = 0;
|
||||
if (auto Err = deserializeSeq(C, Count))
|
||||
@ -177,8 +176,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace rpc
|
||||
} // end namespace shared
|
||||
} // end namespace orc
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_EXECUTIONENGINE_ORC_RPC_RAWBYTECHANNEL_H
|
||||
#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_RAWBYTECHANNEL_H
|
@ -1,4 +1,4 @@
|
||||
//===- llvm/ExecutionEngine/Orc/RPC/RPCSerialization.h --------------*- C++ -*-===//
|
||||
//===- Serialization.h ------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
@ -6,8 +6,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_EXECUTIONENGINE_ORC_RPC_RPCSERIALIZATION_H
|
||||
#define LLVM_EXECUTIONENGINE_ORC_RPC_RPCSERIALIZATION_H
|
||||
#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_SERIALIZATION_H
|
||||
#define LLVM_EXECUTIONENGINE_ORC_SHARED_SERIALIZATION_H
|
||||
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
@ -22,118 +22,104 @@
|
||||
|
||||
namespace llvm {
|
||||
namespace orc {
|
||||
namespace rpc {
|
||||
namespace shared {
|
||||
|
||||
template <typename T>
|
||||
class RPCTypeName;
|
||||
template <typename T> class SerializationTypeName;
|
||||
|
||||
/// TypeNameSequence is a utility for rendering sequences of types to a string
|
||||
/// by rendering each type, separated by ", ".
|
||||
template <typename... ArgTs> class RPCTypeNameSequence {};
|
||||
template <typename... ArgTs> class SerializationTypeNameSequence {};
|
||||
|
||||
/// Render an empty TypeNameSequence to an ostream.
|
||||
template <typename OStream>
|
||||
OStream &operator<<(OStream &OS, const RPCTypeNameSequence<> &V) {
|
||||
OStream &operator<<(OStream &OS, const SerializationTypeNameSequence<> &V) {
|
||||
return OS;
|
||||
}
|
||||
|
||||
/// Render a TypeNameSequence of a single type to an ostream.
|
||||
template <typename OStream, typename ArgT>
|
||||
OStream &operator<<(OStream &OS, const RPCTypeNameSequence<ArgT> &V) {
|
||||
OS << RPCTypeName<ArgT>::getName();
|
||||
OStream &operator<<(OStream &OS, const SerializationTypeNameSequence<ArgT> &V) {
|
||||
OS << SerializationTypeName<ArgT>::getName();
|
||||
return OS;
|
||||
}
|
||||
|
||||
/// Render a TypeNameSequence of more than one type to an ostream.
|
||||
template <typename OStream, typename ArgT1, typename ArgT2, typename... ArgTs>
|
||||
OStream&
|
||||
operator<<(OStream &OS, const RPCTypeNameSequence<ArgT1, ArgT2, ArgTs...> &V) {
|
||||
OS << RPCTypeName<ArgT1>::getName() << ", "
|
||||
<< RPCTypeNameSequence<ArgT2, ArgTs...>();
|
||||
OStream &
|
||||
operator<<(OStream &OS,
|
||||
const SerializationTypeNameSequence<ArgT1, ArgT2, ArgTs...> &V) {
|
||||
OS << SerializationTypeName<ArgT1>::getName() << ", "
|
||||
<< SerializationTypeNameSequence<ArgT2, ArgTs...>();
|
||||
return OS;
|
||||
}
|
||||
|
||||
template <>
|
||||
class RPCTypeName<void> {
|
||||
template <> class SerializationTypeName<void> {
|
||||
public:
|
||||
static const char* getName() { return "void"; }
|
||||
static const char *getName() { return "void"; }
|
||||
};
|
||||
|
||||
template <>
|
||||
class RPCTypeName<int8_t> {
|
||||
template <> class SerializationTypeName<int8_t> {
|
||||
public:
|
||||
static const char* getName() { return "int8_t"; }
|
||||
static const char *getName() { return "int8_t"; }
|
||||
};
|
||||
|
||||
template <>
|
||||
class RPCTypeName<uint8_t> {
|
||||
template <> class SerializationTypeName<uint8_t> {
|
||||
public:
|
||||
static const char* getName() { return "uint8_t"; }
|
||||
static const char *getName() { return "uint8_t"; }
|
||||
};
|
||||
|
||||
template <>
|
||||
class RPCTypeName<int16_t> {
|
||||
template <> class SerializationTypeName<int16_t> {
|
||||
public:
|
||||
static const char* getName() { return "int16_t"; }
|
||||
static const char *getName() { return "int16_t"; }
|
||||
};
|
||||
|
||||
template <>
|
||||
class RPCTypeName<uint16_t> {
|
||||
template <> class SerializationTypeName<uint16_t> {
|
||||
public:
|
||||
static const char* getName() { return "uint16_t"; }
|
||||
static const char *getName() { return "uint16_t"; }
|
||||
};
|
||||
|
||||
template <>
|
||||
class RPCTypeName<int32_t> {
|
||||
template <> class SerializationTypeName<int32_t> {
|
||||
public:
|
||||
static const char* getName() { return "int32_t"; }
|
||||
static const char *getName() { return "int32_t"; }
|
||||
};
|
||||
|
||||
template <>
|
||||
class RPCTypeName<uint32_t> {
|
||||
template <> class SerializationTypeName<uint32_t> {
|
||||
public:
|
||||
static const char* getName() { return "uint32_t"; }
|
||||
static const char *getName() { return "uint32_t"; }
|
||||
};
|
||||
|
||||
template <>
|
||||
class RPCTypeName<int64_t> {
|
||||
template <> class SerializationTypeName<int64_t> {
|
||||
public:
|
||||
static const char* getName() { return "int64_t"; }
|
||||
static const char *getName() { return "int64_t"; }
|
||||
};
|
||||
|
||||
template <>
|
||||
class RPCTypeName<uint64_t> {
|
||||
template <> class SerializationTypeName<uint64_t> {
|
||||
public:
|
||||
static const char* getName() { return "uint64_t"; }
|
||||
static const char *getName() { return "uint64_t"; }
|
||||
};
|
||||
|
||||
template <>
|
||||
class RPCTypeName<bool> {
|
||||
template <> class SerializationTypeName<bool> {
|
||||
public:
|
||||
static const char* getName() { return "bool"; }
|
||||
static const char *getName() { return "bool"; }
|
||||
};
|
||||
|
||||
template <>
|
||||
class RPCTypeName<std::string> {
|
||||
template <> class SerializationTypeName<std::string> {
|
||||
public:
|
||||
static const char* getName() { return "std::string"; }
|
||||
static const char *getName() { return "std::string"; }
|
||||
};
|
||||
|
||||
template <>
|
||||
class RPCTypeName<Error> {
|
||||
template <> class SerializationTypeName<Error> {
|
||||
public:
|
||||
static const char* getName() { return "Error"; }
|
||||
static const char *getName() { return "Error"; }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class RPCTypeName<Expected<T>> {
|
||||
template <typename T> class SerializationTypeName<Expected<T>> {
|
||||
public:
|
||||
static const char* getName() {
|
||||
static const char *getName() {
|
||||
static std::string Name = [] {
|
||||
std::string Name;
|
||||
raw_string_ostream(Name) << "Expected<"
|
||||
<< RPCTypeNameSequence<T>()
|
||||
<< ">";
|
||||
raw_string_ostream(Name)
|
||||
<< "Expected<" << SerializationTypeNameSequence<T>() << ">";
|
||||
return Name;
|
||||
}();
|
||||
return Name.data();
|
||||
@ -141,80 +127,78 @@ public:
|
||||
};
|
||||
|
||||
template <typename T1, typename T2>
|
||||
class RPCTypeName<std::pair<T1, T2>> {
|
||||
public:
|
||||
static const char* getName() {
|
||||
static std::string Name = [] {
|
||||
std::string Name;
|
||||
raw_string_ostream(Name) << "std::pair<" << RPCTypeNameSequence<T1, T2>()
|
||||
<< ">";
|
||||
return Name;
|
||||
}();
|
||||
return Name.data();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... ArgTs>
|
||||
class RPCTypeName<std::tuple<ArgTs...>> {
|
||||
public:
|
||||
static const char* getName() {
|
||||
static std::string Name = [] {
|
||||
std::string Name;
|
||||
raw_string_ostream(Name) << "std::tuple<"
|
||||
<< RPCTypeNameSequence<ArgTs...>() << ">";
|
||||
return Name;
|
||||
}();
|
||||
return Name.data();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> class RPCTypeName<Optional<T>> {
|
||||
class SerializationTypeName<std::pair<T1, T2>> {
|
||||
public:
|
||||
static const char *getName() {
|
||||
static std::string Name = [] {
|
||||
std::string Name;
|
||||
raw_string_ostream(Name)
|
||||
<< "Optional<" << RPCTypeName<T>::getName() << ">";
|
||||
<< "std::pair<" << SerializationTypeNameSequence<T1, T2>() << ">";
|
||||
return Name;
|
||||
}();
|
||||
return Name.data();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class RPCTypeName<std::vector<T>> {
|
||||
public:
|
||||
static const char*getName() {
|
||||
static std::string Name = [] {
|
||||
std::string Name;
|
||||
raw_string_ostream(Name) << "std::vector<" << RPCTypeName<T>::getName()
|
||||
<< ">";
|
||||
return Name;
|
||||
}();
|
||||
return Name.data();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> class RPCTypeName<std::set<T>> {
|
||||
template <typename... ArgTs> class SerializationTypeName<std::tuple<ArgTs...>> {
|
||||
public:
|
||||
static const char *getName() {
|
||||
static std::string Name = [] {
|
||||
std::string Name;
|
||||
raw_string_ostream(Name)
|
||||
<< "std::set<" << RPCTypeName<T>::getName() << ">";
|
||||
<< "std::tuple<" << SerializationTypeNameSequence<ArgTs...>() << ">";
|
||||
return Name;
|
||||
}();
|
||||
return Name.data();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V> class RPCTypeName<std::map<K, V>> {
|
||||
template <typename T> class SerializationTypeName<Optional<T>> {
|
||||
public:
|
||||
static const char *getName() {
|
||||
static std::string Name = [] {
|
||||
std::string Name;
|
||||
raw_string_ostream(Name)
|
||||
<< "std::map<" << RPCTypeNameSequence<K, V>() << ">";
|
||||
<< "Optional<" << SerializationTypeName<T>::getName() << ">";
|
||||
return Name;
|
||||
}();
|
||||
return Name.data();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> class SerializationTypeName<std::vector<T>> {
|
||||
public:
|
||||
static const char *getName() {
|
||||
static std::string Name = [] {
|
||||
std::string Name;
|
||||
raw_string_ostream(Name)
|
||||
<< "std::vector<" << SerializationTypeName<T>::getName() << ">";
|
||||
return Name;
|
||||
}();
|
||||
return Name.data();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> class SerializationTypeName<std::set<T>> {
|
||||
public:
|
||||
static const char *getName() {
|
||||
static std::string Name = [] {
|
||||
std::string Name;
|
||||
raw_string_ostream(Name)
|
||||
<< "std::set<" << SerializationTypeName<T>::getName() << ">";
|
||||
return Name;
|
||||
}();
|
||||
return Name.data();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V> class SerializationTypeName<std::map<K, V>> {
|
||||
public:
|
||||
static const char *getName() {
|
||||
static std::string Name = [] {
|
||||
std::string Name;
|
||||
raw_string_ostream(Name)
|
||||
<< "std::map<" << SerializationTypeNameSequence<K, V>() << ">";
|
||||
return Name;
|
||||
}();
|
||||
return Name.data();
|
||||
@ -257,8 +241,7 @@ template <typename ChannelT, typename WireType,
|
||||
typename ConcreteType = WireType, typename = void>
|
||||
class SerializationTraits;
|
||||
|
||||
template <typename ChannelT>
|
||||
class SequenceTraits {
|
||||
template <typename ChannelT> class SequenceTraits {
|
||||
public:
|
||||
static Error emitSeparator(ChannelT &C) { return Error::success(); }
|
||||
static Error consumeSeparator(ChannelT &C) { return Error::success(); }
|
||||
@ -273,11 +256,9 @@ public:
|
||||
/// is a SerializationTraits specialization
|
||||
/// SerializeTraits<ChannelT, ArgT, CArgT> with methods that can serialize the
|
||||
/// caller argument to over-the-wire value.
|
||||
template <typename ChannelT, typename... ArgTs>
|
||||
class SequenceSerialization;
|
||||
template <typename ChannelT, typename... ArgTs> class SequenceSerialization;
|
||||
|
||||
template <typename ChannelT>
|
||||
class SequenceSerialization<ChannelT> {
|
||||
template <typename ChannelT> class SequenceSerialization<ChannelT> {
|
||||
public:
|
||||
static Error serialize(ChannelT &C) { return Error::success(); }
|
||||
static Error deserialize(ChannelT &C) { return Error::success(); }
|
||||
@ -286,15 +267,12 @@ public:
|
||||
template <typename ChannelT, typename ArgT>
|
||||
class SequenceSerialization<ChannelT, ArgT> {
|
||||
public:
|
||||
|
||||
template <typename CArgT>
|
||||
static Error serialize(ChannelT &C, CArgT &&CArg) {
|
||||
template <typename CArgT> static Error serialize(ChannelT &C, CArgT &&CArg) {
|
||||
return SerializationTraits<ChannelT, ArgT, std::decay_t<CArgT>>::serialize(
|
||||
C, std::forward<CArgT>(CArg));
|
||||
}
|
||||
|
||||
template <typename CArgT>
|
||||
static Error deserialize(ChannelT &C, CArgT &CArg) {
|
||||
template <typename CArgT> static Error deserialize(ChannelT &C, CArgT &CArg) {
|
||||
return SerializationTraits<ChannelT, ArgT, CArgT>::deserialize(C, CArg);
|
||||
}
|
||||
};
|
||||
@ -302,25 +280,22 @@ public:
|
||||
template <typename ChannelT, typename ArgT, typename... ArgTs>
|
||||
class SequenceSerialization<ChannelT, ArgT, ArgTs...> {
|
||||
public:
|
||||
|
||||
template <typename CArgT, typename... CArgTs>
|
||||
static Error serialize(ChannelT &C, CArgT &&CArg,
|
||||
CArgTs &&... CArgs) {
|
||||
static Error serialize(ChannelT &C, CArgT &&CArg, CArgTs &&...CArgs) {
|
||||
if (auto Err =
|
||||
SerializationTraits<ChannelT, ArgT, std::decay_t<CArgT>>::serialize(
|
||||
C, std::forward<CArgT>(CArg)))
|
||||
return Err;
|
||||
if (auto Err = SequenceTraits<ChannelT>::emitSeparator(C))
|
||||
return Err;
|
||||
return SequenceSerialization<ChannelT, ArgTs...>::
|
||||
serialize(C, std::forward<CArgTs>(CArgs)...);
|
||||
return SequenceSerialization<ChannelT, ArgTs...>::serialize(
|
||||
C, std::forward<CArgTs>(CArgs)...);
|
||||
}
|
||||
|
||||
template <typename CArgT, typename... CArgTs>
|
||||
static Error deserialize(ChannelT &C, CArgT &CArg,
|
||||
CArgTs &... CArgs) {
|
||||
static Error deserialize(ChannelT &C, CArgT &CArg, CArgTs &...CArgs) {
|
||||
if (auto Err =
|
||||
SerializationTraits<ChannelT, ArgT, CArgT>::deserialize(C, CArg))
|
||||
SerializationTraits<ChannelT, ArgT, CArgT>::deserialize(C, CArg))
|
||||
return Err;
|
||||
if (auto Err = SequenceTraits<ChannelT>::consumeSeparator(C))
|
||||
return Err;
|
||||
@ -329,25 +304,23 @@ public:
|
||||
};
|
||||
|
||||
template <typename ChannelT, typename... ArgTs>
|
||||
Error serializeSeq(ChannelT &C, ArgTs &&... Args) {
|
||||
Error serializeSeq(ChannelT &C, ArgTs &&...Args) {
|
||||
return SequenceSerialization<ChannelT, std::decay_t<ArgTs>...>::serialize(
|
||||
C, std::forward<ArgTs>(Args)...);
|
||||
}
|
||||
|
||||
template <typename ChannelT, typename... ArgTs>
|
||||
Error deserializeSeq(ChannelT &C, ArgTs &... Args) {
|
||||
Error deserializeSeq(ChannelT &C, ArgTs &...Args) {
|
||||
return SequenceSerialization<ChannelT, ArgTs...>::deserialize(C, Args...);
|
||||
}
|
||||
|
||||
template <typename ChannelT>
|
||||
class SerializationTraits<ChannelT, Error> {
|
||||
template <typename ChannelT> class SerializationTraits<ChannelT, Error> {
|
||||
public:
|
||||
|
||||
using WrappedErrorSerializer =
|
||||
std::function<Error(ChannelT &C, const ErrorInfoBase&)>;
|
||||
std::function<Error(ChannelT &C, const ErrorInfoBase &)>;
|
||||
|
||||
using WrappedErrorDeserializer =
|
||||
std::function<Error(ChannelT &C, Error &Err)>;
|
||||
std::function<Error(ChannelT &C, Error &Err)>;
|
||||
|
||||
template <typename ErrorInfoT, typename SerializeFtor,
|
||||
typename DeserializeFtor>
|
||||
@ -358,15 +331,14 @@ public:
|
||||
|
||||
const std::string *KeyName = nullptr;
|
||||
{
|
||||
// We're abusing the stability of std::map here: We take a reference to the
|
||||
// key of the deserializers map to save us from duplicating the string in
|
||||
// the serializer. This should be changed to use a stringpool if we switch
|
||||
// to a map type that may move keys in memory.
|
||||
// We're abusing the stability of std::map here: We take a reference to
|
||||
// the key of the deserializers map to save us from duplicating the string
|
||||
// in the serializer. This should be changed to use a stringpool if we
|
||||
// switch to a map type that may move keys in memory.
|
||||
std::lock_guard<std::recursive_mutex> Lock(DeserializersMutex);
|
||||
auto I =
|
||||
Deserializers.insert(Deserializers.begin(),
|
||||
std::make_pair(std::move(Name),
|
||||
std::move(Deserialize)));
|
||||
auto I = Deserializers.insert(
|
||||
Deserializers.begin(),
|
||||
std::make_pair(std::move(Name), std::move(Deserialize)));
|
||||
KeyName = &I->first;
|
||||
}
|
||||
|
||||
@ -391,13 +363,12 @@ public:
|
||||
if (!Err)
|
||||
return serializeSeq(C, std::string());
|
||||
|
||||
return handleErrors(std::move(Err),
|
||||
[&C](const ErrorInfoBase &EIB) {
|
||||
auto SI = Serializers.find(EIB.dynamicClassID());
|
||||
if (SI == Serializers.end())
|
||||
return serializeAsStringError(C, EIB);
|
||||
return (SI->second)(C, EIB);
|
||||
});
|
||||
return handleErrors(std::move(Err), [&C](const ErrorInfoBase &EIB) {
|
||||
auto SI = Serializers.find(EIB.dynamicClassID());
|
||||
if (SI == Serializers.end())
|
||||
return serializeAsStringError(C, EIB);
|
||||
return (SI->second)(C, EIB);
|
||||
});
|
||||
}
|
||||
|
||||
static Error deserialize(ChannelT &C, Error &Err) {
|
||||
@ -419,7 +390,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static Error serializeAsStringError(ChannelT &C, const ErrorInfoBase &EIB) {
|
||||
std::string ErrMsg;
|
||||
{
|
||||
@ -432,7 +402,7 @@ private:
|
||||
|
||||
static std::recursive_mutex SerializersMutex;
|
||||
static std::recursive_mutex DeserializersMutex;
|
||||
static std::map<const void*, WrappedErrorSerializer> Serializers;
|
||||
static std::map<const void *, WrappedErrorSerializer> Serializers;
|
||||
static std::map<std::string, WrappedErrorDeserializer> Deserializers;
|
||||
};
|
||||
|
||||
@ -443,14 +413,14 @@ template <typename ChannelT>
|
||||
std::recursive_mutex SerializationTraits<ChannelT, Error>::DeserializersMutex;
|
||||
|
||||
template <typename ChannelT>
|
||||
std::map<const void*,
|
||||
std::map<const void *,
|
||||
typename SerializationTraits<ChannelT, Error>::WrappedErrorSerializer>
|
||||
SerializationTraits<ChannelT, Error>::Serializers;
|
||||
SerializationTraits<ChannelT, Error>::Serializers;
|
||||
|
||||
template <typename ChannelT>
|
||||
std::map<std::string,
|
||||
typename SerializationTraits<ChannelT, Error>::WrappedErrorDeserializer>
|
||||
SerializationTraits<ChannelT, Error>::Deserializers;
|
||||
std::map<std::string, typename SerializationTraits<
|
||||
ChannelT, Error>::WrappedErrorDeserializer>
|
||||
SerializationTraits<ChannelT, Error>::Deserializers;
|
||||
|
||||
/// Registers a serializer and deserializer for the given error type on the
|
||||
/// given channel type.
|
||||
@ -459,32 +429,29 @@ template <typename ChannelT, typename ErrorInfoT, typename SerializeFtor,
|
||||
void registerErrorSerialization(std::string Name, SerializeFtor &&Serialize,
|
||||
DeserializeFtor &&Deserialize) {
|
||||
SerializationTraits<ChannelT, Error>::template registerErrorType<ErrorInfoT>(
|
||||
std::move(Name),
|
||||
std::forward<SerializeFtor>(Serialize),
|
||||
std::forward<DeserializeFtor>(Deserialize));
|
||||
std::move(Name), std::forward<SerializeFtor>(Serialize),
|
||||
std::forward<DeserializeFtor>(Deserialize));
|
||||
}
|
||||
|
||||
/// Registers serialization/deserialization for StringError.
|
||||
template <typename ChannelT>
|
||||
void registerStringError() {
|
||||
template <typename ChannelT> void registerStringError() {
|
||||
static bool AlreadyRegistered = false;
|
||||
if (!AlreadyRegistered) {
|
||||
registerErrorSerialization<ChannelT, StringError>(
|
||||
"StringError",
|
||||
[](ChannelT &C, const StringError &SE) {
|
||||
return serializeSeq(C, SE.getMessage());
|
||||
},
|
||||
[](ChannelT &C, Error &Err) -> Error {
|
||||
ErrorAsOutParameter EAO(&Err);
|
||||
std::string Msg;
|
||||
if (auto E2 = deserializeSeq(C, Msg))
|
||||
return E2;
|
||||
Err =
|
||||
make_error<StringError>(std::move(Msg),
|
||||
orcError(
|
||||
OrcErrorCode::UnknownErrorCodeFromRemote));
|
||||
return Error::success();
|
||||
});
|
||||
"StringError",
|
||||
[](ChannelT &C, const StringError &SE) {
|
||||
return serializeSeq(C, SE.getMessage());
|
||||
},
|
||||
[](ChannelT &C, Error &Err) -> Error {
|
||||
ErrorAsOutParameter EAO(&Err);
|
||||
std::string Msg;
|
||||
if (auto E2 = deserializeSeq(C, Msg))
|
||||
return E2;
|
||||
Err = make_error<StringError>(
|
||||
std::move(Msg),
|
||||
orcError(OrcErrorCode::UnknownErrorCodeFromRemote));
|
||||
return Error::success();
|
||||
});
|
||||
AlreadyRegistered = true;
|
||||
}
|
||||
}
|
||||
@ -493,7 +460,6 @@ void registerStringError() {
|
||||
template <typename ChannelT, typename T1, typename T2>
|
||||
class SerializationTraits<ChannelT, Expected<T1>, Expected<T2>> {
|
||||
public:
|
||||
|
||||
static Error serialize(ChannelT &C, Expected<T2> &&ValOrErr) {
|
||||
if (ValOrErr) {
|
||||
if (auto Err = serializeSeq(C, true))
|
||||
@ -524,7 +490,6 @@ public:
|
||||
template <typename ChannelT, typename T1, typename T2>
|
||||
class SerializationTraits<ChannelT, Expected<T1>, T2> {
|
||||
public:
|
||||
|
||||
static Error serialize(ChannelT &C, T2 &&Val) {
|
||||
return serializeSeq(C, Expected<T2>(std::forward<T2>(Val)));
|
||||
}
|
||||
@ -534,7 +499,6 @@ public:
|
||||
template <typename ChannelT, typename T>
|
||||
class SerializationTraits<ChannelT, Expected<T>, Error> {
|
||||
public:
|
||||
|
||||
static Error serialize(ChannelT &C, Error &&Err) {
|
||||
return serializeSeq(C, Expected<T>(std::move(Err)));
|
||||
}
|
||||
@ -562,7 +526,6 @@ public:
|
||||
template <typename ChannelT, typename... ArgTs>
|
||||
class SerializationTraits<ChannelT, std::tuple<ArgTs...>> {
|
||||
public:
|
||||
|
||||
/// RPC channel serialization for std::tuple.
|
||||
static Error serialize(ChannelT &C, const std::tuple<ArgTs...> &V) {
|
||||
return serializeTupleHelper(C, V, std::index_sequence_for<ArgTs...>());
|
||||
@ -618,7 +581,6 @@ public:
|
||||
template <typename ChannelT, typename T>
|
||||
class SerializationTraits<ChannelT, std::vector<T>> {
|
||||
public:
|
||||
|
||||
/// Serialize a std::vector<T> from std::vector<T>.
|
||||
static Error serialize(ChannelT &C, const std::vector<T> &V) {
|
||||
if (auto Err = serializeSeq(C, static_cast<uint64_t>(V.size())))
|
||||
@ -800,7 +762,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace rpc
|
||||
} // namespace shared
|
||||
} // end namespace orc
|
||||
} // end namespace llvm
|
||||
|
@ -14,8 +14,8 @@
|
||||
#define LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_ORCRPCTPCSERVER_H
|
||||
|
||||
#include "llvm/ADT/BitmaskEnum.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RPC/RPCUtils.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RPC/RawByteChannel.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/RPCUtils.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/RawByteChannel.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcessControl.h"
|
||||
@ -93,49 +93,50 @@ using ReleaseOrFinalizeMemRequest =
|
||||
|
||||
} // end namespace orcrpctpc
|
||||
|
||||
namespace rpc {
|
||||
namespace shared {
|
||||
|
||||
template <> class RPCTypeName<tpctypes::UInt8Write> {
|
||||
template <> class SerializationTypeName<tpctypes::UInt8Write> {
|
||||
public:
|
||||
static const char *getName() { return "UInt8Write"; }
|
||||
};
|
||||
|
||||
template <> class RPCTypeName<tpctypes::UInt16Write> {
|
||||
template <> class SerializationTypeName<tpctypes::UInt16Write> {
|
||||
public:
|
||||
static const char *getName() { return "UInt16Write"; }
|
||||
};
|
||||
|
||||
template <> class RPCTypeName<tpctypes::UInt32Write> {
|
||||
template <> class SerializationTypeName<tpctypes::UInt32Write> {
|
||||
public:
|
||||
static const char *getName() { return "UInt32Write"; }
|
||||
};
|
||||
|
||||
template <> class RPCTypeName<tpctypes::UInt64Write> {
|
||||
template <> class SerializationTypeName<tpctypes::UInt64Write> {
|
||||
public:
|
||||
static const char *getName() { return "UInt64Write"; }
|
||||
};
|
||||
|
||||
template <> class RPCTypeName<tpctypes::BufferWrite> {
|
||||
template <> class SerializationTypeName<tpctypes::BufferWrite> {
|
||||
public:
|
||||
static const char *getName() { return "BufferWrite"; }
|
||||
};
|
||||
|
||||
template <> class RPCTypeName<orcrpctpc::ReserveMemRequestElement> {
|
||||
template <> class SerializationTypeName<orcrpctpc::ReserveMemRequestElement> {
|
||||
public:
|
||||
static const char *getName() { return "ReserveMemRequestElement"; }
|
||||
};
|
||||
|
||||
template <> class RPCTypeName<orcrpctpc::ReserveMemResultElement> {
|
||||
template <> class SerializationTypeName<orcrpctpc::ReserveMemResultElement> {
|
||||
public:
|
||||
static const char *getName() { return "ReserveMemResultElement"; }
|
||||
};
|
||||
|
||||
template <> class RPCTypeName<orcrpctpc::ReleaseOrFinalizeMemRequestElement> {
|
||||
template <>
|
||||
class SerializationTypeName<orcrpctpc::ReleaseOrFinalizeMemRequestElement> {
|
||||
public:
|
||||
static const char *getName() { return "ReleaseOrFinalizeMemRequestElement"; }
|
||||
};
|
||||
|
||||
template <> class RPCTypeName<tpctypes::WrapperFunctionResult> {
|
||||
template <> class SerializationTypeName<tpctypes::WrapperFunctionResult> {
|
||||
public:
|
||||
static const char *getName() { return "WrapperFunctionResult"; }
|
||||
};
|
||||
@ -271,7 +272,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace rpc
|
||||
} // end namespace shared
|
||||
|
||||
namespace orcrpctpc {
|
||||
|
||||
@ -279,100 +280,105 @@ using RemoteSymbolLookupSet = std::vector<std::pair<std::string, bool>>;
|
||||
using RemoteLookupRequest =
|
||||
std::pair<tpctypes::DylibHandle, RemoteSymbolLookupSet>;
|
||||
|
||||
class GetTargetTriple : public rpc::Function<GetTargetTriple, std::string()> {
|
||||
class GetTargetTriple
|
||||
: public shared::RPCFunction<GetTargetTriple, std::string()> {
|
||||
public:
|
||||
static const char *getName() { return "GetTargetTriple"; }
|
||||
};
|
||||
|
||||
class GetPageSize : public rpc::Function<GetPageSize, uint64_t()> {
|
||||
class GetPageSize : public shared::RPCFunction<GetPageSize, uint64_t()> {
|
||||
public:
|
||||
static const char *getName() { return "GetPageSize"; }
|
||||
};
|
||||
|
||||
class ReserveMem : public rpc::Function<ReserveMem, Expected<ReserveMemResult>(
|
||||
ReserveMemRequest)> {
|
||||
class ReserveMem
|
||||
: public shared::RPCFunction<ReserveMem, Expected<ReserveMemResult>(
|
||||
ReserveMemRequest)> {
|
||||
public:
|
||||
static const char *getName() { return "ReserveMem"; }
|
||||
};
|
||||
|
||||
class FinalizeMem
|
||||
: public rpc::Function<FinalizeMem, Error(ReleaseOrFinalizeMemRequest)> {
|
||||
: public shared::RPCFunction<FinalizeMem,
|
||||
Error(ReleaseOrFinalizeMemRequest)> {
|
||||
public:
|
||||
static const char *getName() { return "FinalizeMem"; }
|
||||
};
|
||||
|
||||
class ReleaseMem
|
||||
: public rpc::Function<ReleaseMem, Error(ReleaseOrFinalizeMemRequest)> {
|
||||
: public shared::RPCFunction<ReleaseMem,
|
||||
Error(ReleaseOrFinalizeMemRequest)> {
|
||||
public:
|
||||
static const char *getName() { return "ReleaseMem"; }
|
||||
};
|
||||
|
||||
class WriteUInt8s
|
||||
: public rpc::Function<WriteUInt8s,
|
||||
Error(std::vector<tpctypes::UInt8Write>)> {
|
||||
: public shared::RPCFunction<WriteUInt8s,
|
||||
Error(std::vector<tpctypes::UInt8Write>)> {
|
||||
public:
|
||||
static const char *getName() { return "WriteUInt8s"; }
|
||||
};
|
||||
|
||||
class WriteUInt16s
|
||||
: public rpc::Function<WriteUInt16s,
|
||||
Error(std::vector<tpctypes::UInt16Write>)> {
|
||||
: public shared::RPCFunction<WriteUInt16s,
|
||||
Error(std::vector<tpctypes::UInt16Write>)> {
|
||||
public:
|
||||
static const char *getName() { return "WriteUInt16s"; }
|
||||
};
|
||||
|
||||
class WriteUInt32s
|
||||
: public rpc::Function<WriteUInt32s,
|
||||
Error(std::vector<tpctypes::UInt32Write>)> {
|
||||
: public shared::RPCFunction<WriteUInt32s,
|
||||
Error(std::vector<tpctypes::UInt32Write>)> {
|
||||
public:
|
||||
static const char *getName() { return "WriteUInt32s"; }
|
||||
};
|
||||
|
||||
class WriteUInt64s
|
||||
: public rpc::Function<WriteUInt64s,
|
||||
Error(std::vector<tpctypes::UInt64Write>)> {
|
||||
: public shared::RPCFunction<WriteUInt64s,
|
||||
Error(std::vector<tpctypes::UInt64Write>)> {
|
||||
public:
|
||||
static const char *getName() { return "WriteUInt64s"; }
|
||||
};
|
||||
|
||||
class WriteBuffers
|
||||
: public rpc::Function<WriteBuffers,
|
||||
Error(std::vector<tpctypes::BufferWrite>)> {
|
||||
: public shared::RPCFunction<WriteBuffers,
|
||||
Error(std::vector<tpctypes::BufferWrite>)> {
|
||||
public:
|
||||
static const char *getName() { return "WriteBuffers"; }
|
||||
};
|
||||
|
||||
class LoadDylib
|
||||
: public rpc::Function<LoadDylib, Expected<tpctypes::DylibHandle>(
|
||||
std::string DylibPath)> {
|
||||
: public shared::RPCFunction<LoadDylib, Expected<tpctypes::DylibHandle>(
|
||||
std::string DylibPath)> {
|
||||
public:
|
||||
static const char *getName() { return "LoadDylib"; }
|
||||
};
|
||||
|
||||
class LookupSymbols
|
||||
: public rpc::Function<LookupSymbols,
|
||||
Expected<std::vector<tpctypes::LookupResult>>(
|
||||
std::vector<RemoteLookupRequest>)> {
|
||||
: public shared::RPCFunction<LookupSymbols,
|
||||
Expected<std::vector<tpctypes::LookupResult>>(
|
||||
std::vector<RemoteLookupRequest>)> {
|
||||
public:
|
||||
static const char *getName() { return "LookupSymbols"; }
|
||||
};
|
||||
|
||||
class RunMain
|
||||
: public rpc::Function<RunMain, int32_t(JITTargetAddress MainAddr,
|
||||
std::vector<std::string> Args)> {
|
||||
: public shared::RPCFunction<RunMain,
|
||||
int32_t(JITTargetAddress MainAddr,
|
||||
std::vector<std::string> Args)> {
|
||||
public:
|
||||
static const char *getName() { return "RunMain"; }
|
||||
};
|
||||
|
||||
class RunWrapper
|
||||
: public rpc::Function<RunWrapper,
|
||||
tpctypes::WrapperFunctionResult(
|
||||
JITTargetAddress, std::vector<uint8_t>)> {
|
||||
: public shared::RPCFunction<RunWrapper,
|
||||
tpctypes::WrapperFunctionResult(
|
||||
JITTargetAddress, std::vector<uint8_t>)> {
|
||||
public:
|
||||
static const char *getName() { return "RunWrapper"; }
|
||||
};
|
||||
|
||||
class CloseConnection : public rpc::Function<CloseConnection, void()> {
|
||||
class CloseConnection : public shared::RPCFunction<CloseConnection, void()> {
|
||||
public:
|
||||
static const char *getName() { return "CloseConnection"; }
|
||||
};
|
||||
|
@ -10,21 +10,21 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ExecutionEngine/Orc/RPC/RPCUtils.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/RPCUtils.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
|
||||
char llvm::orc::rpc::RPCFatalError::ID = 0;
|
||||
char llvm::orc::rpc::ConnectionClosed::ID = 0;
|
||||
char llvm::orc::rpc::ResponseAbandoned::ID = 0;
|
||||
char llvm::orc::rpc::CouldNotNegotiate::ID = 0;
|
||||
char llvm::orc::shared::RPCFatalError::ID = 0;
|
||||
char llvm::orc::shared::ConnectionClosed::ID = 0;
|
||||
char llvm::orc::shared::ResponseAbandoned::ID = 0;
|
||||
char llvm::orc::shared::CouldNotNegotiate::ID = 0;
|
||||
|
||||
namespace llvm {
|
||||
namespace orc {
|
||||
namespace rpc {
|
||||
namespace shared {
|
||||
|
||||
std::error_code ConnectionClosed::convertToErrorCode() const {
|
||||
return orcError(OrcErrorCode::RPCConnectionClosed);
|
||||
@ -53,6 +53,6 @@ void CouldNotNegotiate::log(raw_ostream &OS) const {
|
||||
OS << "Could not negotiate RPC function " << Signature;
|
||||
}
|
||||
|
||||
} // end namespace rpc
|
||||
} // end namespace shared
|
||||
} // end namespace orc
|
||||
} // end namespace llvm
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "llvm/ExecutionEngine/Orc/OrcABISupport.h"
|
||||
#include "llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RPC/FDRawByteChannel.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/FDRawByteChannel.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/DynamicLibrary.h"
|
||||
#include "llvm/Support/Process.h"
|
||||
@ -54,8 +54,8 @@ int main(int argc, char *argv[]) {
|
||||
RTDyldMemoryManager::deregisterEHFramesInProcess(Addr, Size);
|
||||
};
|
||||
|
||||
rpc::FDRawByteChannel Channel(InFD, OutFD);
|
||||
typedef remote::OrcRemoteTargetServer<rpc::FDRawByteChannel, HostOrcArch>
|
||||
shared::FDRawByteChannel Channel(InFD, OutFD);
|
||||
typedef remote::OrcRemoteTargetServer<shared::FDRawByteChannel, HostOrcArch>
|
||||
JITServer;
|
||||
JITServer Server(Channel, SymbolLookup, RegisterEHFrames, DeregisterEHFrames);
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
#ifndef LLVM_TOOLS_LLI_REMOTEJITUTILS_H
|
||||
#define LLVM_TOOLS_LLI_REMOTEJITUTILS_H
|
||||
|
||||
#include "llvm/ExecutionEngine/Orc/RPC/FDRawByteChannel.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/FDRawByteChannel.h"
|
||||
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
|
||||
#include <mutex>
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
#endif
|
||||
|
||||
// launch the remote process (see lli.cpp) and return a channel to it.
|
||||
std::unique_ptr<llvm::orc::rpc::FDRawByteChannel> launchRemote();
|
||||
std::unique_ptr<llvm::orc::shared::FDRawByteChannel> launchRemote();
|
||||
|
||||
namespace llvm {
|
||||
|
||||
|
@ -670,7 +670,7 @@ int main(int argc, char **argv, char * const *envp) {
|
||||
// MCJIT itself. FIXME.
|
||||
|
||||
// Lanch the remote process and get a channel to it.
|
||||
std::unique_ptr<orc::rpc::FDRawByteChannel> C = launchRemote();
|
||||
std::unique_ptr<orc::shared::FDRawByteChannel> C = launchRemote();
|
||||
if (!C) {
|
||||
WithColor::error(errs(), argv[0]) << "failed to launch remote JIT.\n";
|
||||
exit(1);
|
||||
@ -1015,7 +1015,7 @@ void disallowOrcOptions() {
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<orc::rpc::FDRawByteChannel> launchRemote() {
|
||||
std::unique_ptr<orc::shared::FDRawByteChannel> launchRemote() {
|
||||
#ifndef LLVM_ON_UNIX
|
||||
llvm_unreachable("launchRemote not supported on non-Unix platforms");
|
||||
#else
|
||||
@ -1065,7 +1065,7 @@ std::unique_ptr<orc::rpc::FDRawByteChannel> launchRemote() {
|
||||
close(PipeFD[1][1]);
|
||||
|
||||
// Return an RPC channel connected to our end of the pipes.
|
||||
return std::make_unique<orc::rpc::FDRawByteChannel>(PipeFD[1][0],
|
||||
PipeFD[0][1]);
|
||||
return std::make_unique<orc::shared::FDRawByteChannel>(PipeFD[1][0],
|
||||
PipeFD[0][1]);
|
||||
#endif
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RPC/FDRawByteChannel.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/FDRawByteChannel.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcess/OrcRPCTPCServer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h"
|
||||
#include "llvm/Support/DynamicLibrary.h"
|
||||
@ -113,11 +113,11 @@ int main(int argc, char *argv[]) {
|
||||
ExitOnErr.setBanner(std::string(argv[0]) + ":");
|
||||
|
||||
using JITLinkExecutorEndpoint =
|
||||
rpc::MultiThreadedRPCEndpoint<rpc::FDRawByteChannel>;
|
||||
shared::MultiThreadedRPCEndpoint<shared::FDRawByteChannel>;
|
||||
|
||||
rpc::registerStringError<rpc::FDRawByteChannel>();
|
||||
shared::registerStringError<shared::FDRawByteChannel>();
|
||||
|
||||
rpc::FDRawByteChannel C(InFD, OutFD);
|
||||
shared::FDRawByteChannel C(InFD, OutFD);
|
||||
JITLinkExecutorEndpoint EP(C, true);
|
||||
OrcRPCTPCServer<JITLinkExecutorEndpoint> Server(EP);
|
||||
Server.setProgramName(std::string("llvm-jitlink-executor"));
|
||||
|
@ -585,7 +585,7 @@ LLVMJITLinkRemoteTargetProcessControl::LaunchExecutor() {
|
||||
inconvertibleErrorCode());
|
||||
#else
|
||||
|
||||
rpc::registerStringError<LLVMJITLinkChannel>();
|
||||
shared::registerStringError<LLVMJITLinkChannel>();
|
||||
|
||||
constexpr int ReadEnd = 0;
|
||||
constexpr int WriteEnd = 1;
|
||||
@ -640,8 +640,8 @@ LLVMJITLinkRemoteTargetProcessControl::LaunchExecutor() {
|
||||
|
||||
// Return an RPC channel connected to our end of the pipes.
|
||||
auto SSP = std::make_shared<SymbolStringPool>();
|
||||
auto Channel = std::make_unique<rpc::FDRawByteChannel>(FromExecutor[ReadEnd],
|
||||
ToExecutor[WriteEnd]);
|
||||
auto Channel = std::make_unique<shared::FDRawByteChannel>(
|
||||
FromExecutor[ReadEnd], ToExecutor[WriteEnd]);
|
||||
auto Endpoint = std::make_unique<LLVMJITLinkRPCEndpoint>(*Channel, true);
|
||||
|
||||
auto ReportError = [](Error Err) {
|
||||
@ -668,7 +668,7 @@ LLVMJITLinkRemoteTargetProcessControl::ConnectToExecutor() {
|
||||
inconvertibleErrorCode());
|
||||
#else
|
||||
|
||||
rpc::registerStringError<LLVMJITLinkChannel>();
|
||||
shared::registerStringError<LLVMJITLinkChannel>();
|
||||
|
||||
StringRef HostNameStr, PortStr;
|
||||
std::tie(HostNameStr, PortStr) =
|
||||
@ -705,7 +705,7 @@ LLVMJITLinkRemoteTargetProcessControl::ConnectToExecutor() {
|
||||
inconvertibleErrorCode());
|
||||
|
||||
auto SSP = std::make_shared<SymbolStringPool>();
|
||||
auto Channel = std::make_unique<rpc::FDRawByteChannel>(SockFD, SockFD);
|
||||
auto Channel = std::make_unique<shared::FDRawByteChannel>(SockFD, SockFD);
|
||||
auto Endpoint = std::make_unique<LLVMJITLinkRPCEndpoint>(*Channel, true);
|
||||
|
||||
auto ReportError = [](Error Err) {
|
||||
|
@ -19,8 +19,8 @@
|
||||
#include "llvm/ExecutionEngine/Orc/Core.h"
|
||||
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/OrcRPCTargetProcessControl.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RPC/FDRawByteChannel.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RPC/RPCUtils.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/FDRawByteChannel.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/RPCUtils.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcessControl.h"
|
||||
#include "llvm/ExecutionEngine/RuntimeDyldChecker.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
@ -48,9 +48,9 @@ private:
|
||||
Session &S;
|
||||
};
|
||||
|
||||
using LLVMJITLinkChannel = orc::rpc::FDRawByteChannel;
|
||||
using LLVMJITLinkChannel = orc::shared::FDRawByteChannel;
|
||||
using LLVMJITLinkRPCEndpoint =
|
||||
orc::rpc::MultiThreadedRPCEndpoint<LLVMJITLinkChannel>;
|
||||
orc::shared::MultiThreadedRPCEndpoint<LLVMJITLinkChannel>;
|
||||
using LLVMJITLinkRemoteMemoryManager =
|
||||
orc::OrcRPCTPCJITLinkMemoryManager<LLVMJITLinkRPCEndpoint>;
|
||||
using LLVMJITLinkRemoteMemoryAccess =
|
||||
|
@ -9,7 +9,7 @@
|
||||
#ifndef LLVM_UNITTESTS_EXECUTIONENGINE_ORC_QUEUECHANNEL_H
|
||||
#define LLVM_UNITTESTS_EXECUTIONENGINE_ORC_QUEUECHANNEL_H
|
||||
|
||||
#include "llvm/ExecutionEngine/Orc/RPC/RawByteChannel.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/RawByteChannel.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
|
||||
#include <atomic>
|
||||
@ -70,7 +70,7 @@ private:
|
||||
std::function<Error()> ReadError, WriteError;
|
||||
};
|
||||
|
||||
class QueueChannel : public orc::rpc::RawByteChannel {
|
||||
class QueueChannel : public orc::shared::RawByteChannel {
|
||||
public:
|
||||
QueueChannel(std::shared_ptr<Queue> InQueue,
|
||||
std::shared_ptr<Queue> OutQueue)
|
||||
@ -84,25 +84,25 @@ public:
|
||||
template <typename FunctionIdT, typename SequenceIdT>
|
||||
Error startSendMessage(const FunctionIdT &FnId, const SequenceIdT &SeqNo) {
|
||||
++InFlightOutgoingMessages;
|
||||
return orc::rpc::RawByteChannel::startSendMessage(FnId, SeqNo);
|
||||
return orc::shared::RawByteChannel::startSendMessage(FnId, SeqNo);
|
||||
}
|
||||
|
||||
Error endSendMessage() {
|
||||
--InFlightOutgoingMessages;
|
||||
++CompletedOutgoingMessages;
|
||||
return orc::rpc::RawByteChannel::endSendMessage();
|
||||
return orc::shared::RawByteChannel::endSendMessage();
|
||||
}
|
||||
|
||||
template <typename FunctionIdT, typename SequenceNumberT>
|
||||
Error startReceiveMessage(FunctionIdT &FnId, SequenceNumberT &SeqNo) {
|
||||
++InFlightIncomingMessages;
|
||||
return orc::rpc::RawByteChannel::startReceiveMessage(FnId, SeqNo);
|
||||
return orc::shared::RawByteChannel::startReceiveMessage(FnId, SeqNo);
|
||||
}
|
||||
|
||||
Error endReceiveMessage() {
|
||||
--InFlightIncomingMessages;
|
||||
++CompletedIncomingMessages;
|
||||
return orc::rpc::RawByteChannel::endReceiveMessage();
|
||||
return orc::shared::RawByteChannel::endReceiveMessage();
|
||||
}
|
||||
|
||||
Error readBytes(char *Dst, unsigned Size) override {
|
||||
|
@ -6,7 +6,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ExecutionEngine/Orc/RPC/RPCUtils.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/RPCUtils.h"
|
||||
#include "QueueChannel.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@ -14,19 +14,18 @@
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::orc;
|
||||
using namespace llvm::orc::rpc;
|
||||
using namespace llvm::orc::shared;
|
||||
|
||||
class RPCFoo {};
|
||||
|
||||
namespace llvm {
|
||||
namespace orc {
|
||||
namespace rpc {
|
||||
namespace shared {
|
||||
|
||||
template <>
|
||||
class RPCTypeName<RPCFoo> {
|
||||
public:
|
||||
static const char* getName() { return "RPCFoo"; }
|
||||
};
|
||||
template <> class SerializationTypeName<RPCFoo> {
|
||||
public:
|
||||
static const char *getName() { return "RPCFoo"; }
|
||||
};
|
||||
|
||||
template <>
|
||||
class SerializationTraits<QueueChannel, RPCFoo, RPCFoo> {
|
||||
@ -40,7 +39,7 @@ namespace rpc {
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace rpc
|
||||
} // namespace shared
|
||||
} // end namespace orc
|
||||
} // end namespace llvm
|
||||
|
||||
@ -96,65 +95,64 @@ void registerDummyErrorSerialization() {
|
||||
|
||||
namespace llvm {
|
||||
namespace orc {
|
||||
namespace rpc {
|
||||
namespace shared {
|
||||
|
||||
template <>
|
||||
class SerializationTraits<QueueChannel, RPCFoo, RPCBar> {
|
||||
public:
|
||||
static Error serialize(QueueChannel&, const RPCBar&) {
|
||||
return Error::success();
|
||||
}
|
||||
template <> class SerializationTraits<QueueChannel, RPCFoo, RPCBar> {
|
||||
public:
|
||||
static Error serialize(QueueChannel &, const RPCBar &) {
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
static Error deserialize(QueueChannel&, RPCBar&) {
|
||||
return Error::success();
|
||||
}
|
||||
static Error deserialize(QueueChannel &, RPCBar &) {
|
||||
return Error::success();
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace rpc
|
||||
} // end namespace shared
|
||||
} // end namespace orc
|
||||
} // end namespace llvm
|
||||
|
||||
namespace DummyRPCAPI {
|
||||
|
||||
class VoidBool : public Function<VoidBool, void(bool)> {
|
||||
public:
|
||||
static const char* getName() { return "VoidBool"; }
|
||||
};
|
||||
class VoidBool : public RPCFunction<VoidBool, void(bool)> {
|
||||
public:
|
||||
static const char *getName() { return "VoidBool"; }
|
||||
};
|
||||
|
||||
class IntInt : public Function<IntInt, int32_t(int32_t)> {
|
||||
public:
|
||||
static const char* getName() { return "IntInt"; }
|
||||
};
|
||||
class IntInt : public RPCFunction<IntInt, int32_t(int32_t)> {
|
||||
public:
|
||||
static const char *getName() { return "IntInt"; }
|
||||
};
|
||||
|
||||
class VoidString : public Function<VoidString, void(std::string)> {
|
||||
public:
|
||||
static const char* getName() { return "VoidString"; }
|
||||
};
|
||||
class VoidString : public RPCFunction<VoidString, void(std::string)> {
|
||||
public:
|
||||
static const char *getName() { return "VoidString"; }
|
||||
};
|
||||
|
||||
class AllTheTypes
|
||||
: public Function<AllTheTypes, void(int8_t, uint8_t, int16_t, uint16_t,
|
||||
int32_t, uint32_t, int64_t, uint64_t,
|
||||
bool, std::string, std::vector<int>,
|
||||
std::set<int>, std::map<int, bool>)> {
|
||||
public:
|
||||
static const char* getName() { return "AllTheTypes"; }
|
||||
};
|
||||
class AllTheTypes
|
||||
: public RPCFunction<AllTheTypes,
|
||||
void(int8_t, uint8_t, int16_t, uint16_t, int32_t,
|
||||
uint32_t, int64_t, uint64_t, bool, std::string,
|
||||
std::vector<int>, std::set<int>,
|
||||
std::map<int, bool>)> {
|
||||
public:
|
||||
static const char *getName() { return "AllTheTypes"; }
|
||||
};
|
||||
|
||||
class CustomType : public Function<CustomType, RPCFoo(RPCFoo)> {
|
||||
public:
|
||||
static const char* getName() { return "CustomType"; }
|
||||
};
|
||||
class CustomType : public RPCFunction<CustomType, RPCFoo(RPCFoo)> {
|
||||
public:
|
||||
static const char *getName() { return "CustomType"; }
|
||||
};
|
||||
|
||||
class ErrorFunc : public Function<ErrorFunc, Error()> {
|
||||
public:
|
||||
static const char* getName() { return "ErrorFunc"; }
|
||||
};
|
||||
|
||||
class ExpectedFunc : public Function<ExpectedFunc, Expected<uint32_t>()> {
|
||||
public:
|
||||
static const char* getName() { return "ExpectedFunc"; }
|
||||
};
|
||||
class ErrorFunc : public RPCFunction<ErrorFunc, Error()> {
|
||||
public:
|
||||
static const char *getName() { return "ErrorFunc"; }
|
||||
};
|
||||
|
||||
class ExpectedFunc : public RPCFunction<ExpectedFunc, Expected<uint32_t>()> {
|
||||
public:
|
||||
static const char *getName() { return "ExpectedFunc"; }
|
||||
};
|
||||
}
|
||||
|
||||
class DummyRPCEndpoint : public SingleThreadedRPCEndpoint<QueueChannel> {
|
||||
|
Loading…
Reference in New Issue
Block a user