LLVM 24.0.0git
LookupAndApply.cpp
Go to the documentation of this file.
1//===- LookupAndApply.cpp - Compose a lookup from handlers ----------------===//
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
13#include <future>
14
15namespace llvm::orc {
16
17void lookupAndApply(unique_function<void(Error)> OnApplied,
19 const JITDylibSearchOrder &SearchOrder,
20 ArrayRef<LookupPrepareFn> PrepareFns) {
21 // Collect the symbols to look up. Each prepare function hands back the
22 // applicator that will act on the result; the prepare functions themselves
23 // are not needed beyond this point.
24 SymbolLookupSet Symbols;
25 std::vector<LookupApplyFn> Applies;
26 Applies.reserve(PrepareFns.size());
27 for (const auto &PF : PrepareFns)
28 Applies.push_back(PF(Symbols, ES));
29
30 // PrepareFns are independent, so two of them may legitimately ask for the
31 // same symbol. ExecutionSession::lookup requires a duplicate-free set, and
32 // the applicators read the result by name, so merging here is invisible to
33 // them.
34 Symbols.mergeEntries();
35
36 ES.lookup(
37 K, SearchOrder, std::move(Symbols), SymbolState::Ready,
38 [Applies = std::move(Applies),
39 OnApplied = std::move(OnApplied)](Expected<SymbolMap> Result) mutable {
40 if (!Result)
41 return OnApplied(Result.takeError());
42 for (auto &Apply : Applies)
43 Apply(*Result);
44 OnApplied(Error::success());
45 },
47}
48
50 const JITDylibSearchOrder &SearchOrder,
51 ArrayRef<LookupPrepareFn> PrepareFns) {
52 std::promise<MSVCPError> ResultP;
53 auto ResultF = ResultP.get_future();
54 lookupAndApply([&](Error Err) { ResultP.set_value(std::move(Err)); }, ES, K,
55 SearchOrder, PrepareFns);
56 return ResultF.get();
57}
58
59void lookupAndApply(unique_function<void(Error)> OnApplied, JITDylib &JD,
60 ArrayRef<LookupPrepareFn> PrepareFns) {
61 lookupAndApply(std::move(OnApplied), JD.getExecutionSession(),
63}
64
69
70} // namespace llvm::orc
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
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
An ExecutionSession represents a running JIT program.
Definition Core.h:1111
LLVM_ABI void lookup(LookupKind K, const JITDylibSearchOrder &SearchOrder, SymbolLookupSet Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete, RegisterDependenciesFunction RegisterDependencies)
Search the given JITDylibs for the given symbols.
Definition Core.cpp:1764
Represents a JIT'd dynamic library.
Definition Core.h:675
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
Definition Core.h:694
A set of symbols to look up, each associated with a SymbolLookupFlags value.
unique_function is a type-erasing functor similar to std::function.
JITDylibSearchOrder makeJITDylibSearchOrder(ArrayRef< JITDylib * > JDs, JITDylibLookupFlags Flags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Convenience function for creating a search order from an ArrayRef of JITDylib*, all with the same fla...
Definition Core.h:153
std::vector< std::pair< JITDylib *, JITDylibLookupFlags > > JITDylibSearchOrder
A list of (JITDylib*, JITDylibLookupFlags) pairs to be used as a search order during symbol lookup.
Definition Core.h:148
LLVM_ABI void lookupAndApply(unique_function< void(Error)> OnApplied, ExecutionSession &ES, LookupKind K, const JITDylibSearchOrder &SearchOrder, ArrayRef< LookupPrepareFn > PrepareFns)
Resolve the symbols contributed by every prepare function with a single lookup, then let each of thei...
LookupKind
Describes the kind of lookup being performed.
Definition Core.h:144
LLVM_ABI RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
Definition Core.cpp:40
@ Ready
Emitted to memory, but waiting on transitive dependencies.
Definition Core.h:551