From 044eb2f6afba375a914ac9d8024f8f5142bb912e Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 18 Dec 2017 20:10:56 +0000 Subject: Vendor import of llvm trunk r321017: https://llvm.org/svn/llvm-project/llvm/trunk@321017 --- .../ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h | 263 +++++++++++++++------ 1 file changed, 185 insertions(+), 78 deletions(-) (limited to 'include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h') diff --git a/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h b/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h index 07ae7f04d1a0..bc0da0f9a730 100644 --- a/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h +++ b/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h @@ -25,6 +25,37 @@ namespace orc { namespace remote { +/// Template error for missing resources. +template +class ResourceNotFound + : public ErrorInfo> { +public: + static char ID; + + ResourceNotFound(ResourceIdT ResourceId, + std::string ResourceDescription = "") + : ResourceId(std::move(ResourceId)), + ResourceDescription(std::move(ResourceDescription)) {} + + std::error_code convertToErrorCode() const override { + return orcError(OrcErrorCode::UnknownResourceHandle); + } + + void log(raw_ostream &OS) const override { + OS << (ResourceDescription.empty() + ? "Remote resource with id " + : ResourceDescription) + << " " << ResourceId << " not found"; + } + +private: + ResourceIdT ResourceId; + std::string ResourceDescription; +}; + +template +char ResourceNotFound::ID = 0; + class DirectBufferWriter { public: DirectBufferWriter() = default; @@ -45,6 +76,32 @@ private: namespace rpc { +template <> +class RPCTypeName { +public: + static const char *getName() { return "JITSymbolFlags"; } +}; + +template +class SerializationTraits { +public: + + static Error serialize(ChannelT &C, const JITSymbolFlags &Flags) { + return serializeSeq(C, static_cast(Flags), + Flags.getTargetFlags()); + } + + static Error deserialize(ChannelT &C, JITSymbolFlags &Flags) { + JITSymbolFlags::UnderlyingType JITFlags; + JITSymbolFlags::TargetFlagsType TargetFlags; + if (auto Err = deserializeSeq(C, JITFlags, TargetFlags)) + return Err; + Flags = JITSymbolFlags(static_cast(JITFlags), + TargetFlags); + return Error::success(); + } +}; + template <> class RPCTypeName { public: static const char *getName() { return "DirectBufferWriter"; } @@ -83,41 +140,66 @@ public: namespace remote { -class OrcRemoteTargetRPCAPI - : public rpc::SingleThreadedRPCEndpoint { -protected: - class ResourceIdMgr { - public: - using ResourceId = uint64_t; - static const ResourceId InvalidId = ~0U; - - ResourceId getNext() { - if (!FreeIds.empty()) { - ResourceId I = FreeIds.back(); - FreeIds.pop_back(); - return I; - } - return NextId++; +class ResourceIdMgr { +public: + using ResourceId = uint64_t; + static const ResourceId InvalidId = ~0U; + + ResourceIdMgr() = default; + explicit ResourceIdMgr(ResourceId FirstValidId) + : NextId(std::move(FirstValidId)) {} + + ResourceId getNext() { + if (!FreeIds.empty()) { + ResourceId I = FreeIds.back(); + FreeIds.pop_back(); + return I; } + assert(NextId + 1 != ~0ULL && "All ids allocated"); + return NextId++; + } + + void release(ResourceId I) { FreeIds.push_back(I); } + +private: + ResourceId NextId = 1; + std::vector FreeIds; +}; - void release(ResourceId I) { FreeIds.push_back(I); } +/// Registers EH frames on the remote. +namespace eh { - private: - ResourceId NextId = 0; - std::vector FreeIds; + /// Registers EH frames on the remote. + class RegisterEHFrames + : public rpc::Function { + public: + static const char *getName() { return "RegisterEHFrames"; } }; -public: - // FIXME: Remove constructors once MSVC supports synthesizing move-ops. - OrcRemoteTargetRPCAPI(rpc::RawByteChannel &C) - : rpc::SingleThreadedRPCEndpoint(C, true) {} + /// Deregisters EH frames on the remote. + class DeregisterEHFrames + : public rpc::Function { + public: + static const char *getName() { return "DeregisterEHFrames"; } + }; + +} // end namespace eh + +/// RPC functions for executing remote code. +namespace exec { + /// Call an 'int32_t()'-type function on the remote, returns the called + /// function's return value. class CallIntVoid : public rpc::Function { public: static const char *getName() { return "CallIntVoid"; } }; + /// Call an 'int32_t(int32_t, char**)'-type function on the remote, returns the + /// called function's return value. class CallMain : public rpc::Function Args)> { @@ -125,12 +207,20 @@ 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 { public: static const char *getName() { return "CallVoidVoid"; } }; +} // end namespace exec + +/// RPC functions for remote memory management / inspection / modification. +namespace mem { + + /// Creates a memory allocator on the remote. class CreateRemoteAllocator : public rpc::Function { @@ -138,27 +228,68 @@ public: static const char *getName() { return "CreateRemoteAllocator"; } }; - class CreateIndirectStubsOwner - : public rpc::Function { + /// Destroys a remote allocator, freeing any memory allocated by it. + class DestroyRemoteAllocator + : public rpc::Function { public: - static const char *getName() { return "CreateIndirectStubsOwner"; } + static const char *getName() { return "DestroyRemoteAllocator"; } }; - class DeregisterEHFrames - : public rpc::Function { + /// Read a remote memory block. + class ReadMem + : public rpc::Function(JITTargetAddress Src, + uint64_t Size)> { public: - static const char *getName() { return "DeregisterEHFrames"; } + static const char *getName() { return "ReadMem"; } }; - class DestroyRemoteAllocator - : public rpc::Function { + /// Reserve a block of memory on the remote via the given allocator. + class ReserveMem + : public rpc::Function { public: - static const char *getName() { return "DestroyRemoteAllocator"; } + static const char *getName() { return "ReserveMem"; } + }; + + /// Set the memory protection on a memory block. + class SetProtections + : public rpc::Function { + public: + static const char *getName() { return "SetProtections"; } + }; + + /// Write to a remote memory block. + class WriteMem + : public rpc::Function { + public: + static const char *getName() { return "WriteMem"; } + }; + + /// Write to a remote pointer. + class WritePtr : public rpc::Function { + public: + static const char *getName() { return "WritePtr"; } + }; + +} // end namespace mem + +/// RPC functions for remote stub and trampoline management. +namespace stubs { + + /// Creates an indirect stub owner on the remote. + class CreateIndirectStubsOwner + : public rpc::Function { + public: + static const char *getName() { return "CreateIndirectStubsOwner"; } }; + /// RPC function for destroying an indirect stubs owner. class DestroyIndirectStubsOwner : public rpc::Function { @@ -177,6 +308,7 @@ public: static const char *getName() { return "EmitIndirectStubs"; } }; + /// RPC function to emit the resolver block and return its address. class EmitResolverBlock : public rpc::Function { public: static const char *getName() { return "EmitResolverBlock"; } @@ -190,12 +322,10 @@ public: static const char *getName() { return "EmitTrampolineBlock"; } }; - class GetSymbolAddress - : public rpc::Function { - public: - static const char *getName() { return "GetSymbolAddress"; } - }; +} // end namespace stubs + +/// Miscelaneous RPC functions for dealing with remotes. +namespace utils { /// GetRemoteInfo result is (Triple, PointerSize, PageSize, TrampolineSize, /// IndirectStubsSize). @@ -207,28 +337,15 @@ public: static const char *getName() { return "GetRemoteInfo"; } }; - class ReadMem - : public rpc::Function(JITTargetAddress Src, - uint64_t Size)> { - public: - static const char *getName() { return "ReadMem"; } - }; - - class RegisterEHFrames - : public rpc::Function { - public: - static const char *getName() { return "RegisterEHFrames"; } - }; - - class ReserveMem - : public rpc::Function { + /// Get the address of a remote symbol. + class GetSymbolAddress + : public rpc::Function { public: - static const char *getName() { return "ReserveMem"; } + static const char *getName() { return "GetSymbolAddress"; } }; + /// Request that the host execute a compile callback. class RequestCompile : public rpc::Function< RequestCompile, JITTargetAddress(JITTargetAddress TrampolineAddr)> { @@ -236,30 +353,20 @@ public: static const char *getName() { return "RequestCompile"; } }; - class SetProtections - : public rpc::Function { - public: - static const char *getName() { return "SetProtections"; } - }; - + /// Notify the remote and terminate the session. class TerminateSession : public rpc::Function { public: static const char *getName() { return "TerminateSession"; } }; - class WriteMem - : public rpc::Function { - public: - static const char *getName() { return "WriteMem"; } - }; +} // namespace utils - class WritePtr : public rpc::Function { - public: - static const char *getName() { return "WritePtr"; } - }; +class OrcRemoteTargetRPCAPI + : public rpc::SingleThreadedRPCEndpoint { +public: + // FIXME: Remove constructors once MSVC supports synthesizing move-ops. + OrcRemoteTargetRPCAPI(rpc::RawByteChannel &C) + : rpc::SingleThreadedRPCEndpoint(C, true) {} }; } // end namespace remote -- cgit v1.2.3