1//===- EPCGenericDylibManagerSPS.cpp - SPS 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
9#include "llvm/ExecutionEngine/Orc/EPCGenericDylibManagerSPS.h"
10
11#include "llvm/ExecutionEngine/Orc/Core.h"
12#include "llvm/ExecutionEngine/Orc/LookupAndApply.h"
13#include "llvm/ExecutionEngine/Orc/RecordProxy.h"
14#include "llvm/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.h"
15
16namespace llvm::orc::shared {
17
18// Serialize a local SymbolLookupSet directly as an SPSRemoteSymbolLookupSet,
19// avoiding a std::string copy of each (potentially large) symbol name.
20template <>
21class SPSSerializationTraits<SPSRemoteSymbolLookupSetElement,
22 SymbolLookupSet::value_type> {
23public:
24 static size_t size(const SymbolLookupSet::value_type &V) {
25 return SPSArgList<SPSString, bool>::size(
26 Arg: *V.first, Args: V.second == SymbolLookupFlags::RequiredSymbol);
27 }
28
29 static bool serialize(SPSOutputBuffer &OB,
30 const SymbolLookupSet::value_type &V) {
31 return SPSArgList<SPSString, bool>::serialize(
32 OB, Arg: *V.first, Args: V.second == SymbolLookupFlags::RequiredSymbol);
33 }
34};
35
36template <>
37class TrivialSPSSequenceSerialization<SPSRemoteSymbolLookupSetElement,
38 SymbolLookupSet> {
39public:
40 static constexpr bool available = true;
41};
42
43} // namespace llvm::orc::shared
44
45namespace llvm::orc::sps {
46
47Expected<std::unique_ptr<EPCGenericDylibManager>>
48createEPCGenericDylibManager(JITDylib &JD) {
49 auto &ES = JD.getExecutionSession();
50 EPCGenericDylibManager::Bindings B;
51 // Instance is the executor-side manager object -- a data symbol passed as the
52 // first argument to each call, not a wrapper to proxy. The proxies resolve to
53 // the specs' default (NativeDylibManager) names.
54 if (auto Err = lookupAndApply(
55 JD,
56 PrepareFns: {recordAddr(Name: rt::sps_ci::NativeDylibManagerInstanceName, A: &B.Instance),
57 recordProxy<DylibMgrOpenProxySpec>(P: &B.Open),
58 recordProxy<DylibMgrResolveProxySpec>(P: &B.Resolve)}))
59 return std::move(Err);
60 return std::make_unique<EPCGenericDylibManager>(args&: ES, args: std::move(B));
61}
62
63Expected<std::unique_ptr<EPCGenericDylibManager>>
64createEPCGenericDylibManager(ExecutionSession &ES) {
65 return createEPCGenericDylibManager(JD&: ES.getBootstrapJITDylib());
66}
67
68} // namespace llvm::orc::sps
69