LLVM 23.0.0git
ExecutorResolutionGenerator.cpp
Go to the documentation of this file.
1//===---- ExecutorProcessControl.cpp -- Executor process control APIs -----===//
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
13#include "llvm/Support/Error.h"
14
15#define DEBUG_TYPE "orc"
16
17namespace llvm {
18namespace orc {
19
20Expected<std::unique_ptr<ExecutorResolutionGenerator>>
22 const char *LibraryPath,
23 SymbolPredicate Allow,
24 AbsoluteSymbolsFn AbsoluteSymbols) {
25 auto H = DylibMgr.loadDylib(LibraryPath);
26 if (H)
27 return H.takeError();
28 return std::make_unique<ExecutorResolutionGenerator>(
29 ES, DylibMgr, *H, std::move(Allow), std::move(AbsoluteSymbols));
30}
31
34 JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &LookupSet) {
35
36 if (LookupSet.empty())
37 return Error::success();
38
40 dbgs() << "ExecutorResolutionGenerator trying to generate " << LookupSet
41 << "\n";
42 });
43
44 SymbolLookupSet LookupSymbols;
45 for (auto &[Name, LookupFlag] : LookupSet) {
46 if (Allow && !Allow(Name))
47 continue;
48 LookupSymbols.add(Name, LookupFlag);
49 }
50
51 DylibManager::LookupRequest LR(H, LookupSymbols);
52 DylibMgr.lookupSymbolsAsync(
53 LR, [this, LS = std::move(LS), JD = JITDylibSP(&JD),
54 LookupSymbols](auto Result) mutable {
55 if (Result) {
57 dbgs() << "ExecutorResolutionGenerator lookup failed due to error";
58 });
59 return LS.continueLookup(Result.takeError());
60 }
61 assert(Result->size() == 1 &&
62 "Results for more than one library returned");
63 assert(Result->front().size() == LookupSymbols.size() &&
64 "Result has incorrect number of elements");
65
66 // const tpctypes::LookupResult &Syms = Result->front();
67 // size_t SymIdx = 0;
68 auto Syms = Result->front().begin();
69 SymbolNameSet MissingSymbols;
70 SymbolMap NewSyms;
71 for (auto &[Name, Flags] : LookupSymbols) {
72 const auto &Sym = *Syms++;
73 if (Sym && Sym->getAddress())
74 NewSyms[Name] = *Sym;
75 else if (LLVM_UNLIKELY(!Sym &&
77 MissingSymbols.insert(Name);
78 }
79
81 dbgs() << "ExecutorResolutionGenerator lookup returned " << NewSyms
82 << "\n";
83 });
84
85 if (NewSyms.empty())
86 return LS.continueLookup(Error::success());
87
88 if (LLVM_UNLIKELY(!MissingSymbols.empty()))
89 return LS.continueLookup(make_error<SymbolsNotFound>(
90 this->ES.getSymbolStringPool(), std::move(MissingSymbols)));
91
92 LS.continueLookup(JD->define(AbsoluteSymbols(std::move(NewSyms))));
93 });
94
95 return Error::success();
96}
97
98} // end namespace orc
99} // end namespace llvm
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_UNLIKELY(EXPR)
Definition Compiler.h:336
#define LLVM_DEBUG(...)
Definition Debug.h:114
bool empty() const
Definition DenseMap.h:109
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:202
friend class ExecutionSession
Definition Core.h:877
static Expected< std::unique_ptr< ExecutorResolutionGenerator > > Load(ExecutionSession &ES, DylibManager &DylibMgr, const char *LibraryPath, SymbolPredicate Allow=SymbolPredicate(), AbsoluteSymbolsFn AbsoluteSymbols=absoluteSymbols)
Permanently loads the library at the given path and, on success, returns an ExecutorResolutionGenerat...
unique_function< std::unique_ptr< MaterializationUnit >(SymbolMap)> AbsoluteSymbolsFn
Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD, JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &LookupSet) override
DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.
unique_function< bool(const SymbolStringPtr &)> SymbolPredicate
Represents a JIT'd dynamic library.
Definition Core.h:919
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:1897
Wraps state for a lookup-in-progress.
Definition Core.h:851
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Definition Core.h:199
bool empty() const
Definition Core.h:279
IntrusiveRefCntPtr< JITDylib > JITDylibSP
Definition Core.h:57
JITDylibLookupFlags
Lookup flags that apply to each dylib in the search order for a lookup.
Definition Core.h:151
DenseMap< SymbolStringPtr, ExecutorSymbolDef > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
LookupKind
Describes the kind of lookup being performed.
Definition Core.h:173
DenseSet< SymbolStringPtr > SymbolNameSet
A set of symbol names (represented by SymbolStringPtrs for.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
A pair of a dylib and a set of symbols to be looked up.