13 #ifndef LLVM_EXECUTIONENGINE_ORC_REMOTEOBJECTLAYER_H 14 #define LLVM_EXECUTIONENGINE_ORC_REMOTEOBJECTLAYER_H 47 :
public rpc::Function<AddObject, Expected<ObjHandleT>(std::string)> {
49 static const char *
getName() {
return "AddObject"; }
55 static const char *
getName() {
return "RemoveObject"; }
59 :
public rpc::Function<FindSymbol, Expected<RemoteSymbol>(std::string,
62 static const char *
getName() {
return "FindSymbol"; }
67 Expected<RemoteSymbol>(ObjHandleT, std::string,
70 static const char *
getName() {
return "FindSymbolIn"; }
77 static const char *
getName() {
return "EmitAndFinalize"; }
82 Expected<RemoteSymbol>(ObjHandleT, std::string)> {
84 static const char *
getName() {
return "Lookup"; }
89 Expected<RemoteSymbol>(ObjHandleT, std::string)> {
91 static const char *
getName() {
return "LookupInLogicalDylib"; }
95 :
public rpc::Function<ReleaseRemoteSymbol, Error(RemoteSymbolId)> {
97 static const char *
getName() {
return "ReleaseRemoteSymbol"; }
102 Expected<JITTargetAddress>(RemoteSymbolId)> {
104 static const char *
getName() {
return "MaterializeRemoteSymbol"; }
110 template <
typename RPCEndpo
int>
119 Remote.template addHandler<ReleaseRemoteSymbol>(
120 *
this, &ThisT::handleReleaseRemoteSymbol);
121 Remote.template addHandler<MaterializeRemoteSymbol>(
122 *
this, &ThisT::handleMaterializeRemoteSymbol);
150 C.releaseRemoteSymbol(
Id);
155 auto Addr =
C.materializeRemoteSymbol(
Id);
177 [
this](std::unique_ptr<ErrorInfoBase> EIB) {
180 EIB->convertToErrorCode()));
181 return Error(std::move(EIB));
186 return make_error<BadSymbolHandleError>(
Id,
"Remote JIT Symbol");
190 return make_error<RemoteObjectLayerAPI::BadObjectHandleError>(
191 H,
"Bad object handle");
197 auto Id = SymbolIdMgr.getNext();
199 assert(!InUseSymbols.count(
Id) &&
"Symbol id already in use");
200 InUseSymbols.insert(std::make_pair(
Id, std::move(Sym)));
203 return teeLog(std::move(Err));
205 return nullRemoteSymbol();
210 if (RemoteSymOrErr) {
211 auto &RemoteSym = *RemoteSymOrErr;
212 if (RemoteSym == nullRemoteSymbol())
217 [RSM = std::move(RSM)]()
mutable {
return RSM.
materialize(); },
231 if (
auto Err = Remote.template callB<ReleaseRemoteSymbol>(Id))
238 return Remote.template callB<MaterializeRemoteSymbol>(
Id);
243 auto SI = InUseSymbols.find(Id);
244 if (
SI != InUseSymbols.end()) {
245 InUseSymbols.erase(
SI);
248 return teeLog(badRemoteSymbolIdError(Id));
254 auto SI = InUseSymbols.find(Id);
255 if (
SI != InUseSymbols.end()) {
256 auto AddrOrErr =
SI->second.getAddress();
257 InUseSymbols.erase(
SI);
258 SymbolIdMgr.release(Id);
262 return teeLog(AddrOrErr.takeError());
264 return teeLog(badRemoteSymbolIdError(Id));
269 std::map<RemoteSymbolId, JITSymbol> InUseSymbols;
283 template <
typename RPCEndpo
int>
314 "ORCv1 layers (including RemoteObjectClientLayer) are deprecated. Please " 316 "ORCv2 (see docs/ORCv2.rst)");
323 Remote.template addHandler<LookupInLogicalDylib>(
324 *
this, &ThisT::lookupInLogicalDylib);
333 std::shared_ptr<LegacyJITSymbolResolver>
Resolver) {
334 if (
auto HandleOrErr =
335 this->Remote.template callB<AddObject>(ObjBuffer->getBuffer())) {
336 auto &Handle = *HandleOrErr;
338 assert(!Resolvers.count(Handle) &&
"Handle already in use?");
339 Resolvers[Handle] = std::move(Resolver);
342 return HandleOrErr.takeError();
347 return this->Remote.template callB<RemoveObject>(
H);
352 return remoteToJITSymbol(
353 this->Remote.template callB<FindSymbol>(Name,
354 ExportedSymbolsOnly));
359 return remoteToJITSymbol(
360 this->Remote.template callB<FindSymbolIn>(H, Name,
361 ExportedSymbolsOnly));
366 return this->Remote.template callB<EmitAndFinalize>(
H);
372 auto RI = Resolvers.find(H);
373 if (RI != Resolvers.end()) {
374 return this->jitSymbolToRemote(RI->second->findSymbol(Name));
376 return teeLog(badObjectHandleError(H));
380 const std::string &Name) {
381 auto RI = Resolvers.find(H);
382 if (RI != Resolvers.end())
383 return this->jitSymbolToRemote(
384 RI->second->findSymbolInLogicalDylib(Name));
386 return teeLog(badObjectHandleError(H));
390 std::shared_ptr<LegacyJITSymbolResolver>>
400 template <
typename BaseLayerT,
typename RPCEndpo
int>
426 "ORCv1 layers (including RemoteObjectServerLayer) are deprecated. Please " 428 "ORCv2 (see docs/ORCv2.rst)");
431 BaseLayerT &BaseLayer, RPCEndpoint &Remote,
434 BaseLayer(BaseLayer), HandleIdMgr(1) {
437 Remote.template addHandler<AddObject>(*
this, &ThisT::addObject);
438 Remote.template addHandler<RemoveObject>(*
this, &ThisT::removeObject);
439 Remote.template addHandler<FindSymbol>(*
this, &ThisT::findSymbol);
440 Remote.template addHandler<FindSymbolIn>(*
this, &ThisT::findSymbolIn);
441 Remote.template addHandler<EmitAndFinalize>(*
this, &ThisT::emitAndFinalize);
448 StringMemoryBuffer(std::string Buffer)
449 : Buffer(std::move(Buffer)) {
450 init(this->Buffer.data(), this->Buffer.data() + this->Buffer.size(),
454 BufferKind getBufferKind()
const override {
return MemoryBuffer_Malloc; }
460 return remoteToJITSymbol(
461 this->Remote.template callB<Lookup>(Id, Name));
465 return remoteToJITSymbol(
466 this->Remote.template callB<LookupInLogicalDylib>(Id, Name));
470 auto Buffer = std::make_unique<StringMemoryBuffer>(std::move(ObjBuffer));
471 auto Id = HandleIdMgr.getNext();
472 assert(!BaseLayerHandles.count(Id) &&
"Id already in use?");
476 [
this, Id](
const std::string &Name) {
return lookup(Id, Name); },
477 [
this,
Id](
const std::string &
Name) {
478 return lookupInLogicalDylib(Id, Name);
481 if (
auto HandleOrErr =
482 BaseLayer.addObject(std::move(Buffer), std::move(Resolver))) {
483 BaseLayerHandles[
Id] = std::move(*HandleOrErr);
486 return teeLog(HandleOrErr.takeError());
490 auto HI = BaseLayerHandles.find(H);
491 if (
HI != BaseLayerHandles.end()) {
492 if (
auto Err = BaseLayer.removeObject(
HI->second))
493 return teeLog(std::move(Err));
496 return teeLog(badObjectHandleError(H));
500 bool ExportedSymbolsOnly) {
501 if (
auto Sym = BaseLayer.findSymbol(Name, ExportedSymbolsOnly))
502 return this->jitSymbolToRemote(std::move(Sym));
503 else if (
auto Err = Sym.takeError())
504 return teeLog(std::move(Err));
505 return this->nullRemoteSymbol();
509 bool ExportedSymbolsOnly) {
510 auto HI = BaseLayerHandles.find(H);
511 if (
HI != BaseLayerHandles.end()) {
512 if (
auto Sym = BaseLayer.findSymbolIn(
HI->second, Name, ExportedSymbolsOnly))
513 return this->jitSymbolToRemote(std::move(Sym));
514 else if (
auto Err = Sym.takeError())
515 return teeLog(std::move(Err));
516 return this->nullRemoteSymbol();
518 return teeLog(badObjectHandleError(H));
522 auto HI = BaseLayerHandles.find(H);
523 if (
HI != BaseLayerHandles.end()) {
524 if (
auto Err = BaseLayer.emitAndFinalize(
HI->second))
525 return teeLog(std::move(Err));
528 return teeLog(badObjectHandleError(H));
531 BaseLayerT &BaseLayer;
533 std::map<ObjHandleT, typename BaseLayerT::ObjHandleT> BaseLayerHandles;
536 template <
typename RPCEndpo
int>
542 Remote.template addHandler<LookupInLogicalDylib>(
543 *
this, &ThisT::lookupInLogicalDylib);
546 template <
typename BaseLayerT,
typename RPCEndpo
int>
548 BaseLayerT &BaseLayer, RPCEndpoint &Remote,
551 BaseLayer(BaseLayer), HandleIdMgr(1) {
554 Remote.template addHandler<AddObject>(*
this, &ThisT::addObject);
555 Remote.template addHandler<RemoveObject>(*
this, &ThisT::removeObject);
556 Remote.template addHandler<FindSymbol>(*
this, &ThisT::findSymbol);
557 Remote.template addHandler<FindSymbolIn>(*
this, &ThisT::findSymbolIn);
558 Remote.template addHandler<EmitAndFinalize>(*
this, &ThisT::emitAndFinalize);
564 #endif // LLVM_EXECUTIONENGINE_ORC_REMOTEOBJECTLAYER_H
RemoteObjectClientLayer(ORCv1DeprecationAcknowledgement, RPCEndpoint &Remote, std::function< void(Error)> ReportError)
Represents a symbol in the JIT.
This class represents lattice values for constants.
RemoteSymbol nullRemoteSymbol()
Convenience function for getting a null remote symbol value.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
RemoteObjectServerLayer(ORCv1DeprecationAcknowledgement, BaseLayerT &BaseLayer, RPCEndpoint &Remote, std::function< void(Error)> ReportError)
Error badObjectHandleError(ObjHandleT H)
static bool lookup(const GsymReader &GR, DataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr, uint64_t Addr, SourceLocations &SrcLocs, llvm::Error &Err)
A Lookup helper functions.
Optional< std::vector< StOtherPiece > > Other
static const char * getName()
Error takeError()
Take ownership of the stored error.
remote::ResourceIdMgr::ResourceId ObjHandleT
JITSymbolFlags getFlags() const
std::unique_ptr< MemoryBuffer > ObjectPtr
RemoteObjectLayer(RPCEndpoint &Remote, std::function< void(Error)> ReportError)
static int Lookup(ArrayRef< TableEntry > Table, unsigned Opcode)
~RemoteSymbolMaterializer()
Release the remote symbol.
Tagged union holding either a T or a Error.
Error emitAndFinalize(ObjHandleT H)
Immediately emit and finalize the object with the given handle.
static const char * getName()
static const char * getName()
ORCv1DeprecationAcknowledgement
static const char * getName()
JITSymbol remoteToJITSymbol(Expected< RemoteSymbol > RemoteSymOrErr)
Convert an Expected<RemoteSymbol> to a JITSymbol.
initializer< Ty > init(const Ty &Val)
Expected< RemoteSymbol > jitSymbolToRemote(JITSymbol Sym)
Create a RemoteSymbol wrapping the given JITSymbol.
static void LLVM_ATTRIBUTE_NORETURN ReportError(uint64_t StartOffset, const char *ErrorMsg)
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
This class is used as the symbol materializer for JITSymbols returned by RemoteObjectLayerClient/Remo...
RemoteSymbolMaterializer(RemoteObjectLayer &C, RemoteSymbolId Id)
Construct a RemoteSymbolMaterializer for the given RemoteObjectLayer with the given Id...
Error badRemoteSymbolIdError(RemoteSymbolId Id)
static const RemoteSymbolId NullSymbolId
Flags for symbols in the JIT.
remote::ResourceIdMgr::ResourceId RemoteSymbolId
JITSymbol findSymbolIn(ObjHandleT H, StringRef Name, bool ExportedSymbolsOnly)
Search for the given named symbol within the given context.
RPC API needed by RemoteObjectClientLayer and RemoteObjectServerLayer.
std::function< void(Error)> ReportError
Expected< ObjHandleT > addObject(ObjectPtr ObjBuffer, std::shared_ptr< LegacyJITSymbolResolver > Resolver)
Add an object to the JIT.
Template error for missing resources.
JITSymbol findSymbol(StringRef Name, bool ExportedSymbolsOnly)
Search for the given named symbol.
#define LLVM_ATTRIBUTE_DEPRECATED(decl, message)
static ErrorSuccess success()
Create a success value.
std::pair< RemoteSymbolId, JITSymbolFlags > RemoteSymbol
Base class containing common utilities for RemoteObjectClientLayer and RemoteObjectServerLayer.
RemoteSymbolMaterializer(RemoteSymbolMaterializer &&Other)
RemoteObjectServerLayer acts as a server and handling RPC calls for the object layer API from the giv...
static const char * getName()
This interface provides simple read-only access to a block of memory, and provides simple methods for...
static const char * getName()
static const char * getName()
static const char * getName()
Error teeLog(Error Err)
Creates a StringError that contains a copy of Err's log message, then sends that StringError to Repor...
static const ObjHandleT InvalidObjectHandleId
RemoteObjectClientLayer forwards the ORC Object Layer API over an RPC connection. ...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Error removeObject(ObjHandleT H)
Remove the given object from the JIT.
std::shared_ptr< LambdaResolver< DylibLookupFtorT, ExternalLookupFtorT > > createLambdaResolver(DylibLookupFtorT DylibLookupFtor, ExternalLookupFtorT ExternalLookupFtor)
Lightweight error class with error context and mandatory checking.
Error handleErrors(Error E, HandlerTs &&... Hs)
Pass the ErrorInfo(s) contained in E to their respective handlers.
Error takeError()
Move the error field value out of this JITSymbol.
print Print MemDeps of function
static const char * getName()
StringRef - Represent a constant reference to a string, i.e.
Expected< JITTargetAddress > materialize()
Materialize the symbol on the remote and get its address.