16#ifndef LLVM_EXECUTIONENGINE_ORC_LAZYREEXPORTS_H
17#define LLVM_EXECUTIONENGINE_ORC_LAZYREEXPORTS_H
74 using ReexportsMap = std::map<ExecutorAddr, ReexportsEntry>;
76 using NotifiersMap = std::map<ExecutorAddr, NotifyResolvedFunction>;
82 ReexportsMap Reexports;
83 NotifiersMap Notifiers;
95 template <
typename ORCABI>
Error init() {
99 NotifyLandingResolved) {
101 std::move(NotifyLandingResolved));
105 return TP.takeError();
107 this->TP = std::move(*TP);
112 std::unique_ptr<TrampolinePool> TP;
117 template <
typename ORCABI>
120 auto LLCTM = std::unique_ptr<LocalLazyCallThroughManager>(
123 if (
auto Err = LLCTM->init<ORCABI>())
124 return std::move(Err);
126 return std::move(LLCTM);
134 ExecutorAddr ErrorHandlerAddr);
152 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override;
167inline std::unique_ptr<LazyReexportsMaterializationUnit>
172 return std::make_unique<LazyReexportsMaterializationUnit>(
173 LCTManager, RSManager, SourceJD, std::move(CallableAliases), SrcJDLoc);
178 friend std::unique_ptr<MaterializationUnit>
214 Expected<std::vector<ExecutorSymbolDef>> EntryAddrs)>;
243 std::unique_ptr<MaterializationUnit>
246 void emitReentryTrampolines(std::unique_ptr<MaterializationResponsibility> MR,
248 void emitRedirectableSymbols(
249 std::unique_ptr<MaterializationResponsibility> MR,
251 Expected<std::vector<ExecutorSymbolDef>> ReentryPoints);
266inline std::unique_ptr<MaterializationUnit>
268 return LRM.createLazyReexports(std::move(Reexports));
276 static std::shared_ptr<SimpleLazyReexportsSpeculator>
281 RecordExecutionFunction RecordExec)
286 std::make_shared<make_shared_helper>(ES, std::move(RecordExec));
287 Instance->WeakThis = Instance;
307 std::vector<std::pair<std::string, SymbolStringPtr>> NewSuggestions);
312 : ES(ES), RecordExec(
std::
move(RecordExec)) {}
314 bool doNextSpeculativeLookup();
318 using KeyToFunctionBodiesMap =
323 std::weak_ptr<SimpleLazyReexportsSpeculator> WeakThis;
325 std::deque<std::pair<std::string, SymbolStringPtr>> SpeculateSuggestions;
326 bool SpeculateTaskActive =
false;
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
StringRef - Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
An ExecutionSession represents a running JIT program.
Represents an address in the executor process.
Represents a JIT'd dynamic library.
Manages a set of 'lazy call-through' trampolines.
ExecutorAddr reportCallThroughError(Error Err)
Expected< ReexportsEntry > findReexport(ExecutorAddr TrampolineAddr)
Error notifyResolved(ExecutorAddr TrampolineAddr, ExecutorAddr ResolvedAddr)
void setTrampolinePool(TrampolinePool &TP)
void resolveTrampolineLandingAddress(ExecutorAddr TrampolineAddr, TrampolinePool::NotifyLandingResolvedFunction NotifyLandingResolved)
virtual ~LazyCallThroughManager()=default
Expected< ExecutorAddr > getCallThroughTrampoline(JITDylib &SourceJD, SymbolStringPtr SymbolName, NotifyResolvedFunction NotifyResolved)
virtual void onLazyReexportCalled(const CallThroughInfo &CTI)=0
Called outside the session lock when a lazy reexport is called.
virtual void onLazyReexportsCreated(JITDylib &JD, ResourceKey K, const SymbolAliasMap &Reexports)=0
Called under the session lock when new lazy reexports are created.
virtual Error onLazyReexportsRemoved(JITDylib &JD, ResourceKey K)=0
Called under the session lock when lazy reexports are removed.
virtual void onLazyReexportsTransfered(JITDylib &JD, ResourceKey DstK, ResourceKey SrcK)=0
Called under the session lock when lazy reexports have their ownership transferred to a new ResourceK...
void handleTransferResources(JITDylib &JD, ResourceKey DstK, ResourceKey SrcK) override
This function will be called inside the session lock.
friend std::unique_ptr< MaterializationUnit > lazyReexports(LazyReexportsManager &, SymbolAliasMap)
Define lazy-reexports based on the given SymbolAliasMap.
Error handleRemoveResources(JITDylib &JD, ResourceKey K) override
This function will be called outside the session lock.
LazyReexportsManager & operator=(LazyReexportsManager &&)=delete
LazyReexportsManager(LazyReexportsManager &&)=delete
static Expected< std::unique_ptr< LazyReexportsManager > > Create(EmitTrampolinesFn EmitTrampolines, RedirectableSymbolManager &RSMgr, JITDylib &PlatformJD, Listener *L=nullptr)
Create a LazyReexportsManager that uses the ORC runtime for reentry.
A materialization unit that builds lazy re-exports.
StringRef getName() const override
Return the name of this materialization unit.
A lazy call-through manager that builds trampolines in the current process.
static Expected< std::unique_ptr< LocalLazyCallThroughManager > > Create(ExecutionSession &ES, ExecutorAddr ErrorHandlerAddr)
Create a LocalLazyCallThroughManager using the given ABI.
static Expected< std::unique_ptr< LocalTrampolinePool > > Create(ResolveLandingFunction ResolveLanding)
Creates a LocalTrampolinePool with the given RunCallback function.
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
Base class for managing redirectable symbols in which a call gets redirected to another symbol in run...
Listens for ResourceTracker operations.
Error onLazyReexportsRemoved(JITDylib &JD, ResourceKey K) override
Called under the session lock when lazy reexports are removed.
~SimpleLazyReexportsSpeculator() override
void onLazyReexportsCreated(JITDylib &JD, ResourceKey K, const SymbolAliasMap &Reexports) override
Called under the session lock when new lazy reexports are created.
void onLazyReexportCalled(const CallThroughInfo &CTI) override
Called outside the session lock when a lazy reexport is called.
void onLazyReexportsTransfered(JITDylib &JD, ResourceKey DstK, ResourceKey SrcK) override
Called under the session lock when lazy reexports have their ownership transferred to a new ResourceK...
static std::shared_ptr< SimpleLazyReexportsSpeculator > Create(ExecutionSession &ES, RecordExecutionFunction RecordExec={})
SimpleLazyReexportsSpeculator(SimpleLazyReexportsSpeculator &&)=delete
unique_function< void(const CallThroughInfo &CTI)> RecordExecutionFunction
void addSpeculationSuggestions(std::vector< std::pair< std::string, SymbolStringPtr > > NewSuggestions)
SimpleLazyReexportsSpeculator & operator=(SimpleLazyReexportsSpeculator &&)=delete
Pointer to a pooled string representing a symbol name.
Base class for pools of compiler re-entry trampolines.
unique_function< void(ExecutorAddr) const > NotifyLandingResolvedFunction
unique_function is a type-erasing functor similar to std::function.
Expected< std::unique_ptr< LazyCallThroughManager > > createLocalLazyCallThroughManager(const Triple &T, ExecutionSession &ES, ExecutorAddr ErrorHandlerAddr)
Create a LocalLazyCallThroughManager from the given triple and execution session.
std::unique_ptr< LazyReexportsMaterializationUnit > lazyReexports(LazyCallThroughManager &LCTManager, RedirectableSymbolManager &RSManager, JITDylib &SourceJD, SymbolAliasMap CallableAliases, ImplSymbolMap *SrcJDLoc=nullptr)
Define lazy-reexports based on the given SymbolAliasMap.
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
SymbolStringPtr SymbolName