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 template <
typename T,
typename SPSTagT>
70 std::vector<char> Buffer;
75 assert(
Success &&
"Bootstrap map value serialization failed");
76 BootstrapMap[std::move(Key)] = std::move(Buffer);
79 std::vector<std::unique_ptr<ExecutorBootstrapService>> &
services() {
84 S.ReportError = std::move(ReportError);
92 std::vector<std::unique_ptr<ExecutorBootstrapService>> Services;
97 template <
typename TransportT,
typename... TransportTCtorArgTs>
100 TransportTCtorArgTs &&...TransportTCtorArgs) {
101 auto Server = std::make_unique<SimpleRemoteEPCServer>();
103 if (
auto Err = SetupFunction(S))
104 return std::move(Err);
108 if (!Server->ReportError)
109 Server->ReportError = [](
Error Err) {
114 auto T = TransportT::Create(
115 *Server, std::forward<TransportTCtorArgTs>(TransportTCtorArgs)...);
117 return T.takeError();
118 Server->T = std::move(*
T);
119 if (
auto Err = Server->T->start())
120 return std::move(Err);
123 Server->Services = std::move(S.
services());
124 Server->Services.push_back(
125 std::make_unique<rt_bootstrap::SimpleExecutorDylibManager>());
126 for (
auto &Service : Server->Services)
129 if (
auto Err = Server->sendSetupMessage(std::move(S.BootstrapMap),
130 std::move(S.BootstrapSymbols)))
131 return std::move(Err);
132 return std::move(Server);
137 this->ReportError = std::move(ReportError);
166 doJITDispatch(
const void *FnTag,
const char *ArgData,
size_t ArgSize);
173 uint64_t getNextSeqNo() {
return NextSeqNo++; }
176 using PendingJITDispatchResultsMap =
177 DenseMap<uint64_t, std::promise<shared::WrapperFunctionResult> *>;
179 std::mutex ServerStateMutex;
180 std::condition_variable ShutdownCV;
181 enum { ServerRunning, ServerShuttingDown, ServerShutDown } RunState;
183 std::unique_ptr<SimpleRemoteEPCTransport>
T;
184 std::unique_ptr<Dispatcher>
D;
185 std::vector<std::unique_ptr<ExecutorBootstrapService>> Services;
189 PendingJITDispatchResultsMap PendingJITDispatchResults;
190 std::vector<sys::DynamicLibrary> Dylibs;
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file defines the DenseMap class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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",...
LLVM Value Representation.
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)
void setBootstrapMapValue(std::string Key, const T &Value)
StringMap< std::vector< char > > & bootstrapMap()
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
A utility class for serializing to a blob from a variadic list.
Output char buffer with overflow check.
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.