LLVM 23.0.0git
LookupAndRecordAddrs.cpp
Go to the documentation of this file.
1//===------- LookupAndRecordAddrs.h - Symbol lookup support utility -------===//
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
11#include <future>
12
13namespace llvm {
14namespace orc {
15
17 unique_function<void(Error)> OnRecorded, ExecutionSession &ES, LookupKind K,
18 const JITDylibSearchOrder &SearchOrder,
19 std::vector<std::pair<SymbolStringPtr, ExecutorAddr *>> Pairs,
20 SymbolLookupFlags LookupFlags) {
21
22 SymbolLookupSet Symbols;
23 for (auto &KV : Pairs)
24 Symbols.add(KV.first, LookupFlags);
25
26 ES.lookup(
27 K, SearchOrder, std::move(Symbols), SymbolState::Ready,
28 [Pairs = std::move(Pairs),
29 OnRec = std::move(OnRecorded)](Expected<SymbolMap> Result) mutable {
30 if (!Result)
31 return OnRec(Result.takeError());
32 for (auto &KV : Pairs) {
33 auto I = Result->find(KV.first);
34 *KV.second =
35 I != Result->end() ? I->second.getAddress() : orc::ExecutorAddr();
36 }
37 OnRec(Error::success());
38 },
40}
41
43 ExecutionSession &ES, LookupKind K, const JITDylibSearchOrder &SearchOrder,
44 std::vector<std::pair<SymbolStringPtr, ExecutorAddr *>> Pairs,
45 SymbolLookupFlags LookupFlags) {
46
47 std::promise<MSVCPError> ResultP;
48 auto ResultF = ResultP.get_future();
49 lookupAndRecordAddrs([&](Error Err) { ResultP.set_value(std::move(Err)); },
50 ES, K, SearchOrder, std::move(Pairs), LookupFlags);
51 return ResultF.get();
52}
53
54} // End namespace orc.
55} // End namespace llvm.
#define I(x, y, z)
Definition MD5.cpp:57
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:1355
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:1790
Represents an address in the executor process.
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Definition Core.h:199
unique_function is a type-erasing functor similar to std::function.
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:177
SymbolLookupFlags
Lookup flags that apply to each symbol in a lookup.
Definition Core.h:161
LLVM_ABI void lookupAndRecordAddrs(unique_function< void(Error)> OnRecorded, ExecutionSession &ES, LookupKind K, const JITDylibSearchOrder &SearchOrder, std::vector< std::pair< SymbolStringPtr, ExecutorAddr * > > Pairs, SymbolLookupFlags LookupFlags=SymbolLookupFlags::RequiredSymbol)
Record addresses of the given symbols in the given ExecutorAddrs.
LookupKind
Describes the kind of lookup being performed.
Definition Core.h:173
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:795
This is an optimization pass for GlobalISel generic memory operations.