From e98bc7af8bb4eb8cf45413bf2826b1dbd8c9c57d Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Sun, 11 Sep 2016 18:41:05 +0000 Subject: [ORC] Rename RPCChannel to RPCByteChannel. NFC. llvm-svn: 281171 --- .../ExecutionEngine/Orc/OrcRemoteTargetClient.h | 12 +- .../ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h | 8 +- .../ExecutionEngine/Orc/OrcRemoteTargetServer.h | 2 +- .../llvm/ExecutionEngine/Orc/RPCByteChannel.h | 250 +++++++++++++++++++++ llvm/include/llvm/ExecutionEngine/Orc/RPCChannel.h | 249 -------------------- llvm/tools/lli/RemoteJITUtils.h | 4 +- llvm/tools/lli/lli.cpp | 3 +- 7 files changed, 265 insertions(+), 263 deletions(-) create mode 100644 llvm/include/llvm/ExecutionEngine/Orc/RPCByteChannel.h delete mode 100644 llvm/include/llvm/ExecutionEngine/Orc/RPCChannel.h (limited to 'llvm') diff --git a/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h b/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h index 42b5b507e98..a922d862976 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h @@ -8,8 +8,8 @@ //===----------------------------------------------------------------------===// // // This file defines the OrcRemoteTargetClient class and helpers. This class -// can be used to communicate over an RPCChannel with an OrcRemoteTargetServer -// instance to support remote-JITing. +// can be used to communicate over an RPCByteChannel with an +// OrcRemoteTargetServer instance to support remote-JITing. // //===----------------------------------------------------------------------===// @@ -601,7 +601,7 @@ public: Expected callIntVoid(JITTargetAddress Addr) { DEBUG(dbgs() << "Calling int(*)(void) " << format("0x%016x", Addr) << "\n"); - auto Listen = [&](RPCChannel &C, uint32_t Id) { + auto Listen = [&](RPCByteChannel &C, uint32_t Id) { return listenForCompileRequests(C, Id); }; return callSTHandling(Channel, Listen, Addr); @@ -614,7 +614,7 @@ public: DEBUG(dbgs() << "Calling int(*)(int, char*[]) " << format("0x%016x", Addr) << "\n"); - auto Listen = [&](RPCChannel &C, uint32_t Id) { + auto Listen = [&](RPCByteChannel &C, uint32_t Id) { return listenForCompileRequests(C, Id); }; return callSTHandling(Channel, Listen, Addr, Args); @@ -626,7 +626,7 @@ public: DEBUG(dbgs() << "Calling void(*)(void) " << format("0x%016x", Addr) << "\n"); - auto Listen = [&](RPCChannel &C, uint32_t Id) { + auto Listen = [&](RPCByteChannel &C, uint32_t Id) { return listenForCompileRequests(C, Id); }; return callSTHandling(Channel, Listen, Addr); @@ -736,7 +736,7 @@ private: uint32_t getTrampolineSize() const { return RemoteTrampolineSize; } - Error listenForCompileRequests(RPCChannel &C, uint32_t &Id) { + Error listenForCompileRequests(RPCByteChannel &C, uint32_t &Id) { assert(CallbackManager && "No calback manager. enableCompileCallbacks must be called first"); diff --git a/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h b/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h index e951c124b15..2b3caf06067 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h @@ -16,7 +16,7 @@ #ifndef LLVM_EXECUTIONENGINE_ORC_ORCREMOTETARGETRPCAPI_H #define LLVM_EXECUTIONENGINE_ORC_ORCREMOTETARGETRPCAPI_H -#include "RPCChannel.h" +#include "RPCByteChannel.h" #include "RPCUtils.h" #include "llvm/ExecutionEngine/JITSymbol.h" @@ -40,7 +40,7 @@ private: uint64_t Size; }; -inline Error serialize(RPCChannel &C, const DirectBufferWriter &DBW) { +inline Error serialize(RPCByteChannel &C, const DirectBufferWriter &DBW) { if (auto EC = serialize(C, DBW.getDst())) return EC; if (auto EC = serialize(C, DBW.getSize())) @@ -48,7 +48,7 @@ inline Error serialize(RPCChannel &C, const DirectBufferWriter &DBW) { return C.appendBytes(DBW.getSrc(), DBW.getSize()); } -inline Error deserialize(RPCChannel &C, DirectBufferWriter &DBW) { +inline Error deserialize(RPCByteChannel &C, DirectBufferWriter &DBW) { JITTargetAddress Dst; if (auto EC = deserialize(C, Dst)) return EC; @@ -62,7 +62,7 @@ inline Error deserialize(RPCChannel &C, DirectBufferWriter &DBW) { return C.readBytes(Addr, Size); } -class OrcRemoteTargetRPCAPI : public RPC { +class OrcRemoteTargetRPCAPI : public RPC { protected: class ResourceIdMgr { public: diff --git a/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h b/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h index 48e58f6bbfd..e3dfaf77566 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h @@ -119,7 +119,7 @@ public: } Expected requestCompile(JITTargetAddress TrampolineAddr) { - auto Listen = [&](RPCChannel &C, uint32_t Id) { + auto Listen = [&](RPCByteChannel &C, uint32_t Id) { return handleKnownFunction(static_cast(Id)); }; diff --git a/llvm/include/llvm/ExecutionEngine/Orc/RPCByteChannel.h b/llvm/include/llvm/ExecutionEngine/Orc/RPCByteChannel.h new file mode 100644 index 00000000000..1069cb91d36 --- /dev/null +++ b/llvm/include/llvm/ExecutionEngine/Orc/RPCByteChannel.h @@ -0,0 +1,250 @@ +//===- llvm/ExecutionEngine/Orc/RPCByteChannel.h ----------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_EXECUTIONENGINE_ORC_RPCBYTECHANNEL_H +#define LLVM_EXECUTIONENGINE_ORC_RPCBYTECHANNEL_H + +#include "OrcError.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" +#include +#include +#include +#include +#include +#include + +namespace llvm { +namespace orc { +namespace remote { + +/// Interface for byte-streams to be used with RPC. +class RPCByteChannel { +public: + virtual ~RPCByteChannel() {} + + /// Read Size bytes from the stream into *Dst. + virtual Error readBytes(char *Dst, unsigned Size) = 0; + + /// Read size bytes from *Src and append them to the stream. + virtual Error appendBytes(const char *Src, unsigned Size) = 0; + + /// Flush the stream if possible. + virtual Error send() = 0; + + /// Get the lock for stream reading. + std::mutex &getReadLock() { return readLock; } + + /// Get the lock for stream writing. + std::mutex &getWriteLock() { return writeLock; } + +private: + std::mutex readLock, writeLock; +}; + +/// Notify the channel that we're starting a message send. +/// Locks the channel for writing. +inline Error startSendMessage(RPCByteChannel &C) { + C.getWriteLock().lock(); + return Error::success(); +} + +/// Notify the channel that we're ending a message send. +/// Unlocks the channel for writing. +inline Error endSendMessage(RPCByteChannel &C) { + C.getWriteLock().unlock(); + return Error::success(); +} + +/// Notify the channel that we're starting a message receive. +/// Locks the channel for reading. +inline Error startReceiveMessage(RPCByteChannel &C) { + C.getReadLock().lock(); + return Error::success(); +} + +/// Notify the channel that we're ending a message receive. +/// Unlocks the channel for reading. +inline Error endReceiveMessage(RPCByteChannel &C) { + C.getReadLock().unlock(); + return Error::success(); +} + +/// RPC channel serialization for a variadic list of arguments. +template +Error serializeSeq(RPCByteChannel &C, const T &Arg, const Ts &... Args) { + if (auto Err = serialize(C, Arg)) + return Err; + return serializeSeq(C, Args...); +} + +/// RPC channel serialization for an (empty) variadic list of arguments. +inline Error serializeSeq(RPCByteChannel &C) { return Error::success(); } + +/// RPC channel deserialization for a variadic list of arguments. +template +Error deserializeSeq(RPCByteChannel &C, T &Arg, Ts &... Args) { + if (auto Err = deserialize(C, Arg)) + return Err; + return deserializeSeq(C, Args...); +} + +/// RPC channel serialization for an (empty) variadic list of arguments. +inline Error deserializeSeq(RPCByteChannel &C) { return Error::success(); } + +/// RPC channel serialization for integer primitives. +template +typename std::enable_if< + std::is_same::value || std::is_same::value || + std::is_same::value || std::is_same::value || + std::is_same::value || std::is_same::value || + std::is_same::value || std::is_same::value, + Error>::type +serialize(RPCByteChannel &C, T V) { + support::endian::byte_swap(V); + return C.appendBytes(reinterpret_cast(&V), sizeof(T)); +} + +/// RPC channel deserialization for integer primitives. +template +typename std::enable_if< + std::is_same::value || std::is_same::value || + std::is_same::value || std::is_same::value || + std::is_same::value || std::is_same::value || + std::is_same::value || std::is_same::value, + Error>::type +deserialize(RPCByteChannel &C, T &V) { + if (auto Err = C.readBytes(reinterpret_cast(&V), sizeof(T))) + return Err; + support::endian::byte_swap(V); + return Error::success(); +} + +/// RPC channel serialization for enums. +template +typename std::enable_if::value, Error>::type +serialize(RPCByteChannel &C, T V) { + return serialize(C, static_cast::type>(V)); +} + +/// RPC channel deserialization for enums. +template +typename std::enable_if::value, Error>::type +deserialize(RPCByteChannel &C, T &V) { + typename std::underlying_type::type Tmp; + Error Err = deserialize(C, Tmp); + V = static_cast(Tmp); + return Err; +} + +/// RPC channel serialization for bools. +inline Error serialize(RPCByteChannel &C, bool V) { + uint8_t VN = V ? 1 : 0; + return C.appendBytes(reinterpret_cast(&VN), 1); +} + +/// RPC channel deserialization for bools. +inline Error deserialize(RPCByteChannel &C, bool &V) { + uint8_t VN = 0; + if (auto Err = C.readBytes(reinterpret_cast(&VN), 1)) + return Err; + + V = (VN != 0); + return Error::success(); +} + +/// RPC channel serialization for StringRefs. +/// Note: There is no corresponding deseralization for this, as StringRef +/// doesn't own its memory and so can't hold the deserialized data. +inline Error serialize(RPCByteChannel &C, StringRef S) { + if (auto Err = serialize(C, static_cast(S.size()))) + return Err; + return C.appendBytes((const char *)S.bytes_begin(), S.size()); +} + +/// RPC channel serialization for std::strings. +inline Error serialize(RPCByteChannel &C, const std::string &S) { + return serialize(C, StringRef(S)); +} + +/// RPC channel deserialization for std::strings. +inline Error deserialize(RPCByteChannel &C, std::string &S) { + uint64_t Count; + if (auto Err = deserialize(C, Count)) + return Err; + S.resize(Count); + return C.readBytes(&S[0], Count); +} + +// Serialization helper for std::tuple. +template +inline Error serializeTupleHelper(RPCByteChannel &C, const TupleT &V, + llvm::index_sequence _) { + return serializeSeq(C, std::get(V)...); +} + +/// RPC channel serialization for std::tuple. +template +inline Error serialize(RPCByteChannel &C, const std::tuple &V) { + return serializeTupleHelper(C, V, llvm::index_sequence_for()); +} + +// Serialization helper for std::tuple. +template +inline Error deserializeTupleHelper(RPCByteChannel &C, TupleT &V, + llvm::index_sequence _) { + return deserializeSeq(C, std::get(V)...); +} + +/// RPC channel deserialization for std::tuple. +template +inline Error deserialize(RPCByteChannel &C, std::tuple &V) { + return deserializeTupleHelper(C, V, llvm::index_sequence_for()); +} + +/// RPC channel serialization for ArrayRef. +template Error serialize(RPCByteChannel &C, const ArrayRef &A) { + if (auto Err = serialize(C, static_cast(A.size()))) + return Err; + + for (const auto &E : A) + if (auto Err = serialize(C, E)) + return Err; + + return Error::success(); +} + +/// RPC channel serialization for std::array. +template Error serialize(RPCByteChannel &C, + const std::vector &V) { + return serialize(C, ArrayRef(V)); +} + +/// RPC channel deserialization for std::array. +template Error deserialize(RPCByteChannel &C, std::vector &V) { + uint64_t Count = 0; + if (auto Err = deserialize(C, Count)) + return Err; + + V.resize(Count); + for (auto &E : V) + if (auto Err = deserialize(C, E)) + return Err; + + return Error::success(); +} + +} // end namespace remote +} // end namespace orc +} // end namespace llvm + +#endif // LLVM_EXECUTIONENGINE_ORC_RPCBYTECHANNEL_H diff --git a/llvm/include/llvm/ExecutionEngine/Orc/RPCChannel.h b/llvm/include/llvm/ExecutionEngine/Orc/RPCChannel.h deleted file mode 100644 index c569e3cf05b..00000000000 --- a/llvm/include/llvm/ExecutionEngine/Orc/RPCChannel.h +++ /dev/null @@ -1,249 +0,0 @@ -//===- llvm/ExecutionEngine/Orc/RPCChannel.h --------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_EXECUTIONENGINE_ORC_RPCCHANNEL_H -#define LLVM_EXECUTIONENGINE_ORC_RPCCHANNEL_H - -#include "OrcError.h" -#include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/Support/Endian.h" -#include "llvm/Support/Error.h" -#include -#include -#include -#include -#include -#include - -namespace llvm { -namespace orc { -namespace remote { - -/// Interface for byte-streams to be used with RPC. -class RPCChannel { -public: - virtual ~RPCChannel() {} - - /// Read Size bytes from the stream into *Dst. - virtual Error readBytes(char *Dst, unsigned Size) = 0; - - /// Read size bytes from *Src and append them to the stream. - virtual Error appendBytes(const char *Src, unsigned Size) = 0; - - /// Flush the stream if possible. - virtual Error send() = 0; - - /// Get the lock for stream reading. - std::mutex &getReadLock() { return readLock; } - - /// Get the lock for stream writing. - std::mutex &getWriteLock() { return writeLock; } - -private: - std::mutex readLock, writeLock; -}; - -/// Notify the channel that we're starting a message send. -/// Locks the channel for writing. -inline Error startSendMessage(RPCChannel &C) { - C.getWriteLock().lock(); - return Error::success(); -} - -/// Notify the channel that we're ending a message send. -/// Unlocks the channel for writing. -inline Error endSendMessage(RPCChannel &C) { - C.getWriteLock().unlock(); - return Error::success(); -} - -/// Notify the channel that we're starting a message receive. -/// Locks the channel for reading. -inline Error startReceiveMessage(RPCChannel &C) { - C.getReadLock().lock(); - return Error::success(); -} - -/// Notify the channel that we're ending a message receive. -/// Unlocks the channel for reading. -inline Error endReceiveMessage(RPCChannel &C) { - C.getReadLock().unlock(); - return Error::success(); -} - -/// RPC channel serialization for a variadic list of arguments. -template -Error serializeSeq(RPCChannel &C, const T &Arg, const Ts &... Args) { - if (auto Err = serialize(C, Arg)) - return Err; - return serializeSeq(C, Args...); -} - -/// RPC channel serialization for an (empty) variadic list of arguments. -inline Error serializeSeq(RPCChannel &C) { return Error::success(); } - -/// RPC channel deserialization for a variadic list of arguments. -template -Error deserializeSeq(RPCChannel &C, T &Arg, Ts &... Args) { - if (auto Err = deserialize(C, Arg)) - return Err; - return deserializeSeq(C, Args...); -} - -/// RPC channel serialization for an (empty) variadic list of arguments. -inline Error deserializeSeq(RPCChannel &C) { return Error::success(); } - -/// RPC channel serialization for integer primitives. -template -typename std::enable_if< - std::is_same::value || std::is_same::value || - std::is_same::value || std::is_same::value || - std::is_same::value || std::is_same::value || - std::is_same::value || std::is_same::value, - Error>::type -serialize(RPCChannel &C, T V) { - support::endian::byte_swap(V); - return C.appendBytes(reinterpret_cast(&V), sizeof(T)); -} - -/// RPC channel deserialization for integer primitives. -template -typename std::enable_if< - std::is_same::value || std::is_same::value || - std::is_same::value || std::is_same::value || - std::is_same::value || std::is_same::value || - std::is_same::value || std::is_same::value, - Error>::type -deserialize(RPCChannel &C, T &V) { - if (auto Err = C.readBytes(reinterpret_cast(&V), sizeof(T))) - return Err; - support::endian::byte_swap(V); - return Error::success(); -} - -/// RPC channel serialization for enums. -template -typename std::enable_if::value, Error>::type -serialize(RPCChannel &C, T V) { - return serialize(C, static_cast::type>(V)); -} - -/// RPC channel deserialization for enums. -template -typename std::enable_if::value, Error>::type -deserialize(RPCChannel &C, T &V) { - typename std::underlying_type::type Tmp; - Error Err = deserialize(C, Tmp); - V = static_cast(Tmp); - return Err; -} - -/// RPC channel serialization for bools. -inline Error serialize(RPCChannel &C, bool V) { - uint8_t VN = V ? 1 : 0; - return C.appendBytes(reinterpret_cast(&VN), 1); -} - -/// RPC channel deserialization for bools. -inline Error deserialize(RPCChannel &C, bool &V) { - uint8_t VN = 0; - if (auto Err = C.readBytes(reinterpret_cast(&VN), 1)) - return Err; - - V = (VN != 0); - return Error::success(); -} - -/// RPC channel serialization for StringRefs. -/// Note: There is no corresponding deseralization for this, as StringRef -/// doesn't own its memory and so can't hold the deserialized data. -inline Error serialize(RPCChannel &C, StringRef S) { - if (auto Err = serialize(C, static_cast(S.size()))) - return Err; - return C.appendBytes((const char *)S.bytes_begin(), S.size()); -} - -/// RPC channel serialization for std::strings. -inline Error serialize(RPCChannel &C, const std::string &S) { - return serialize(C, StringRef(S)); -} - -/// RPC channel deserialization for std::strings. -inline Error deserialize(RPCChannel &C, std::string &S) { - uint64_t Count; - if (auto Err = deserialize(C, Count)) - return Err; - S.resize(Count); - return C.readBytes(&S[0], Count); -} - -// Serialization helper for std::tuple. -template -inline Error serializeTupleHelper(RPCChannel &C, const TupleT &V, - llvm::index_sequence _) { - return serializeSeq(C, std::get(V)...); -} - -/// RPC channel serialization for std::tuple. -template -inline Error serialize(RPCChannel &C, const std::tuple &V) { - return serializeTupleHelper(C, V, llvm::index_sequence_for()); -} - -// Serialization helper for std::tuple. -template -inline Error deserializeTupleHelper(RPCChannel &C, TupleT &V, - llvm::index_sequence _) { - return deserializeSeq(C, std::get(V)...); -} - -/// RPC channel deserialization for std::tuple. -template -inline Error deserialize(RPCChannel &C, std::tuple &V) { - return deserializeTupleHelper(C, V, llvm::index_sequence_for()); -} - -/// RPC channel serialization for ArrayRef. -template Error serialize(RPCChannel &C, const ArrayRef &A) { - if (auto Err = serialize(C, static_cast(A.size()))) - return Err; - - for (const auto &E : A) - if (auto Err = serialize(C, E)) - return Err; - - return Error::success(); -} - -/// RPC channel serialization for std::array. -template Error serialize(RPCChannel &C, const std::vector &V) { - return serialize(C, ArrayRef(V)); -} - -/// RPC channel deserialization for std::array. -template Error deserialize(RPCChannel &C, std::vector &V) { - uint64_t Count = 0; - if (auto Err = deserialize(C, Count)) - return Err; - - V.resize(Count); - for (auto &E : V) - if (auto Err = deserialize(C, E)) - return Err; - - return Error::success(); -} - -} // end namespace remote -} // end namespace orc -} // end namespace llvm - -#endif // LLVM_EXECUTIONENGINE_ORC_RPCCHANNEL_H diff --git a/llvm/tools/lli/RemoteJITUtils.h b/llvm/tools/lli/RemoteJITUtils.h index 0c4306ad5cb..d47716cb880 100644 --- a/llvm/tools/lli/RemoteJITUtils.h +++ b/llvm/tools/lli/RemoteJITUtils.h @@ -14,7 +14,7 @@ #ifndef LLVM_TOOLS_LLI_REMOTEJITUTILS_H #define LLVM_TOOLS_LLI_REMOTEJITUTILS_H -#include "llvm/ExecutionEngine/Orc/RPCChannel.h" +#include "llvm/ExecutionEngine/Orc/RPCByteChannel.h" #include "llvm/ExecutionEngine/RTDyldMemoryManager.h" #include @@ -25,7 +25,7 @@ #endif /// RPC channel that reads from and writes from file descriptors. -class FDRPCChannel final : public llvm::orc::remote::RPCChannel { +class FDRPCChannel final : public llvm::orc::remote::RPCByteChannel { public: FDRPCChannel(int InFD, int OutFD) : InFD(InFD), OutFD(OutFD) {} diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp index 31979097b93..00ae52d35e2 100644 --- a/llvm/tools/lli/lli.cpp +++ b/llvm/tools/lli/lli.cpp @@ -662,7 +662,8 @@ int main(int argc, char **argv, char * const *envp) { } // Create a remote target client running over the channel. - typedef orc::remote::OrcRemoteTargetClient MyRemote; + typedef orc::remote::OrcRemoteTargetClient + MyRemote; MyRemote R = ExitOnErr(MyRemote::Create(*C)); // Create a remote memory manager. -- cgit v1.2.3