13#ifndef LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_SIMPLEREMOTEEPCSERVER_H
14#define LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_SIMPLEREMOTEEPCSERVER_H
18#include "llvm/Config/llvm-config.h"
28#include <condition_variable>
49#if LLVM_ENABLE_THREADS
53 void shutdown()
override;
56 std::mutex DispatchMutex;
58 size_t Outstanding = 0;
59 std::condition_variable OutstandingCV;
69 template <
typename T,
typename SPSTagT>
71 std::vector<char> Buffer;
76 assert(
Success &&
"Bootstrap map value serialization failed");
77 BootstrapMap[std::move(
Key)] = std::move(Buffer);
80 std::vector<std::unique_ptr<ExecutorBootstrapService>> &
services() {
83 void setDispatcher(std::unique_ptr<Dispatcher> D) { S.D = std::move(D); }
85 S.ReportError = std::move(ReportError);
93 std::vector<std::unique_ptr<ExecutorBootstrapService>> Services;
98 template <
typename TransportT,
typename... TransportTCtorArgTs>
101 TransportTCtorArgTs &&...TransportTCtorArgs) {
102 auto Server = std::make_unique<SimpleRemoteEPCServer>();
104 if (
auto Err = SetupFunction(S))
105 return std::move(Err);
109 if (!Server->ReportError)
110 Server->ReportError = [](
Error Err) {
115 auto T = TransportT::Create(
116 *Server, std::forward<TransportTCtorArgTs>(TransportTCtorArgs)...);
118 return T.takeError();
119 Server->T = std::move(*T);
120 if (
auto Err = Server->T->start())
121 return std::move(Err);
124 Server->Services = std::move(S.
services());
125 Server->Services.push_back(
126 std::make_unique<rt_bootstrap::SimpleExecutorDylibManager>());
127 for (
auto &Service : Server->Services)
130 if (
auto Err = Server->sendSetupMessage(std::move(S.BootstrapMap),
131 std::move(S.BootstrapSymbols)))
132 return std::move(Err);
133 return std::move(Server);
138 this->ReportError = std::move(ReportError);
150 Error waitForDisconnect();
152 void handleDisconnect(
Error Err)
override;
167 doJITDispatch(
const void *FnTag,
const char *ArgData,
size_t ArgSize);
174 uint64_t getNextSeqNo() {
return NextSeqNo++; }
177 using PendingJITDispatchResultsMap =
178 DenseMap<uint64_t, std::promise<shared::WrapperFunctionBuffer> *>;
180 std::mutex ServerStateMutex;
181 std::condition_variable ShutdownCV;
182 enum { ServerRunning, ServerShuttingDown, ServerShutDown } RunState;
187 bool RemoteHangup =
false;
189 Error ShutdownErr = Error::success();
190 std::unique_ptr<SimpleRemoteEPCTransport>
T;
191 std::unique_ptr<Dispatcher>
D;
192 std::vector<std::unique_ptr<ExecutorBootstrapService>> Services;
193 ReportErrorFunction ReportError;
196 PendingJITDispatchResultsMap PendingJITDispatchResults;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file defines the DenseMap class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
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
friend class SimpleRemoteEPCServer
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 Expected< std::unique_ptr< SimpleRemoteEPCServer > > Create(unique_function< Error(Setup &S)> SetupFunction, TransportTCtorArgTs &&...TransportTCtorArgs)
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 buffer: Same as CWrapperFunctionBuffer but auto-releases memory.
unique_function is a type-erasing functor similar to std::function.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
@ Success
The lock was released successfully.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.