LLVM 22.0.0git
RedirectionManager.h
Go to the documentation of this file.
1//===- RedirectionManager.h - Redirection manager interface -----*- 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// Redirection manager interface that redirects a call to symbol to another.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_REDIRECTIONMANAGER_H
14#define LLVM_EXECUTIONENGINE_ORC_REDIRECTIONMANAGER_H
15
18
19namespace llvm {
20namespace orc {
21
22/// Base class for performing redirection of call to symbol to another symbol in
23/// runtime.
25public:
26 virtual ~RedirectionManager() = default;
27
28 /// Change the redirection destination of given symbols to new destination
29 /// symbols.
30 virtual Error redirect(JITDylib &JD, const SymbolMap &NewDests) = 0;
31
32 /// Change the redirection destination of given symbol to new destination
33 /// symbol.
35 ExecutorSymbolDef NewDest) {
36 return redirect(JD, {{std::move(Symbol), NewDest}});
37 }
38
39private:
40 virtual void anchor();
41};
42
43/// Base class for managing redirectable symbols in which a call
44/// gets redirected to another symbol in runtime.
46public:
47 /// Create redirectable symbols with given symbol names and initial
48 /// desitnation symbol addresses.
50 SymbolMap InitialDests);
51
52 /// Create a single redirectable symbol with given symbol name and initial
53 /// desitnation symbol address.
55 ExecutorSymbolDef InitialDest) {
56 return createRedirectableSymbols(RT, {{std::move(Symbol), InitialDest}});
57 }
58
59 /// Emit redirectable symbol
60 virtual void
61 emitRedirectableSymbols(std::unique_ptr<MaterializationResponsibility> MR,
62 SymbolMap InitialDests) = 0;
63};
64
65/// RedirectableMaterializationUnit materializes redirectable symbol
66/// by invoking RedirectableSymbolManager::emitRedirectableSymbols
68public:
70 SymbolMap InitialDests)
71 : MaterializationUnit(convertToFlags(InitialDests)), RM(RM),
72 InitialDests(std::move(InitialDests)) {}
73
74 StringRef getName() const override {
75 return "RedirectableSymbolMaterializationUnit";
76 }
77
78 void materialize(std::unique_ptr<MaterializationResponsibility> R) override {
79 RM.emitRedirectableSymbols(std::move(R), std::move(InitialDests));
80 }
81
82 void discard(const JITDylib &JD, const SymbolStringPtr &Name) override {
83 InitialDests.erase(Name);
84 }
85
86private:
88 convertToFlags(const SymbolMap &InitialDests) {
89 SymbolFlagsMap Flags;
90 for (auto [K, V] : InitialDests)
91 Flags[K] = V.getFlags();
92 return MaterializationUnit::Interface(Flags, {});
93 }
94
95 RedirectableSymbolManager &RM;
96 SymbolMap InitialDests;
97};
98
99} // namespace orc
100} // namespace llvm
101
102#endif
#define LLVM_ABI
Definition: Compiler.h:213
std::string Name
bool erase(const KeyT &Val)
Definition: DenseMap.h:319
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Represents a defining location for a JIT symbol.
Represents a JIT'd dynamic library.
Definition: Core.h:902
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
RedirectableMaterializationUnit materializes redirectable symbol by invoking RedirectableSymbolManage...
StringRef getName() const override
Return the name of this materialization unit.
RedirectableMaterializationUnit(RedirectableSymbolManager &RM, SymbolMap InitialDests)
void discard(const JITDylib &JD, const SymbolStringPtr &Name) override
Implementations of this method should discard the given symbol from the source (e....
void materialize(std::unique_ptr< MaterializationResponsibility > R) override
Implementations of this method should materialize all symbols in the materialzation unit,...
Base class for managing redirectable symbols in which a call gets redirected to another symbol in run...
LLVM_ABI Error createRedirectableSymbols(ResourceTrackerSP RT, SymbolMap InitialDests)
Create redirectable symbols with given symbol names and initial desitnation symbol addresses.
Error createRedirectableSymbol(ResourceTrackerSP RT, SymbolStringPtr Symbol, ExecutorSymbolDef InitialDest)
Create a single redirectable symbol with given symbol name and initial desitnation symbol address.
virtual void emitRedirectableSymbols(std::unique_ptr< MaterializationResponsibility > MR, SymbolMap InitialDests)=0
Emit redirectable symbol.
Base class for performing redirection of call to symbol to another symbol in runtime.
virtual Error redirect(JITDylib &JD, const SymbolMap &NewDests)=0
Change the redirection destination of given symbols to new destination symbols.
virtual ~RedirectionManager()=default
Error redirect(JITDylib &JD, SymbolStringPtr Symbol, ExecutorSymbolDef NewDest)
Change the redirection destination of given symbol to new destination symbol.
Pointer to a pooled string representing a symbol name.
DenseMap< SymbolStringPtr, ExecutorSymbolDef > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1886
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856