13#ifndef LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_SIMPLEREMOTEEPCSERVER_H
14#define LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_SIMPLEREMOTEEPCSERVER_H
18#include "llvm/Config/llvm-config.h"
27#include <condition_variable>
48#if LLVM_ENABLE_THREADS
52 void shutdown()
override;
55 std::mutex DispatchMutex;
57 size_t Outstanding = 0;
58 std::condition_variable OutstandingCV;
68 std::vector<std::unique_ptr<ExecutorBootstrapService>> &
services() {
73 S.ReportError = std::move(ReportError);
80 std::vector<std::unique_ptr<ExecutorBootstrapService>> Services;
85 template <
typename TransportT,
typename... TransportTCtorArgTs>
88 TransportTCtorArgTs &&...TransportTCtorArgs) {
89 auto Server = std::make_unique<SimpleRemoteEPCServer>();
91 if (
auto Err = SetupFunction(S))
92 return std::move(Err);
96 if (!Server->ReportError)
97 Server->ReportError = [](
Error Err) {
102 auto T = TransportT::Create(
103 *Server, std::forward<TransportTCtorArgTs>(TransportTCtorArgs)...);
105 return T.takeError();
106 Server->T = std::move(*
T);
107 if (
auto Err = Server->T->start())
108 return std::move(Err);
111 Server->Services = std::move(S.
services());
112 Server->Services.push_back(
113 std::make_unique<rt_bootstrap::SimpleExecutorDylibManager>());
114 for (
auto &Service : Server->Services)
117 if (
auto Err = Server->sendSetupMessage(std::move(S.BootstrapSymbols)))
118 return std::move(Err);
119 return std::move(Server);
124 this->ReportError = std::move(ReportError);
152 doJITDispatch(
const void *FnTag,
const char *ArgData,
size_t ArgSize);
159 uint64_t getNextSeqNo() {
return NextSeqNo++; }
162 using PendingJITDispatchResultsMap =
163 DenseMap<uint64_t, std::promise<shared::WrapperFunctionResult> *>;
165 std::mutex ServerStateMutex;
166 std::condition_variable ShutdownCV;
167 enum { ServerRunning, ServerShuttingDown, ServerShutDown } RunState;
169 std::unique_ptr<SimpleRemoteEPCTransport>
T;
170 std::unique_ptr<Dispatcher>
D;
171 std::vector<std::unique_ptr<ExecutorBootstrapService>> Services;
175 PendingJITDispatchResultsMap PendingJITDispatchResults;
176 std::vector<sys::DynamicLibrary> Dylibs;
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file defines the DenseMap class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Represents an address in the executor process.
Dispatches calls to runWrapper.
virtual void shutdown()=0
virtual void dispatch(unique_function< void()> Work)=0
SimpleRemoteEPCServer & server()
void setDispatcher(std::unique_ptr< Dispatcher > D)
std::vector< std::unique_ptr< ExecutorBootstrapService > > & services()
void setErrorReporter(unique_function< void(Error)> ReportError)
StringMap< ExecutorAddr > & bootstrapSymbols()
A simple EPC server implementation.
void setErrorReporter(ReportErrorFunction ReportError)
Set an error reporter for this server.
static StringMap< ExecutorAddr > defaultBootstrapSymbols()
static Expected< std::unique_ptr< SimpleRemoteEPCServer > > Create(unique_function< Error(Setup &S)> SetupFunction, TransportTCtorArgTs &&...TransportTCtorArgs)
Expected< HandleMessageAction > handleMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo, ExecutorAddr TagAddr, SimpleRemoteEPCArgBytesVector ArgBytes) override
Call to handle an incoming message.
void handleDisconnect(Error Err) override
Handle a disconnection from the underlying transport.
Error waitForDisconnect()
unique_function< void(Error)> ReportErrorFunction
C++ wrapper function result: Same as CWrapperFunctionResult but auto-releases memory.
This is an optimization pass for GlobalISel generic memory operations.
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.