//===--- OrcRemoteTargetRPCAPI.h - Orc Remote-target RPC API ----*- C++ -*-===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // This file defines the Orc remote-target RPC API. It should not be used // directly, but is used by the RemoteTargetClient and RemoteTargetServer // classes. // //===----------------------------------------------------------------------===// #ifndef LLVM_EXECUTIONENGINE_ORC_ORCREMOTETARGETRPCAPI_H #define LLVM_EXECUTIONENGINE_ORC_ORCREMOTETARGETRPCAPI_H #include "JITSymbol.h" #include "RPCChannel.h" #include "RPCUtils.h" namespace llvm { namespace orc { namespace remote { class DirectBufferWriter { public: DirectBufferWriter() = default; DirectBufferWriter(const char *Src, TargetAddress Dst, uint64_t Size) : Src(Src), Dst(Dst), Size(Size) {} const char *getSrc() const { return Src; } TargetAddress getDst() const { return Dst; } uint64_t getSize() const { return Size; } private: const char *Src; TargetAddress Dst; uint64_t Size; }; inline Error serialize(RPCChannel &C, const DirectBufferWriter &DBW) { if (auto EC = serialize(C, DBW.getDst())) return EC; if (auto EC = serialize(C, DBW.getSize())) return EC; return C.appendBytes(DBW.getSrc(), DBW.getSize()); } inline Error deserialize(RPCChannel &C, DirectBufferWriter &DBW) { TargetAddress Dst; if (auto EC = deserialize(C, Dst)) return EC; uint64_t Size; if (auto EC = deserialize(C, Size)) return EC; char *Addr = reinterpret_cast(static_cast(Dst)); DBW = DirectBufferWriter(0, Dst, Size); return C.readBytes(Addr, Size); } class OrcRemoteTargetRPCAPI : public RPC { protected: class ResourceIdMgr { public: typedef uint64_t ResourceId; static const ResourceId InvalidId = ~0U; ResourceId getNext() { if (!FreeIds.empty()) { ResourceId I = FreeIds.back(); FreeIds.pop_back(); return I; } return NextId++; } void release(ResourceId I) { FreeIds.push_back(I); } private: ResourceId NextId = 0; std::vector FreeIds; }; public: // FIXME: Remove constructors once MSVC supports synthesizing move-ops. OrcRemoteTargetRPCAPI() = default; OrcRemoteTargetRPCAPI(const OrcRemoteTargetRPCAPI &) = delete; OrcRemoteTargetRPCAPI &operator=(const OrcRemoteTargetRPCAPI &) = delete; OrcRemoteTargetRPCAPI(OrcRemoteTargetRPCAPI &&) {} OrcRemoteTargetRPCAPI &operator=(OrcRemoteTargetRPCAPI &&) { return *this; } enum JITFuncId : uint32_t { InvalidId = RPCFunctionIdTraits::InvalidId, CallIntVoidId = RPCFunctionIdTraits::FirstValidId, CallMainId, CallVoidVoidId, CreateRemoteAllocatorId, CreateIndirectStubsOwnerId, DeregisterEHFramesId, DestroyRemoteAllocatorId, DestroyIndirectStubsOwnerId, EmitIndirectStubsId, EmitResolverBlockId, EmitTrampolineBlockId, GetSymbolAddressId, GetRemoteInfoId, ReadMemId, RegisterEHFramesId, ReserveMemId, RequestCompileId, SetProtectionsId, TerminateSessionId, WriteMemId, WritePtrId }; static const char *getJITFuncIdName(JITFuncId Id); typedef Function CallIntVoid; typedef Function Args)> CallMain; typedef Function CallVoidVoid; typedef Function CreateRemoteAllocator; typedef Function CreateIndirectStubsOwner; typedef Function DeregisterEHFrames; typedef Function DestroyRemoteAllocator; typedef Function DestroyIndirectStubsOwner; /// EmitIndirectStubs result is (StubsBase, PtrsBase, NumStubsEmitted). typedef Function( ResourceIdMgr::ResourceId StubsOwnerID, uint32_t NumStubsRequired)> EmitIndirectStubs; typedef Function EmitResolverBlock; /// EmitTrampolineBlock result is (BlockAddr, NumTrampolines). typedef Function()> EmitTrampolineBlock; typedef Function GetSymbolAddress; /// GetRemoteInfo result is (Triple, PointerSize, PageSize, TrampolineSize, /// IndirectStubsSize). typedef Function()> GetRemoteInfo; typedef Function(TargetAddress Src, uint64_t Size)> ReadMem; typedef Function RegisterEHFrames; typedef Function ReserveMem; typedef Function RequestCompile; typedef Function SetProtections; typedef Function TerminateSession; typedef Function WriteMem; typedef Function WritePtr; }; } // end namespace remote } // end namespace orc } // end namespace llvm #endif