LLVM 22.0.0git
SimpleExecutorDylibManager.cpp
Go to the documentation of this file.
1//===--- SimpleExecutorDylibManager.cpp - Executor-side dylib management --===//
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
10
12
14
15#include <future>
16
17#define DEBUG_TYPE "orc"
18
19namespace llvm {
20namespace orc {
21namespace rt_bootstrap {
22
24 assert(Dylibs.empty() && "shutdown not called?");
25}
26
29 if (Mode != 0)
30 return make_error<StringError>("open: non-zero mode bits not yet supported",
32
33 const char *PathCStr = Path.empty() ? nullptr : Path.c_str();
34 std::string ErrMsg;
35
36 auto DL = sys::DynamicLibrary::getPermanentLibrary(PathCStr, &ErrMsg);
37 if (!DL.isValid())
38 return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
39
40 std::lock_guard<std::mutex> Lock(M);
41 auto H = ExecutorAddr::fromPtr(DL.getOSSpecificHandle());
42 Resolvers.push_back(std::make_unique<DylibSymbolResolver>(H));
43 Dylibs.insert(DL.getOSSpecificHandle());
44 return ExecutorAddr::fromPtr(Resolvers.back().get());
45}
46
48
49 DylibSet DS;
50 {
51 std::lock_guard<std::mutex> Lock(M);
52 std::swap(DS, Dylibs);
53 }
54
55 // There is no removal of dylibs at the moment, so nothing to do here.
56 return Error::success();
57}
58
67
69SimpleExecutorDylibManager::openWrapper(const char *ArgData, size_t ArgSize) {
70 return shared::
71 WrapperFunction<rt::SPSSimpleExecutorDylibManagerOpenSignature>::handle(
72 ArgData, ArgSize,
75 .release();
76}
77
79SimpleExecutorDylibManager::resolveWrapper(const char *ArgData,
80 size_t ArgSize) {
81 using ResolveResult = ExecutorResolver::ResolveResult;
84 handle(ArgData, ArgSize,
85 [](ExecutorAddr Obj, RemoteSymbolLookupSet L) -> ResolveResult {
86 using TmpResult =
88 std::promise<TmpResult> P;
89 auto F = P.get_future();
90 Obj.toPtr<ExecutorResolver *>()->resolveAsync(
91 std::move(L),
92 [&](TmpResult R) { P.set_value(std::move(R)); });
93 return F.get();
94 })
95 .release();
96}
97
98} // namespace rt_bootstrap
99} // end namespace orc
100} // end namespace llvm
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define F(x, y, z)
Definition MD5.cpp:55
#define H(x, y, z)
Definition MD5.cpp:57
#define P(N)
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:133
Represents an address in the executor process.
static ExecutorAddr fromPtr(T *Ptr, UnwrapFn &&Unwrap=UnwrapFn())
Create an ExecutorAddr from the given pointer.
std::enable_if_t< std::is_pointer< T >::value, T > toPtr(WrapFn &&Wrap=WrapFn()) const
Cast this ExecutorAddr to a pointer of the given type.
Expected< std::vector< std::optional< ExecutorSymbolDef > > > ResolveResult
Expected< tpctypes::DylibHandle > open(const std::string &Path, uint64_t Mode)
void addBootstrapSymbols(StringMap< ExecutorAddr > &M) override
static LLVM_ABI DynamicLibrary getPermanentLibrary(const char *filename, std::string *errMsg=nullptr)
This function permanently loads the dynamic library at the given path using the library load operatio...
LLVM_ABI const char * SimpleExecutorDylibManagerResolveWrapperName
LLVM_ABI const char * SimpleExecutorDylibManagerOpenWrapperName
shared::SPSExpected< shared::SPSSequence< shared::SPSOptional< shared::SPSExecutorSymbolDef > > >( shared::SPSExecutorAddr, shared::SPSRemoteSymbolLookupSet) SPSSimpleExecutorDylibManagerResolveSignature
Definition OrcRTBridge.h:69
LLVM_ABI const char * SimpleExecutorDylibManagerInstanceName
MethodWrapperHandler< RetT, ClassT, ArgTs... > makeMethodWrapperHandler(RetT(ClassT::*Method)(ArgTs...))
Create a MethodWrapperHandler object from the given method pointer.
std::vector< RemoteSymbolLookupSetElement > RemoteSymbolLookupSet
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:98
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:869