File: OrcRemoteTargetRPCAPI.h

package info (click to toggle)
llvm-toolchain-3.9 1%3A3.9.1-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 441,060 kB
  • ctags: 428,777
  • sloc: cpp: 2,546,577; ansic: 538,318; asm: 119,677; objc: 103,316; python: 102,148; sh: 27,847; pascal: 5,626; ml: 5,510; perl: 5,293; lisp: 4,801; makefile: 2,177; xml: 686; cs: 362; php: 212; csh: 117
file content (206 lines) | stat: -rw-r--r-- 6,373 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//===--- 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<char *>(static_cast<uintptr_t>(Dst));

  DBW = DirectBufferWriter(0, Dst, Size);

  return C.readBytes(Addr, Size);
}

class OrcRemoteTargetRPCAPI : public RPC<RPCChannel> {
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<ResourceId> 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<JITFuncId>::InvalidId,
    CallIntVoidId = RPCFunctionIdTraits<JITFuncId>::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<CallIntVoidId, int32_t(TargetAddress Addr)> CallIntVoid;

  typedef Function<CallMainId,
                   int32_t(TargetAddress Addr, std::vector<std::string> Args)>
      CallMain;

  typedef Function<CallVoidVoidId, void(TargetAddress FnAddr)> CallVoidVoid;

  typedef Function<CreateRemoteAllocatorId,
                   void(ResourceIdMgr::ResourceId AllocatorID)>
      CreateRemoteAllocator;

  typedef Function<CreateIndirectStubsOwnerId,
                   void(ResourceIdMgr::ResourceId StubOwnerID)>
      CreateIndirectStubsOwner;

  typedef Function<DeregisterEHFramesId,
                   void(TargetAddress Addr, uint32_t Size)>
      DeregisterEHFrames;

  typedef Function<DestroyRemoteAllocatorId,
                   void(ResourceIdMgr::ResourceId AllocatorID)>
      DestroyRemoteAllocator;

  typedef Function<DestroyIndirectStubsOwnerId,
                   void(ResourceIdMgr::ResourceId StubsOwnerID)>
      DestroyIndirectStubsOwner;

  /// EmitIndirectStubs result is (StubsBase, PtrsBase, NumStubsEmitted).
  typedef Function<EmitIndirectStubsId,
                   std::tuple<TargetAddress, TargetAddress, uint32_t>(
                       ResourceIdMgr::ResourceId StubsOwnerID,
                       uint32_t NumStubsRequired)>
      EmitIndirectStubs;

  typedef Function<EmitResolverBlockId, void()> EmitResolverBlock;

  /// EmitTrampolineBlock result is (BlockAddr, NumTrampolines).
  typedef Function<EmitTrampolineBlockId, std::tuple<TargetAddress, uint32_t>()>
      EmitTrampolineBlock;

  typedef Function<GetSymbolAddressId, TargetAddress(std::string SymbolName)>
      GetSymbolAddress;

  /// GetRemoteInfo result is (Triple, PointerSize, PageSize, TrampolineSize,
  ///                          IndirectStubsSize).
  typedef Function<GetRemoteInfoId, std::tuple<std::string, uint32_t, uint32_t,
                                               uint32_t, uint32_t>()>
      GetRemoteInfo;

  typedef Function<ReadMemId,
                   std::vector<char>(TargetAddress Src, uint64_t Size)>
      ReadMem;

  typedef Function<RegisterEHFramesId, void(TargetAddress Addr, uint32_t Size)>
      RegisterEHFrames;

  typedef Function<ReserveMemId,
                   TargetAddress(ResourceIdMgr::ResourceId AllocID,
                                 uint64_t Size, uint32_t Align)>
      ReserveMem;

  typedef Function<RequestCompileId,
                   TargetAddress(TargetAddress TrampolineAddr)>
      RequestCompile;

  typedef Function<SetProtectionsId,
                   void(ResourceIdMgr::ResourceId AllocID, TargetAddress Dst,
                        uint32_t ProtFlags)>
      SetProtections;

  typedef Function<TerminateSessionId, void()> TerminateSession;

  typedef Function<WriteMemId, void(DirectBufferWriter DB)> WriteMem;

  typedef Function<WritePtrId, void(TargetAddress Dst, TargetAddress Val)>
      WritePtr;
};

} // end namespace remote
} // end namespace orc
} // end namespace llvm

#endif