LLVM 19.0.0git
EPCDynamicLibrarySearchGenerator.cpp
Go to the documentation of this file.
1//===---------------- EPCDynamicLibrarySearchGenerator.cpp ----------------===//
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#include "llvm/Support/Error.h"
11
12namespace llvm {
13namespace orc {
14
15Expected<std::unique_ptr<EPCDynamicLibrarySearchGenerator>>
17 ExecutionSession &ES, const char *LibraryPath, SymbolPredicate Allow,
18 AddAbsoluteSymbolsFn AddAbsoluteSymbols) {
19 auto Handle = ES.getExecutorProcessControl().loadDylib(LibraryPath);
20 if (!Handle)
21 return Handle.takeError();
22
23 return std::make_unique<EPCDynamicLibrarySearchGenerator>(
24 ES, *Handle, std::move(Allow), std::move(AddAbsoluteSymbols));
25}
26
29 JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) {
30
31 if (Symbols.empty())
32 return Error::success();
33
34 SymbolLookupSet LookupSymbols;
35
36 for (auto &KV : Symbols) {
37 // Skip symbols that don't match the filter.
38 if (Allow && !Allow(KV.first))
39 continue;
40 LookupSymbols.add(KV.first, SymbolLookupFlags::WeaklyReferencedSymbol);
41 }
42
43 ExecutorProcessControl::LookupRequest Request(H, LookupSymbols);
44 // Copy-capture LookupSymbols, since LookupRequest keeps a reference.
45 EPC.lookupSymbolsAsync(Request, [this, &JD, LS = std::move(LS),
46 LookupSymbols](auto Result) mutable {
47 if (!Result)
48 return LS.continueLookup(Result.takeError());
49
50 assert(Result->size() == 1 && "Results for more than one library returned");
51 assert(Result->front().size() == LookupSymbols.size() &&
52 "Result has incorrect number of elements");
53
54 SymbolMap NewSymbols;
55 auto ResultI = Result->front().begin();
56 for (auto &KV : LookupSymbols) {
57 if (ResultI->getAddress())
58 NewSymbols[KV.first] = *ResultI;
59 ++ResultI;
60 }
61
62 // If there were no resolved symbols bail out.
63 if (NewSymbols.empty())
64 return LS.continueLookup(Error::success());
65
66 // Define resolved symbols.
67 Error Err = AddAbsoluteSymbols
68 ? AddAbsoluteSymbols(JD, std::move(NewSymbols))
69 : JD.define(absoluteSymbols(std::move(NewSymbols)));
70
71 LS.continueLookup(std::move(Err));
72 });
73
74 return Error::success();
75}
76
77} // end namespace orc
78} // end namespace llvm
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:334
static Expected< std::unique_ptr< EPCDynamicLibrarySearchGenerator > > Load(ExecutionSession &ES, const char *LibraryPath, SymbolPredicate Allow=SymbolPredicate(), AddAbsoluteSymbolsFn AddAbsoluteSymbols=nullptr)
Permanently loads the library at the given path and, on success, returns a DynamicLibrarySearchGenera...
Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD, JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) override
DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.
An ExecutionSession represents a running JIT program.
Definition: Core.h:1425
ExecutorProcessControl & getExecutorProcessControl()
Get the ExecutorProcessControl object associated with this ExecutionSession.
Definition: Core.h:1468
virtual Expected< tpctypes::DylibHandle > loadDylib(const char *DylibPath)=0
Load the dynamic library at the given path and return a handle to it.
virtual void lookupSymbolsAsync(ArrayRef< LookupRequest > Request, SymbolLookupCompleteFn F)=0
Search for symbols in the target process.
Represents a JIT'd dynamic library.
Definition: Core.h:989
Error define(std::unique_ptr< MaterializationUnitType > &&MU, ResourceTrackerSP RT=nullptr)
Define all symbols provided by the materialization unit to be part of this JITDylib.
Definition: Core.h:1911
Wraps state for a lookup-in-progress.
Definition: Core.h:921
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Definition: Core.h:183
UnderlyingVector::size_type size() const
Definition: Core.h:259
SymbolLookupSet & add(SymbolStringPtr Name, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Add an element to the set.
Definition: Core.h:244
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
Definition: Core.h:791
JITDylibLookupFlags
Lookup flags that apply to each dylib in the search order for a lookup.
Definition: Core.h:135
LookupKind
Describes the kind of lookup being performed.
Definition: Core.h:157
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
A pair of a dylib and a set of symbols to be looked up.