LLVM  14.0.0git
OrcRPCTPCServer.h
Go to the documentation of this file.
1 //===-- OrcRPCTPCServer.h -- OrcRPCTargetProcessControl Server --*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // OrcRPCTargetProcessControl server class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_ORCRPCTPCSERVER_H
14 #define LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_ORCRPCTPCSERVER_H
15 
16 #include "llvm/ADT/BitmaskEnum.h"
24 #include "llvm/Support/Host.h"
26 #include "llvm/Support/Memory.h"
27 #include "llvm/Support/Process.h"
28 
29 #include <atomic>
30 
31 namespace llvm {
32 namespace orc {
33 
34 namespace orcrpctpc {
35 
37  std::string Triple;
38  unsigned PageSize;
41 };
42 
47 };
48 
49 using ReserveMemRequest = std::vector<ReserveMemRequestElement>;
50 
55 };
56 
57 using ReserveMemResult = std::vector<ReserveMemResultElement>;
58 
63 };
64 
66  std::vector<ReleaseOrFinalizeMemRequestElement>;
67 
68 } // end namespace orcrpctpc
69 
70 namespace shared {
71 
73 public:
74  static const char *getName() { return "WrapperFunctionResult"; }
75 };
76 
77 template <typename ChannelT>
80  std::enable_if_t<std::is_base_of<RawByteChannel, ChannelT>::value>> {
81 public:
82  static Error serialize(ChannelT &C, const WrapperFunctionResult &E) {
83  if (auto Err = serializeSeq(C, static_cast<uint64_t>(E.size())))
84  return Err;
85  if (E.size() == 0)
86  return Error::success();
87  return C.appendBytes(E.data(), E.size());
88  }
89 
90  static Error deserialize(ChannelT &C, WrapperFunctionResult &E) {
91  uint64_t Size;
92  if (auto Err = deserializeSeq(C, Size))
93  return Err;
94 
96 
97  if (auto Err = C.readBytes(Tmp.data(), Tmp.size()))
98  return Err;
99 
100  E = std::move(Tmp);
101 
102  return Error::success();
103  }
104 };
105 
106 template <> class SerializationTypeName<tpctypes::UInt8Write> {
107 public:
108  static const char *getName() { return "UInt8Write"; }
109 };
110 
111 template <> class SerializationTypeName<tpctypes::UInt16Write> {
112 public:
113  static const char *getName() { return "UInt16Write"; }
114 };
115 
116 template <> class SerializationTypeName<tpctypes::UInt32Write> {
117 public:
118  static const char *getName() { return "UInt32Write"; }
119 };
120 
121 template <> class SerializationTypeName<tpctypes::UInt64Write> {
122 public:
123  static const char *getName() { return "UInt64Write"; }
124 };
125 
126 template <> class SerializationTypeName<tpctypes::BufferWrite> {
127 public:
128  static const char *getName() { return "BufferWrite"; }
129 };
130 
131 template <> class SerializationTypeName<orcrpctpc::ReserveMemRequestElement> {
132 public:
133  static const char *getName() { return "ReserveMemRequestElement"; }
134 };
135 
136 template <> class SerializationTypeName<orcrpctpc::ReserveMemResultElement> {
137 public:
138  static const char *getName() { return "ReserveMemResultElement"; }
139 };
140 
141 template <>
142 class SerializationTypeName<orcrpctpc::ReleaseOrFinalizeMemRequestElement> {
143 public:
144  static const char *getName() { return "ReleaseOrFinalizeMemRequestElement"; }
145 };
146 
147 template <> class SerializationTypeName<orcrpctpc::ExecutorProcessInfo> {
148 public:
149  static const char *getName() { return "ExecutorProcessInfo"; }
150 };
151 
152 template <typename ChannelT, typename WriteT>
154  ChannelT, WriteT, WriteT,
155  std::enable_if_t<std::is_same<WriteT, tpctypes::UInt8Write>::value ||
156  std::is_same<WriteT, tpctypes::UInt16Write>::value ||
157  std::is_same<WriteT, tpctypes::UInt32Write>::value ||
158  std::is_same<WriteT, tpctypes::UInt64Write>::value>> {
159 public:
160  static Error serialize(ChannelT &C, const WriteT &W) {
161  return serializeSeq(C, W.Address, W.Value);
162  }
163  static Error deserialize(ChannelT &C, WriteT &W) {
164  return deserializeSeq(C, W.Address, W.Value);
165  }
166 };
167 
168 template <typename ChannelT>
170  ChannelT, tpctypes::BufferWrite, tpctypes::BufferWrite,
171  std::enable_if_t<std::is_base_of<RawByteChannel, ChannelT>::value>> {
172 public:
173  static Error serialize(ChannelT &C, const tpctypes::BufferWrite &W) {
174  uint64_t Size = W.Buffer.size();
175  if (auto Err = serializeSeq(C, W.Address, Size))
176  return Err;
177 
178  return C.appendBytes(W.Buffer.data(), Size);
179  }
180  static Error deserialize(ChannelT &C, tpctypes::BufferWrite &W) {
182  uint64_t Size;
183 
184  if (auto Err = deserializeSeq(C, Address, Size))
185  return Err;
186 
187  char *Buffer = jitTargetAddressToPointer<char *>(Address);
188 
189  if (auto Err = C.readBytes(Buffer, Size))
190  return Err;
191 
192  W = {Address, StringRef(Buffer, Size)};
193  return Error::success();
194  }
195 };
196 
197 template <typename ChannelT>
198 class SerializationTraits<ChannelT, orcrpctpc::ReserveMemRequestElement> {
199 public:
200  static Error serialize(ChannelT &C,
202  return serializeSeq(C, static_cast<uint8_t>(E.Prot), E.Size, E.Alignment);
203  }
204 
205  static Error deserialize(ChannelT &C,
207  return deserializeSeq(C, *reinterpret_cast<uint8_t *>(&E.Prot), E.Size,
208  E.Alignment);
209  }
210 };
211 
212 template <typename ChannelT>
213 class SerializationTraits<ChannelT, orcrpctpc::ReserveMemResultElement> {
214 public:
215  static Error serialize(ChannelT &C,
217  return serializeSeq(C, static_cast<uint8_t>(E.Prot), E.Address,
218  E.AllocatedSize);
219  }
220 
222  return deserializeSeq(C, *reinterpret_cast<uint8_t *>(&E.Prot), E.Address,
223  E.AllocatedSize);
224  }
225 };
226 
227 template <typename ChannelT>
228 class SerializationTraits<ChannelT,
229  orcrpctpc::ReleaseOrFinalizeMemRequestElement> {
230 public:
231  static Error
232  serialize(ChannelT &C,
234  return serializeSeq(C, static_cast<uint8_t>(E.Prot), E.Address, E.Size);
235  }
236 
237  static Error deserialize(ChannelT &C,
239  return deserializeSeq(C, *reinterpret_cast<uint8_t *>(&E.Prot), E.Address,
240  E.Size);
241  }
242 };
243 
244 template <typename ChannelT>
245 class SerializationTraits<ChannelT, orcrpctpc::ExecutorProcessInfo> {
246 public:
247  static Error serialize(ChannelT &C,
248  const orcrpctpc::ExecutorProcessInfo &EPI) {
249  return serializeSeq(C, EPI.Triple, EPI.PageSize, EPI.DispatchFuncAddr,
250  EPI.DispatchCtxAddr);
251  }
252 
254  return deserializeSeq(C, EPI.Triple, EPI.PageSize, EPI.DispatchFuncAddr,
255  EPI.DispatchCtxAddr);
256  }
257 };
258 
259 } // end namespace shared
260 
261 namespace orcrpctpc {
262 
263 using RemoteSymbolLookupSet = std::vector<std::pair<std::string, bool>>;
264 using RemoteLookupRequest =
265  std::pair<tpctypes::DylibHandle, RemoteSymbolLookupSet>;
266 
268  : public shared::RPCFunction<GetExecutorProcessInfo,
269  orcrpctpc::ExecutorProcessInfo()> {
270 public:
271  static const char *getName() { return "GetJITDispatchInfo"; }
272 };
273 
275  : public shared::RPCFunction<ReserveMem, Expected<ReserveMemResult>(
276  ReserveMemRequest)> {
277 public:
278  static const char *getName() { return "ReserveMem"; }
279 };
280 
282  : public shared::RPCFunction<FinalizeMem,
283  Error(ReleaseOrFinalizeMemRequest)> {
284 public:
285  static const char *getName() { return "FinalizeMem"; }
286 };
287 
289  : public shared::RPCFunction<ReleaseMem,
290  Error(ReleaseOrFinalizeMemRequest)> {
291 public:
292  static const char *getName() { return "ReleaseMem"; }
293 };
294 
296  : public shared::RPCFunction<WriteUInt8s,
297  Error(std::vector<tpctypes::UInt8Write>)> {
298 public:
299  static const char *getName() { return "WriteUInt8s"; }
300 };
301 
303  : public shared::RPCFunction<WriteUInt16s,
304  Error(std::vector<tpctypes::UInt16Write>)> {
305 public:
306  static const char *getName() { return "WriteUInt16s"; }
307 };
308 
310  : public shared::RPCFunction<WriteUInt32s,
311  Error(std::vector<tpctypes::UInt32Write>)> {
312 public:
313  static const char *getName() { return "WriteUInt32s"; }
314 };
315 
317  : public shared::RPCFunction<WriteUInt64s,
318  Error(std::vector<tpctypes::UInt64Write>)> {
319 public:
320  static const char *getName() { return "WriteUInt64s"; }
321 };
322 
324  : public shared::RPCFunction<WriteBuffers,
325  Error(std::vector<tpctypes::BufferWrite>)> {
326 public:
327  static const char *getName() { return "WriteBuffers"; }
328 };
329 
331  : public shared::RPCFunction<LoadDylib, Expected<tpctypes::DylibHandle>(
332  std::string DylibPath)> {
333 public:
334  static const char *getName() { return "LoadDylib"; }
335 };
336 
338  : public shared::RPCFunction<LookupSymbols,
339  Expected<std::vector<tpctypes::LookupResult>>(
340  std::vector<RemoteLookupRequest>)> {
341 public:
342  static const char *getName() { return "LookupSymbols"; }
343 };
344 
345 class RunMain
346  : public shared::RPCFunction<RunMain,
347  int64_t(JITTargetAddress MainAddr,
348  std::vector<std::string> Args)> {
349 public:
350  static const char *getName() { return "RunMain"; }
351 };
352 
354  : public shared::RPCFunction<RunWrapper,
355  shared::WrapperFunctionResult(
356  JITTargetAddress, std::vector<uint8_t>)> {
357 public:
358  static const char *getName() { return "RunWrapper"; }
359 };
360 
361 class CloseConnection : public shared::RPCFunction<CloseConnection, void()> {
362 public:
363  static const char *getName() { return "CloseConnection"; }
364 };
365 
366 } // end namespace orcrpctpc
367 
368 /// TargetProcessControl for a process connected via an ORC RPC Endpoint.
369 template <typename RPCEndpointT> class OrcRPCTPCServer {
370 private:
372 
373 public:
374  /// Create an OrcRPCTPCServer from the given endpoint.
375  OrcRPCTPCServer(RPCEndpointT &EP) : EP(EP) {
376 
377  TripleStr = sys::getProcessTriple();
379 
380  EP.template addHandler<orcrpctpc::GetExecutorProcessInfo>(
381  *this, &ThisT::getExecutorProcessInfo);
382  EP.template addHandler<orcrpctpc::ReserveMem>(*this, &ThisT::reserveMemory);
383  EP.template addHandler<orcrpctpc::FinalizeMem>(*this,
384  &ThisT::finalizeMemory);
385  EP.template addHandler<orcrpctpc::ReleaseMem>(*this, &ThisT::releaseMemory);
386 
387  EP.template addHandler<orcrpctpc::WriteUInt8s>(
388  handleWriteUInt<tpctypes::UInt8Write>);
389  EP.template addHandler<orcrpctpc::WriteUInt16s>(
390  handleWriteUInt<tpctypes::UInt16Write>);
391  EP.template addHandler<orcrpctpc::WriteUInt32s>(
392  handleWriteUInt<tpctypes::UInt32Write>);
393  EP.template addHandler<orcrpctpc::WriteUInt64s>(
394  handleWriteUInt<tpctypes::UInt64Write>);
395  EP.template addHandler<orcrpctpc::WriteBuffers>(handleWriteBuffer);
396 
397  EP.template addHandler<orcrpctpc::LoadDylib>(*this, &ThisT::loadDylib);
398  EP.template addHandler<orcrpctpc::LookupSymbols>(*this,
399  &ThisT::lookupSymbols);
400 
401  EP.template addHandler<orcrpctpc::RunMain>(*this, &ThisT::runMain);
402  EP.template addHandler<orcrpctpc::RunWrapper>(*this, &ThisT::runWrapper);
403 
404  EP.template addHandler<orcrpctpc::CloseConnection>(*this,
405  &ThisT::closeConnection);
406  }
407 
408  /// Set the ProgramName to be used as the first argv element when running
409  /// functions via runAsMain.
410  void setProgramName(Optional<std::string> ProgramName = None) {
411  this->ProgramName = std::move(ProgramName);
412  }
413 
414  /// Get the RPC endpoint for this server.
415  RPCEndpointT &getEndpoint() { return EP; }
416 
417  /// Run the server loop.
418  Error run() {
419  while (!Finished) {
420  if (auto Err = EP.handleOne())
421  return Err;
422  }
423  return Error::success();
424  }
425 
428  return EP.template callB<orcrpctpc::RunWrapper>(
429  FunctionId,
430  ArrayRef<uint8_t>(reinterpret_cast<const uint8_t *>(ArgBuffer.data()),
431  ArgBuffer.size()));
432  }
433 
434 private:
436  jitDispatchViaOrcRPCTPCServer(void *Ctx, const void *FnTag, const char *Data,
437  size_t Size) {
438  assert(Ctx && "Attempt to dispatch with null context ptr");
439  auto R = static_cast<ThisT *>(Ctx)->runWrapperInJIT(
440  pointerToJITTargetAddress(FnTag), {Data, Size});
441  if (!R) {
442  auto ErrMsg = toString(R.takeError());
444  .release();
445  }
446  return R->release();
447  }
448 
449  orcrpctpc::ExecutorProcessInfo getExecutorProcessInfo() {
450  return {TripleStr, static_cast<uint32_t>(PageSize),
451  pointerToJITTargetAddress(jitDispatchViaOrcRPCTPCServer),
453  }
454 
455  template <typename WriteT>
456  static void handleWriteUInt(const std::vector<WriteT> &Ws) {
457  using ValueT = decltype(std::declval<WriteT>().Value);
458  for (auto &W : Ws)
459  *jitTargetAddressToPointer<ValueT *>(W.Address) = W.Value;
460  }
461 
462  static void handleWriteBuffer(const std::vector<tpctypes::BufferWrite> &Ws) {
463  for (auto &W : Ws) {
464  memcpy(jitTargetAddressToPointer<char *>(W.Address), W.Buffer.data(),
465  W.Buffer.size());
466  }
467  }
468 
469  Expected<orcrpctpc::ReserveMemResult>
470  reserveMemory(const orcrpctpc::ReserveMemRequest &Request) {
473 
474  uint64_t TotalSize = 0;
475 
476  for (const auto &E : Request) {
477  uint64_t Size = alignTo(E.Size, PageSize);
478  uint16_t Align = E.Alignment;
479 
480  if ((Align > PageSize) || (PageSize % Align))
481  return make_error<StringError>(
482  "Page alignmen does not satisfy requested alignment",
484 
485  TotalSize += Size;
486  }
487 
488  // Allocate memory slab.
489  std::error_code EC;
490  auto MB = sys::Memory::allocateMappedMemory(TotalSize, nullptr, PF, EC);
491  if (EC)
492  return make_error<StringError>("Unable to allocate memory: " +
493  EC.message(),
495 
496  // Zero-fill the whole thing.
497  memset(MB.base(), 0, MB.allocatedSize());
498 
499  // Carve up sections to return.
500  uint64_t SectionBase = 0;
501  for (const auto &E : Request) {
502  uint64_t SectionSize = alignTo(E.Size, PageSize);
503  Allocs.push_back({E.Prot,
504  pointerToJITTargetAddress(MB.base()) + SectionBase,
505  SectionSize});
506  SectionBase += SectionSize;
507  }
508 
509  return Allocs;
510  }
511 
512  Error finalizeMemory(const orcrpctpc::ReleaseOrFinalizeMemRequest &FMR) {
513  for (const auto &E : FMR) {
514  sys::MemoryBlock MB(jitTargetAddressToPointer<void *>(E.Address), E.Size);
515 
516  auto PF = tpctypes::fromWireProtectionFlags(E.Prot);
517  if (auto EC =
518  sys::Memory::protectMappedMemory(MB, static_cast<unsigned>(PF)))
519  return make_error<StringError>("error protecting memory: " +
520  EC.message(),
522  }
523  return Error::success();
524  }
525 
526  Error releaseMemory(const orcrpctpc::ReleaseOrFinalizeMemRequest &RMR) {
527  for (const auto &E : RMR) {
528  sys::MemoryBlock MB(jitTargetAddressToPointer<void *>(E.Address), E.Size);
529 
530  if (auto EC = sys::Memory::releaseMappedMemory(MB))
531  return make_error<StringError>("error release memory: " + EC.message(),
533  }
534  return Error::success();
535  }
536 
537  Expected<tpctypes::DylibHandle> loadDylib(const std::string &Path) {
538  std::string ErrMsg;
539  const char *DLPath = !Path.empty() ? Path.c_str() : nullptr;
540  auto DL = sys::DynamicLibrary::getPermanentLibrary(DLPath, &ErrMsg);
541  if (!DL.isValid())
542  return make_error<StringError>(std::move(ErrMsg),
544 
545  tpctypes::DylibHandle H = Dylibs.size();
546  Dylibs[H] = std::move(DL);
547  return H;
548  }
549 
550  Expected<std::vector<tpctypes::LookupResult>>
551  lookupSymbols(const std::vector<orcrpctpc::RemoteLookupRequest> &Request) {
552  std::vector<tpctypes::LookupResult> Result;
553 
554  for (const auto &E : Request) {
555  auto I = Dylibs.find(E.first);
556  if (I == Dylibs.end())
557  return make_error<StringError>("Unrecognized handle",
559  auto &DL = I->second;
560  Result.push_back({});
561 
562  for (const auto &KV : E.second) {
563  auto &SymString = KV.first;
564  bool WeakReference = KV.second;
565 
566  const char *Sym = SymString.c_str();
567 #ifdef __APPLE__
568  if (*Sym == '_')
569  ++Sym;
570 #endif
571 
572  void *Addr = DL.getAddressOfSymbol(Sym);
573  if (!Addr && !WeakReference)
574  return make_error<StringError>(Twine("Missing definition for ") + Sym,
576 
577  Result.back().push_back(pointerToJITTargetAddress(Addr));
578  }
579  }
580 
581  return Result;
582  }
583 
584  int64_t runMain(JITTargetAddress MainFnAddr,
585  const std::vector<std::string> &Args) {
586  Optional<StringRef> ProgramNameOverride;
587  if (ProgramName)
588  ProgramNameOverride = *ProgramName;
589 
590  return runAsMain(
591  jitTargetAddressToFunction<int (*)(int, char *[])>(MainFnAddr), Args,
592  ProgramNameOverride);
593  }
594 
595  shared::WrapperFunctionResult
596  runWrapper(JITTargetAddress WrapperFnAddr,
597  const std::vector<uint8_t> &ArgBuffer) {
598  using WrapperFnTy = shared::detail::CWrapperFunctionResult (*)(
599  const char *Data, uint64_t Size);
600  auto *WrapperFn = jitTargetAddressToFunction<WrapperFnTy>(WrapperFnAddr);
601  return WrapperFn(reinterpret_cast<const char *>(ArgBuffer.data()),
602  ArgBuffer.size());
603  }
604 
605  void closeConnection() { Finished = true; }
606 
607  std::string TripleStr;
608  uint64_t PageSize = 0;
609  Optional<std::string> ProgramName;
610  RPCEndpointT &EP;
611  std::atomic<bool> Finished{false};
612  DenseMap<tpctypes::DylibHandle, sys::DynamicLibrary> Dylibs;
613 };
614 
615 } // end namespace orc
616 } // end namespace llvm
617 
618 #endif // LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_ORCRPCTPCSERVER_H
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::orc::orcrpctpc::ReserveMemResult
std::vector< ReserveMemResultElement > ReserveMemResult
Definition: OrcRPCTPCServer.h:57
llvm::orc::orcrpctpc::RemoteLookupRequest
std::pair< tpctypes::DylibHandle, RemoteSymbolLookupSet > RemoteLookupRequest
Definition: OrcRPCTPCServer.h:265
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:148
llvm::orc::orcrpctpc::CloseConnection::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:363
llvm::orc::orcrpctpc::RunWrapper::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:358
llvm::orc::orcrpctpc::ReleaseOrFinalizeMemRequestElement
Definition: OrcRPCTPCServer.h:59
llvm::sys::Memory::MF_READ
@ MF_READ
Definition: Memory.h:55
llvm::orc::orcrpctpc::ExecutorProcessInfo::DispatchFuncAddr
JITTargetAddress DispatchFuncAddr
Definition: OrcRPCTPCServer.h:39
llvm::orc::shared::WrapperFunctionResult::release
detail::CWrapperFunctionResult release()
Release ownership of the contained detail::CWrapperFunctionResult.
Definition: WrapperFunctionUtils.h:85
TargetProcessControlTypes.h
MathExtras.h
llvm::orc::orcrpctpc::ReleaseOrFinalizeMemRequestElement::Address
JITTargetAddress Address
Definition: OrcRPCTPCServer.h:61
llvm::orc::shared::SerializationTypeName< tpctypes::UInt64Write >::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:123
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::sys::Memory::MF_WRITE
@ MF_WRITE
Definition: Memory.h:56
llvm::lltok::Error
@ Error
Definition: LLToken.h:21
llvm::orc::shared::SerializationTypeName< tpctypes::UInt16Write >::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:113
llvm::orc::shared::deserializeSeq
Error deserializeSeq(ChannelT &C, ArgTs &...Args)
Definition: Serialization.h:313
llvm::toString
std::string toString(Error E)
Write all error messages (if any) in E to a string.
Definition: Error.h:1020
Host.h
llvm::orc::tpctypes::UInt64Write
UIntWrite< uint64_t > UInt64Write
Describes a write to a uint64_t.
Definition: TargetProcessControlTypes.h:99
llvm::orc::tpctypes::WireProtectionFlags
WireProtectionFlags
Definition: TargetProcessControlTypes.h:30
llvm::RISCVFenceField::W
@ W
Definition: RISCVBaseInfo.h:194
llvm::orc::OrcRPCTPCServer
TargetProcessControl for a process connected via an ORC RPC Endpoint.
Definition: OrcRPCTPCServer.h:369
llvm::orc::orcrpctpc::GetExecutorProcessInfo::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:271
llvm::orc::shared::WrapperFunctionResult::allocate
static WrapperFunctionResult allocate(size_t Size)
Create a WrapperFunctionResult with the given size and return a pointer to the underlying memory.
Definition: WrapperFunctionUtils.h:119
llvm::orc::orcrpctpc::ReleaseOrFinalizeMemRequest
std::vector< ReleaseOrFinalizeMemRequestElement > ReleaseOrFinalizeMemRequest
Definition: OrcRPCTPCServer.h:66
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::sys::Memory::allocateMappedMemory
static MemoryBlock allocateMappedMemory(size_t NumBytes, const MemoryBlock *const NearBlock, unsigned Flags, std::error_code &EC)
This method allocates a block of memory that is suitable for loading dynamically generated code (e....
llvm::sys::Memory::releaseMappedMemory
static std::error_code releaseMappedMemory(MemoryBlock &Block)
This method releases a block of memory that was allocated with the allocateMappedMemory method.
llvm::orc::OrcRPCTPCServer::OrcRPCTPCServer
OrcRPCTPCServer(RPCEndpointT &EP)
Create an OrcRPCTPCServer from the given endpoint.
Definition: OrcRPCTPCServer.h:375
llvm::orc::shared::SerializationTraits< ChannelT, WriteT, WriteT, std::enable_if_t< std::is_same< WriteT, tpctypes::UInt8Write >::value||std::is_same< WriteT, tpctypes::UInt16Write >::value||std::is_same< WriteT, tpctypes::UInt32Write >::value||std::is_same< WriteT, tpctypes::UInt64Write >::value > >::deserialize
static Error deserialize(ChannelT &C, WriteT &W)
Definition: OrcRPCTPCServer.h:163
llvm::orc::orcrpctpc::ReserveMemRequestElement
Definition: OrcRPCTPCServer.h:43
llvm::orc::orcrpctpc::WriteUInt16s::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:306
llvm::orc::orcrpctpc::ReleaseMem::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:292
WrapperFunctionUtils.h
DynamicLibrary.h
llvm::orc::orcrpctpc::ReserveMemRequestElement::Prot
tpctypes::WireProtectionFlags Prot
Definition: OrcRPCTPCServer.h:44
llvm::Optional< std::string >
llvm::orc::shared::serializeSeq
Error serializeSeq(ChannelT &C, ArgTs &&...Args)
Definition: Serialization.h:307
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::orc::shared::SerializationTypeName< orcrpctpc::ReleaseOrFinalizeMemRequestElement >::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:144
llvm::ArrayRef::data
const T * data() const
Definition: ArrayRef.h:162
llvm::orc::shared::RPCFunction
Definition: RPCUtils.h:142
llvm::orc::orcrpctpc::RunMain
Definition: OrcRPCTPCServer.h:345
llvm::orc::shared::SerializationTraits< ChannelT, orcrpctpc::ExecutorProcessInfo >::serialize
static Error serialize(ChannelT &C, const orcrpctpc::ExecutorProcessInfo &EPI)
Definition: OrcRPCTPCServer.h:247
llvm::orc::shared::SerializationTraits
The SerializationTraits<ChannelT, T> class describes how to serialize and deserialize an instance of ...
Definition: Serialization.h:242
Process.h
llvm::orc::orcrpctpc::GetExecutorProcessInfo
Definition: OrcRPCTPCServer.h:267
llvm::orc::shared::SerializationTraits< ChannelT, orcrpctpc::ReserveMemResultElement >::deserialize
static Error deserialize(ChannelT &C, orcrpctpc::ReserveMemResultElement &E)
Definition: OrcRPCTPCServer.h:221
llvm::orc::shared::SerializationTraits< ChannelT, orcrpctpc::ReleaseOrFinalizeMemRequestElement >::deserialize
static Error deserialize(ChannelT &C, orcrpctpc::ReleaseOrFinalizeMemRequestElement &E)
Definition: OrcRPCTPCServer.h:237
llvm::orc::orcrpctpc::WriteUInt32s::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:313
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::orc::tpctypes::fromWireProtectionFlags
sys::Memory::ProtectionFlags fromWireProtectionFlags(WireProtectionFlags WPF)
Definition: TargetProcessControlTypes.h:52
llvm::orc::orcrpctpc::ReserveMem::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:278
llvm::orc::orcrpctpc::ReserveMemRequestElement::Size
uint64_t Size
Definition: OrcRPCTPCServer.h:45
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::sys::DynamicLibrary::getPermanentLibrary
static DynamicLibrary getPermanentLibrary(const char *filename, std::string *errMsg=nullptr)
This function permanently loads the dynamic library at the given path.
Definition: DynamicLibrary.cpp:146
llvm::orc::orcrpctpc::FinalizeMem
Definition: OrcRPCTPCServer.h:281
llvm::ms_demangle::QualifierMangleMode::Result
@ Result
llvm::orc::shared::detail::CWrapperFunctionResult
Definition: WrapperFunctionUtils.h:37
llvm::orc::shared::SerializationTypeName< orcrpctpc::ReserveMemRequestElement >::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:133
llvm::orc::runAsMain
int runAsMain(int(*Main)(int, char *[]), ArrayRef< std::string > Args, Optional< StringRef > ProgramName=None)
Run a main function, returning the result.
Definition: TargetExecutionUtils.cpp:16
llvm::orc::orcrpctpc::RunMain::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:350
llvm::orc::shared::SerializationTraits< ChannelT, WrapperFunctionResult, WrapperFunctionResult, std::enable_if_t< std::is_base_of< RawByteChannel, ChannelT >::value > >::serialize
static Error serialize(ChannelT &C, const WrapperFunctionResult &E)
Definition: OrcRPCTPCServer.h:82
llvm::orc::tpctypes::DylibHandle
JITTargetAddress DylibHandle
A handle used to represent a loaded dylib in the target process.
Definition: TargetProcessControlTypes.h:113
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
llvm::orc::shared::SerializationTraits< ChannelT, WriteT, WriteT, std::enable_if_t< std::is_same< WriteT, tpctypes::UInt8Write >::value||std::is_same< WriteT, tpctypes::UInt16Write >::value||std::is_same< WriteT, tpctypes::UInt32Write >::value||std::is_same< WriteT, tpctypes::UInt64Write >::value > >::serialize
static Error serialize(ChannelT &C, const WriteT &W)
Definition: OrcRPCTPCServer.h:160
llvm::orc::shared::SerializationTypeName< orcrpctpc::ReserveMemResultElement >::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:138
FormatVariadic.h
llvm::orc::orcrpctpc::LoadDylib
Definition: OrcRPCTPCServer.h:330
llvm::orc::shared::SerializationTraits< ChannelT, orcrpctpc::ReserveMemResultElement >::serialize
static Error serialize(ChannelT &C, const orcrpctpc::ReserveMemResultElement &E)
Definition: OrcRPCTPCServer.h:215
llvm::orc::tpctypes::BufferWrite
Describes a write to a buffer.
Definition: TargetProcessControlTypes.h:103
llvm::orc::orcrpctpc::ExecutorProcessInfo::DispatchCtxAddr
JITTargetAddress DispatchCtxAddr
Definition: OrcRPCTPCServer.h:40
llvm::orc::shared::SerializationTypeName< tpctypes::UInt8Write >::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:108
llvm::orc::orcrpctpc::WriteBuffers
Definition: OrcRPCTPCServer.h:323
llvm::orc::orcrpctpc::ReleaseOrFinalizeMemRequestElement::Size
uint64_t Size
Definition: OrcRPCTPCServer.h:62
llvm::orc::orcrpctpc::ExecutorProcessInfo
Definition: OrcRPCTPCServer.h:36
llvm::orc::shared::SerializationTypeName< WrapperFunctionResult >::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:74
llvm::orc::orcrpctpc::WriteBuffers::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:327
llvm::orc::orcrpctpc::ReserveMem
Definition: OrcRPCTPCServer.h:274
llvm::orc::shared::WrapperFunctionResult
C++ wrapper function result: Same as CWrapperFunctionResult but auto-releases memory.
Definition: WrapperFunctionUtils.h:46
llvm::orc::tpctypes::WPF_None
@ WPF_None
Definition: TargetProcessControlTypes.h:31
llvm::orc::orcrpctpc::ReserveMemResultElement::Prot
tpctypes::WireProtectionFlags Prot
Definition: OrcRPCTPCServer.h:52
llvm::orc::orcrpctpc::ReserveMemResultElement::Address
JITTargetAddress Address
Definition: OrcRPCTPCServer.h:53
uint64_t
llvm::orc::orcrpctpc::LookupSymbols::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:342
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:80
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::orc::shared::SerializationTraits< ChannelT, orcrpctpc::ReserveMemRequestElement >::serialize
static Error serialize(ChannelT &C, const orcrpctpc::ReserveMemRequestElement &E)
Definition: OrcRPCTPCServer.h:200
llvm::orc::orcrpctpc::WriteUInt16s
Definition: OrcRPCTPCServer.h:302
llvm::orc::orcrpctpc::LookupSymbols
Definition: OrcRPCTPCServer.h:337
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::HighlightColor::Address
@ Address
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
memcpy
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte uint cast struct s *agg result to sbyte *< sbyte * > sbyte uint cast struct s *memtmp to sbyte *< sbyte * > sbyte uint ret void llc ends up issuing two memcpy or custom lower memcpy(of small size) to be ldmia/stmia. I think option 2 is better but the current register allocator cannot allocate a chunk of registers at a time. A feasible temporary solution is to use specific physical registers at the lowering time for small(<
llvm::codeview::CompileSym2Flags::EC
@ EC
llvm::orc::orcrpctpc::ReserveMemRequest
std::vector< ReserveMemRequestElement > ReserveMemRequest
Definition: OrcRPCTPCServer.h:49
llvm::orc::orcrpctpc::RemoteSymbolLookupSet
std::vector< std::pair< std::string, bool > > RemoteSymbolLookupSet
Definition: OrcRPCTPCServer.h:263
llvm::orc::orcrpctpc::ExecutorProcessInfo::Triple
std::string Triple
Definition: OrcRPCTPCServer.h:37
RPCUtils.h
llvm::orc::tpctypes::UInt8Write
UIntWrite< uint8_t > UInt8Write
Describes a write to a uint8_t.
Definition: TargetProcessControlTypes.h:90
llvm::orc::shared::SerializationTypeName< tpctypes::UInt32Write >::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:118
llvm::ArrayRef< char >
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
BitmaskEnum.h
ValueT
uint32_t
llvm::COFF::SectionSize
@ SectionSize
Definition: COFF.h:61
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::orc::shared::SerializationTypeName< orcrpctpc::ExecutorProcessInfo >::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:149
llvm::orc::tpctypes::UInt32Write
UIntWrite< uint32_t > UInt32Write
Describes a write to a uint32_t.
Definition: TargetProcessControlTypes.h:96
llvm::orc::shared::SerializationTraits< ChannelT, WrapperFunctionResult, WrapperFunctionResult, std::enable_if_t< std::is_base_of< RawByteChannel, ChannelT >::value > >::deserialize
static Error deserialize(ChannelT &C, WrapperFunctionResult &E)
Definition: OrcRPCTPCServer.h:90
llvm::orc::orcrpctpc::CloseConnection
Definition: OrcRPCTPCServer.h:361
Memory.h
llvm::pointerToJITTargetAddress
JITTargetAddress pointerToJITTargetAddress(T *Ptr)
Convert a pointer to a JITTargetAddress.
Definition: JITSymbol.h:69
llvm::orc::shared::SerializationTraits< ChannelT, orcrpctpc::ReleaseOrFinalizeMemRequestElement >::serialize
static Error serialize(ChannelT &C, const orcrpctpc::ReleaseOrFinalizeMemRequestElement &E)
Definition: OrcRPCTPCServer.h:232
llvm::orc::tpctypes::UInt16Write
UIntWrite< uint16_t > UInt16Write
Describes a write to a uint16_t.
Definition: TargetProcessControlTypes.h:93
llvm::orc::shared::SerializationTypeName< tpctypes::BufferWrite >::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:128
llvm::orc::orcrpctpc::FinalizeMem::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:285
llvm::orc::orcrpctpc::ReleaseMem
Definition: OrcRPCTPCServer.h:288
llvm::orc::orcrpctpc::WriteUInt32s
Definition: OrcRPCTPCServer.h:309
llvm::orc::orcrpctpc::WriteUInt8s
Definition: OrcRPCTPCServer.h:295
std
Definition: BitVector.h:838
H
#define H(x, y, z)
Definition: MD5.cpp:58
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:77
uint16_t
llvm::sys::getProcessTriple
std::string getProcessTriple()
getProcessTriple() - Return an appropriate target triple for generating code to be loaded into the cu...
Definition: Host.cpp:1748
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::orc::shared::SerializationTraits< ChannelT, tpctypes::BufferWrite, tpctypes::BufferWrite, std::enable_if_t< std::is_base_of< RawByteChannel, ChannelT >::value > >::deserialize
static Error deserialize(ChannelT &C, tpctypes::BufferWrite &W)
Definition: OrcRPCTPCServer.h:180
llvm::orc::orcrpctpc::ReserveMemResultElement::AllocatedSize
uint64_t AllocatedSize
Definition: OrcRPCTPCServer.h:54
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::orc::shared::SerializationTraits< ChannelT, tpctypes::BufferWrite, tpctypes::BufferWrite, std::enable_if_t< std::is_base_of< RawByteChannel, ChannelT >::value > >::serialize
static Error serialize(ChannelT &C, const tpctypes::BufferWrite &W)
Definition: OrcRPCTPCServer.h:173
llvm::JITTargetAddress
uint64_t JITTargetAddress
Represents an address in the target process's address space.
Definition: JITSymbol.h:42
llvm::orc::orcrpctpc::ReserveMemRequestElement::Alignment
uint64_t Alignment
Definition: OrcRPCTPCServer.h:46
llvm::orc::shared::WrapperFunctionResult::createOutOfBandError
static WrapperFunctionResult createOutOfBandError(const char *Msg)
Create an out-of-band error by copying the given string.
Definition: WrapperFunctionUtils.h:146
llvm::orc::shared::SerializationTraits< ChannelT, orcrpctpc::ReserveMemRequestElement >::deserialize
static Error deserialize(ChannelT &C, orcrpctpc::ReserveMemRequestElement &E)
Definition: OrcRPCTPCServer.h:205
llvm::orc::orcrpctpc::WriteUInt64s
Definition: OrcRPCTPCServer.h:316
RawByteChannel.h
llvm::orc::shared::SerializationTraits< ChannelT, orcrpctpc::ExecutorProcessInfo >::deserialize
static Error deserialize(ChannelT &C, orcrpctpc::ExecutorProcessInfo &EPI)
Definition: OrcRPCTPCServer.h:253
llvm::sys::Memory::protectMappedMemory
static std::error_code protectMappedMemory(const MemoryBlock &Block, unsigned Flags)
This method sets the protection flags for a block of memory to the state specified by /p Flags.
llvm::orc::OrcRPCTPCServer::getEndpoint
RPCEndpointT & getEndpoint()
Get the RPC endpoint for this server.
Definition: OrcRPCTPCServer.h:415
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
llvm::orc::orcrpctpc::ReserveMemResultElement
Definition: OrcRPCTPCServer.h:51
llvm::orc::orcrpctpc::LoadDylib::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:334
llvm::orc::OrcRPCTPCServer::run
Error run()
Run the server loop.
Definition: OrcRPCTPCServer.h:418
TargetExecutionUtils.h
llvm::sys::Process::getPageSizeEstimate
static unsigned getPageSizeEstimate()
Get the process's estimated page size.
Definition: Process.h:62
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:389
llvm::jitTargetAddressToFunction
T jitTargetAddressToFunction(JITTargetAddress Addr)
Convert a JITTargetAddress to a callable function pointer.
Definition: JITSymbol.h:61
llvm::orc::orcrpctpc::WriteUInt8s::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:299
llvm::orc::orcrpctpc::ReleaseOrFinalizeMemRequestElement::Prot
tpctypes::WireProtectionFlags Prot
Definition: OrcRPCTPCServer.h:60
llvm::orc::orcrpctpc::WriteUInt64s::getName
static const char * getName()
Definition: OrcRPCTPCServer.h:320
llvm::orc::OrcRPCTPCServer::runWrapperInJIT
Expected< shared::WrapperFunctionResult > runWrapperInJIT(JITTargetAddress FunctionId, ArrayRef< char > ArgBuffer)
Definition: OrcRPCTPCServer.h:427
llvm::orc::orcrpctpc::RunWrapper
Definition: OrcRPCTPCServer.h:353
llvm::orc::shared::SerializationTypeName
Definition: Serialization.h:27
llvm::orc::orcrpctpc::ExecutorProcessInfo::PageSize
unsigned PageSize
Definition: OrcRPCTPCServer.h:38
llvm::orc::OrcRPCTPCServer::setProgramName
void setProgramName(Optional< std::string > ProgramName=None)
Set the ProgramName to be used as the first argv element when running functions via runAsMain.
Definition: OrcRPCTPCServer.h:410