LLVM 20.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
17
18namespace llvm {
19namespace orc {
20
21/// Base class for performing redirection of call to symbol to another symbol in
22/// runtime.
24public:
25 virtual ~RedirectionManager() = default;
26
27 /// Change the redirection destination of given symbols to new destination
28 /// symbols.
29 virtual Error redirect(JITDylib &JD, const SymbolMap &NewDests) = 0;
30
31 /// Change the redirection destination of given symbol to new destination
32 /// symbol.
34 ExecutorSymbolDef NewDest) {
35 return redirect(JD, {{std::move(Symbol), NewDest}});
36 }
37
38private:
39 virtual void anchor();
40};
41
42/// Base class for managing redirectable symbols in which a call
43/// gets redirected to another symbol in runtime.
45public:
46 /// Create redirectable symbols with given symbol names and initial
47 /// desitnation symbol addresses.
49
50 /// Create a single redirectable symbol with given symbol name and initial
51 /// desitnation symbol address.
53 ExecutorSymbolDef InitialDest) {
54 return createRedirectableSymbols(RT, {{std::move(Symbol), InitialDest}});
55 }
56
57 /// Emit redirectable symbol
58 virtual void
59 emitRedirectableSymbols(std::unique_ptr<MaterializationResponsibility> MR,
60 SymbolMap InitialDests) = 0;
61};
62
63/// RedirectableMaterializationUnit materializes redirectable symbol
64/// by invoking RedirectableSymbolManager::emitRedirectableSymbols
66public:
68 SymbolMap InitialDests)
69 : MaterializationUnit(convertToFlags(InitialDests)), RM(RM),
70 InitialDests(std::move(InitialDests)) {}
71
72 StringRef getName() const override {
73 return "RedirectableSymbolMaterializationUnit";
74 }
75
76 void materialize(std::unique_ptr<MaterializationResponsibility> R) override {
77 RM.emitRedirectableSymbols(std::move(R), std::move(InitialDests));
78 }
79
80 void discard(const JITDylib &JD, const SymbolStringPtr &Name) override {
81 InitialDests.erase(Name);
82 }
83
84private:
86 convertToFlags(const SymbolMap &InitialDests) {
87 SymbolFlagsMap Flags;
88 for (auto [K, V] : InitialDests)
89 Flags[K] = V.getFlags();
90 return MaterializationUnit::Interface(Flags, {});
91 }
92
93 RedirectableSymbolManager &RM;
94 SymbolMap InitialDests;
95};
96
97} // namespace orc
98} // namespace llvm
99
100#endif
std::string Name
bool erase(const KeyT &Val)
Definition: DenseMap.h:321
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
Represents a defining location for a JIT symbol.
Represents a JIT'd dynamic library.
Definition: Core.h:897
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...
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:1873
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858