LLVM 24.0.0git
RecordProxy.h
Go to the documentation of this file.
1//===- RecordProxy.h - Build a Proxy from a lookup --------------*- C++ -*-===//
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// lookupAndApply operations that build Proxy objects over the symbols they
10// resolve.
11//
12// This is kept out of Proxy.h so that clients holding or calling a Proxy do not
13// have to see the lookup machinery used to build one.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_EXECUTIONENGINE_ORC_RECORDPROXY_H
18#define LLVM_EXECUTIONENGINE_ORC_RECORDPROXY_H
19
24
25namespace llvm::orc {
26
27/// Builds P over the symbol with the given name, dispatching through Dispatch.
28///
29/// If the symbol is weakly referenced and not found then P is left null.
30template <typename FnT>
33 SymbolNameSpec Name,
35 return [P, Dispatch, Name, LF](SymbolLookupSet &LS, ExecutionSession &ES,
36 const Mangler &Mangle) -> LookupApplyFn {
37 auto N = Mangle.withMangledNameDo([&](StringRef M) { return ES.intern(M); },
38 Name);
39 LS.add(N, LF);
40 return [P, Dispatch, N = std::move(N)](const SymbolMap &M) {
41 auto Sym = M.lookup(N);
42 *P = Sym.getAddress() ? Proxy<FnT>(Dispatch, Sym.getAddress())
43 : Proxy<FnT>();
44 };
45 };
46}
47
48/// Builds P over the symbol with the given, already-interned name,
49/// dispatching through Dispatch.
50///
51/// If the symbol is weakly referenced and not found then P is left null.
52template <typename FnT>
55 SymbolStringPtr Name,
57 return [P, Dispatch, Name = std::move(Name),
59 const Mangler &) -> LookupApplyFn {
60 LS.add(Name, LF);
61 return [P, Dispatch, Name](const SymbolMap &M) {
62 auto Sym = M.lookup(Name);
63 *P = Sym.getAddress() ? Proxy<FnT>(Dispatch, Sym.getAddress())
64 : Proxy<FnT>();
65 };
66 };
67}
68
69/// Builds P from the given spec, using the spec's default controller-interface
70/// name.
71template <typename ProxySpecT, typename FnT>
75 return recordProxy(P, ProxySpecT::dispatch, ProxySpecT::Name, LF);
76}
77
78/// Builds P from the given spec, but resolves it under Name rather than the
79/// spec's default controller-interface name.
80template <typename ProxySpecT, typename FnT>
84 return recordProxy(P, ProxySpecT::dispatch, std::move(Name), LF);
85}
86
87/// Builds P from the given spec, but resolves it under the given,
88/// already-interned name rather than the spec's default controller-interface
89/// name.
90template <typename ProxySpecT, typename FnT>
94 return recordProxy(P, ProxySpecT::dispatch, std::move(Name), LF);
95}
96
97} // namespace llvm::orc
98
99#endif // LLVM_EXECUTIONENGINE_ORC_RECORDPROXY_H
#define P(N)
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
An ExecutionSession represents a running JIT program.
Definition Core.h:1111
Applies linker name-mangling for a target.
Definition Mangler.h:31
A set of symbols to look up, each associated with a SymbolLookupFlags value.
A symbol name together with the naming level (SymbolNameKind) it is expressed in, so that a Mangler /...
Pointer to a pooled string representing a symbol name.
LookupPrepareFn recordProxy(Proxy< FnT > *P, typename Proxy< FnT >::DispatchFn Dispatch, SymbolNameSpec Name, SymbolLookupFlags LF=SymbolLookupFlags::RequiredSymbol)
Builds P over the symbol with the given name, dispatching through Dispatch.
Definition RecordProxy.h:32
SymbolLookupFlags
Lookup flags that apply to each symbol in a lookup.
DenseMap< SymbolStringPtr, ExecutorSymbolDef > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
unique_function< void(const SymbolMap &M)> LookupApplyFn
Acts on the result of a completed lookup.
unique_function< LookupApplyFn( SymbolLookupSet &LS, ExecutionSession &ES, const Mangler &Mangle) const > LookupPrepareFn
Contributes symbols to a lookup, and returns the function that will act on the result.
#define N