1*9880d681SAndroid Build Coastguard Worker //===--- OrcRemoteTargetRPCAPI.h - Orc Remote-target RPC API ----*- C++ -*-===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file defines the Orc remote-target RPC API. It should not be used
11*9880d681SAndroid Build Coastguard Worker // directly, but is used by the RemoteTargetClient and RemoteTargetServer
12*9880d681SAndroid Build Coastguard Worker // classes.
13*9880d681SAndroid Build Coastguard Worker //
14*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
15*9880d681SAndroid Build Coastguard Worker
16*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_EXECUTIONENGINE_ORC_ORCREMOTETARGETRPCAPI_H
17*9880d681SAndroid Build Coastguard Worker #define LLVM_EXECUTIONENGINE_ORC_ORCREMOTETARGETRPCAPI_H
18*9880d681SAndroid Build Coastguard Worker
19*9880d681SAndroid Build Coastguard Worker #include "JITSymbol.h"
20*9880d681SAndroid Build Coastguard Worker #include "RPCChannel.h"
21*9880d681SAndroid Build Coastguard Worker #include "RPCUtils.h"
22*9880d681SAndroid Build Coastguard Worker
23*9880d681SAndroid Build Coastguard Worker namespace llvm {
24*9880d681SAndroid Build Coastguard Worker namespace orc {
25*9880d681SAndroid Build Coastguard Worker namespace remote {
26*9880d681SAndroid Build Coastguard Worker
27*9880d681SAndroid Build Coastguard Worker class DirectBufferWriter {
28*9880d681SAndroid Build Coastguard Worker public:
29*9880d681SAndroid Build Coastguard Worker DirectBufferWriter() = default;
DirectBufferWriter(const char * Src,TargetAddress Dst,uint64_t Size)30*9880d681SAndroid Build Coastguard Worker DirectBufferWriter(const char *Src, TargetAddress Dst, uint64_t Size)
31*9880d681SAndroid Build Coastguard Worker : Src(Src), Dst(Dst), Size(Size) {}
32*9880d681SAndroid Build Coastguard Worker
getSrc()33*9880d681SAndroid Build Coastguard Worker const char *getSrc() const { return Src; }
getDst()34*9880d681SAndroid Build Coastguard Worker TargetAddress getDst() const { return Dst; }
getSize()35*9880d681SAndroid Build Coastguard Worker uint64_t getSize() const { return Size; }
36*9880d681SAndroid Build Coastguard Worker
37*9880d681SAndroid Build Coastguard Worker private:
38*9880d681SAndroid Build Coastguard Worker const char *Src;
39*9880d681SAndroid Build Coastguard Worker TargetAddress Dst;
40*9880d681SAndroid Build Coastguard Worker uint64_t Size;
41*9880d681SAndroid Build Coastguard Worker };
42*9880d681SAndroid Build Coastguard Worker
serialize(RPCChannel & C,const DirectBufferWriter & DBW)43*9880d681SAndroid Build Coastguard Worker inline Error serialize(RPCChannel &C, const DirectBufferWriter &DBW) {
44*9880d681SAndroid Build Coastguard Worker if (auto EC = serialize(C, DBW.getDst()))
45*9880d681SAndroid Build Coastguard Worker return EC;
46*9880d681SAndroid Build Coastguard Worker if (auto EC = serialize(C, DBW.getSize()))
47*9880d681SAndroid Build Coastguard Worker return EC;
48*9880d681SAndroid Build Coastguard Worker return C.appendBytes(DBW.getSrc(), DBW.getSize());
49*9880d681SAndroid Build Coastguard Worker }
50*9880d681SAndroid Build Coastguard Worker
deserialize(RPCChannel & C,DirectBufferWriter & DBW)51*9880d681SAndroid Build Coastguard Worker inline Error deserialize(RPCChannel &C, DirectBufferWriter &DBW) {
52*9880d681SAndroid Build Coastguard Worker TargetAddress Dst;
53*9880d681SAndroid Build Coastguard Worker if (auto EC = deserialize(C, Dst))
54*9880d681SAndroid Build Coastguard Worker return EC;
55*9880d681SAndroid Build Coastguard Worker uint64_t Size;
56*9880d681SAndroid Build Coastguard Worker if (auto EC = deserialize(C, Size))
57*9880d681SAndroid Build Coastguard Worker return EC;
58*9880d681SAndroid Build Coastguard Worker char *Addr = reinterpret_cast<char *>(static_cast<uintptr_t>(Dst));
59*9880d681SAndroid Build Coastguard Worker
60*9880d681SAndroid Build Coastguard Worker DBW = DirectBufferWriter(0, Dst, Size);
61*9880d681SAndroid Build Coastguard Worker
62*9880d681SAndroid Build Coastguard Worker return C.readBytes(Addr, Size);
63*9880d681SAndroid Build Coastguard Worker }
64*9880d681SAndroid Build Coastguard Worker
65*9880d681SAndroid Build Coastguard Worker class OrcRemoteTargetRPCAPI : public RPC<RPCChannel> {
66*9880d681SAndroid Build Coastguard Worker protected:
67*9880d681SAndroid Build Coastguard Worker class ResourceIdMgr {
68*9880d681SAndroid Build Coastguard Worker public:
69*9880d681SAndroid Build Coastguard Worker typedef uint64_t ResourceId;
70*9880d681SAndroid Build Coastguard Worker static const ResourceId InvalidId = ~0U;
71*9880d681SAndroid Build Coastguard Worker
getNext()72*9880d681SAndroid Build Coastguard Worker ResourceId getNext() {
73*9880d681SAndroid Build Coastguard Worker if (!FreeIds.empty()) {
74*9880d681SAndroid Build Coastguard Worker ResourceId I = FreeIds.back();
75*9880d681SAndroid Build Coastguard Worker FreeIds.pop_back();
76*9880d681SAndroid Build Coastguard Worker return I;
77*9880d681SAndroid Build Coastguard Worker }
78*9880d681SAndroid Build Coastguard Worker return NextId++;
79*9880d681SAndroid Build Coastguard Worker }
release(ResourceId I)80*9880d681SAndroid Build Coastguard Worker void release(ResourceId I) { FreeIds.push_back(I); }
81*9880d681SAndroid Build Coastguard Worker
82*9880d681SAndroid Build Coastguard Worker private:
83*9880d681SAndroid Build Coastguard Worker ResourceId NextId = 0;
84*9880d681SAndroid Build Coastguard Worker std::vector<ResourceId> FreeIds;
85*9880d681SAndroid Build Coastguard Worker };
86*9880d681SAndroid Build Coastguard Worker
87*9880d681SAndroid Build Coastguard Worker public:
88*9880d681SAndroid Build Coastguard Worker // FIXME: Remove constructors once MSVC supports synthesizing move-ops.
89*9880d681SAndroid Build Coastguard Worker OrcRemoteTargetRPCAPI() = default;
90*9880d681SAndroid Build Coastguard Worker OrcRemoteTargetRPCAPI(const OrcRemoteTargetRPCAPI &) = delete;
91*9880d681SAndroid Build Coastguard Worker OrcRemoteTargetRPCAPI &operator=(const OrcRemoteTargetRPCAPI &) = delete;
92*9880d681SAndroid Build Coastguard Worker
OrcRemoteTargetRPCAPI(OrcRemoteTargetRPCAPI &&)93*9880d681SAndroid Build Coastguard Worker OrcRemoteTargetRPCAPI(OrcRemoteTargetRPCAPI &&) {}
94*9880d681SAndroid Build Coastguard Worker OrcRemoteTargetRPCAPI &operator=(OrcRemoteTargetRPCAPI &&) { return *this; }
95*9880d681SAndroid Build Coastguard Worker
96*9880d681SAndroid Build Coastguard Worker enum JITFuncId : uint32_t {
97*9880d681SAndroid Build Coastguard Worker InvalidId = RPCFunctionIdTraits<JITFuncId>::InvalidId,
98*9880d681SAndroid Build Coastguard Worker CallIntVoidId = RPCFunctionIdTraits<JITFuncId>::FirstValidId,
99*9880d681SAndroid Build Coastguard Worker CallMainId,
100*9880d681SAndroid Build Coastguard Worker CallVoidVoidId,
101*9880d681SAndroid Build Coastguard Worker CreateRemoteAllocatorId,
102*9880d681SAndroid Build Coastguard Worker CreateIndirectStubsOwnerId,
103*9880d681SAndroid Build Coastguard Worker DeregisterEHFramesId,
104*9880d681SAndroid Build Coastguard Worker DestroyRemoteAllocatorId,
105*9880d681SAndroid Build Coastguard Worker DestroyIndirectStubsOwnerId,
106*9880d681SAndroid Build Coastguard Worker EmitIndirectStubsId,
107*9880d681SAndroid Build Coastguard Worker EmitResolverBlockId,
108*9880d681SAndroid Build Coastguard Worker EmitTrampolineBlockId,
109*9880d681SAndroid Build Coastguard Worker GetSymbolAddressId,
110*9880d681SAndroid Build Coastguard Worker GetRemoteInfoId,
111*9880d681SAndroid Build Coastguard Worker ReadMemId,
112*9880d681SAndroid Build Coastguard Worker RegisterEHFramesId,
113*9880d681SAndroid Build Coastguard Worker ReserveMemId,
114*9880d681SAndroid Build Coastguard Worker RequestCompileId,
115*9880d681SAndroid Build Coastguard Worker SetProtectionsId,
116*9880d681SAndroid Build Coastguard Worker TerminateSessionId,
117*9880d681SAndroid Build Coastguard Worker WriteMemId,
118*9880d681SAndroid Build Coastguard Worker WritePtrId
119*9880d681SAndroid Build Coastguard Worker };
120*9880d681SAndroid Build Coastguard Worker
121*9880d681SAndroid Build Coastguard Worker static const char *getJITFuncIdName(JITFuncId Id);
122*9880d681SAndroid Build Coastguard Worker
123*9880d681SAndroid Build Coastguard Worker typedef Function<CallIntVoidId, int32_t(TargetAddress Addr)> CallIntVoid;
124*9880d681SAndroid Build Coastguard Worker
125*9880d681SAndroid Build Coastguard Worker typedef Function<CallMainId,
126*9880d681SAndroid Build Coastguard Worker int32_t(TargetAddress Addr, std::vector<std::string> Args)>
127*9880d681SAndroid Build Coastguard Worker CallMain;
128*9880d681SAndroid Build Coastguard Worker
129*9880d681SAndroid Build Coastguard Worker typedef Function<CallVoidVoidId, void(TargetAddress FnAddr)> CallVoidVoid;
130*9880d681SAndroid Build Coastguard Worker
131*9880d681SAndroid Build Coastguard Worker typedef Function<CreateRemoteAllocatorId,
132*9880d681SAndroid Build Coastguard Worker void(ResourceIdMgr::ResourceId AllocatorID)>
133*9880d681SAndroid Build Coastguard Worker CreateRemoteAllocator;
134*9880d681SAndroid Build Coastguard Worker
135*9880d681SAndroid Build Coastguard Worker typedef Function<CreateIndirectStubsOwnerId,
136*9880d681SAndroid Build Coastguard Worker void(ResourceIdMgr::ResourceId StubOwnerID)>
137*9880d681SAndroid Build Coastguard Worker CreateIndirectStubsOwner;
138*9880d681SAndroid Build Coastguard Worker
139*9880d681SAndroid Build Coastguard Worker typedef Function<DeregisterEHFramesId,
140*9880d681SAndroid Build Coastguard Worker void(TargetAddress Addr, uint32_t Size)>
141*9880d681SAndroid Build Coastguard Worker DeregisterEHFrames;
142*9880d681SAndroid Build Coastguard Worker
143*9880d681SAndroid Build Coastguard Worker typedef Function<DestroyRemoteAllocatorId,
144*9880d681SAndroid Build Coastguard Worker void(ResourceIdMgr::ResourceId AllocatorID)>
145*9880d681SAndroid Build Coastguard Worker DestroyRemoteAllocator;
146*9880d681SAndroid Build Coastguard Worker
147*9880d681SAndroid Build Coastguard Worker typedef Function<DestroyIndirectStubsOwnerId,
148*9880d681SAndroid Build Coastguard Worker void(ResourceIdMgr::ResourceId StubsOwnerID)>
149*9880d681SAndroid Build Coastguard Worker DestroyIndirectStubsOwner;
150*9880d681SAndroid Build Coastguard Worker
151*9880d681SAndroid Build Coastguard Worker /// EmitIndirectStubs result is (StubsBase, PtrsBase, NumStubsEmitted).
152*9880d681SAndroid Build Coastguard Worker typedef Function<EmitIndirectStubsId,
153*9880d681SAndroid Build Coastguard Worker std::tuple<TargetAddress, TargetAddress, uint32_t>(
154*9880d681SAndroid Build Coastguard Worker ResourceIdMgr::ResourceId StubsOwnerID,
155*9880d681SAndroid Build Coastguard Worker uint32_t NumStubsRequired)>
156*9880d681SAndroid Build Coastguard Worker EmitIndirectStubs;
157*9880d681SAndroid Build Coastguard Worker
158*9880d681SAndroid Build Coastguard Worker typedef Function<EmitResolverBlockId, void()> EmitResolverBlock;
159*9880d681SAndroid Build Coastguard Worker
160*9880d681SAndroid Build Coastguard Worker /// EmitTrampolineBlock result is (BlockAddr, NumTrampolines).
161*9880d681SAndroid Build Coastguard Worker typedef Function<EmitTrampolineBlockId, std::tuple<TargetAddress, uint32_t>()>
162*9880d681SAndroid Build Coastguard Worker EmitTrampolineBlock;
163*9880d681SAndroid Build Coastguard Worker
164*9880d681SAndroid Build Coastguard Worker typedef Function<GetSymbolAddressId, TargetAddress(std::string SymbolName)>
165*9880d681SAndroid Build Coastguard Worker GetSymbolAddress;
166*9880d681SAndroid Build Coastguard Worker
167*9880d681SAndroid Build Coastguard Worker /// GetRemoteInfo result is (Triple, PointerSize, PageSize, TrampolineSize,
168*9880d681SAndroid Build Coastguard Worker /// IndirectStubsSize).
169*9880d681SAndroid Build Coastguard Worker typedef Function<GetRemoteInfoId, std::tuple<std::string, uint32_t, uint32_t,
170*9880d681SAndroid Build Coastguard Worker uint32_t, uint32_t>()>
171*9880d681SAndroid Build Coastguard Worker GetRemoteInfo;
172*9880d681SAndroid Build Coastguard Worker
173*9880d681SAndroid Build Coastguard Worker typedef Function<ReadMemId,
174*9880d681SAndroid Build Coastguard Worker std::vector<char>(TargetAddress Src, uint64_t Size)>
175*9880d681SAndroid Build Coastguard Worker ReadMem;
176*9880d681SAndroid Build Coastguard Worker
177*9880d681SAndroid Build Coastguard Worker typedef Function<RegisterEHFramesId, void(TargetAddress Addr, uint32_t Size)>
178*9880d681SAndroid Build Coastguard Worker RegisterEHFrames;
179*9880d681SAndroid Build Coastguard Worker
180*9880d681SAndroid Build Coastguard Worker typedef Function<ReserveMemId,
181*9880d681SAndroid Build Coastguard Worker TargetAddress(ResourceIdMgr::ResourceId AllocID,
182*9880d681SAndroid Build Coastguard Worker uint64_t Size, uint32_t Align)>
183*9880d681SAndroid Build Coastguard Worker ReserveMem;
184*9880d681SAndroid Build Coastguard Worker
185*9880d681SAndroid Build Coastguard Worker typedef Function<RequestCompileId,
186*9880d681SAndroid Build Coastguard Worker TargetAddress(TargetAddress TrampolineAddr)>
187*9880d681SAndroid Build Coastguard Worker RequestCompile;
188*9880d681SAndroid Build Coastguard Worker
189*9880d681SAndroid Build Coastguard Worker typedef Function<SetProtectionsId,
190*9880d681SAndroid Build Coastguard Worker void(ResourceIdMgr::ResourceId AllocID, TargetAddress Dst,
191*9880d681SAndroid Build Coastguard Worker uint32_t ProtFlags)>
192*9880d681SAndroid Build Coastguard Worker SetProtections;
193*9880d681SAndroid Build Coastguard Worker
194*9880d681SAndroid Build Coastguard Worker typedef Function<TerminateSessionId, void()> TerminateSession;
195*9880d681SAndroid Build Coastguard Worker
196*9880d681SAndroid Build Coastguard Worker typedef Function<WriteMemId, void(DirectBufferWriter DB)> WriteMem;
197*9880d681SAndroid Build Coastguard Worker
198*9880d681SAndroid Build Coastguard Worker typedef Function<WritePtrId, void(TargetAddress Dst, TargetAddress Val)>
199*9880d681SAndroid Build Coastguard Worker WritePtr;
200*9880d681SAndroid Build Coastguard Worker };
201*9880d681SAndroid Build Coastguard Worker
202*9880d681SAndroid Build Coastguard Worker } // end namespace remote
203*9880d681SAndroid Build Coastguard Worker } // end namespace orc
204*9880d681SAndroid Build Coastguard Worker } // end namespace llvm
205*9880d681SAndroid Build Coastguard Worker
206*9880d681SAndroid Build Coastguard Worker #endif
207