Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
EPCDynamicLibrarySearchGenerator.cpp
Go to the documentation of this file.
1//===---------------- EPCDynamicLibrarySearchGenerator.cpp ----------------===//
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#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
10
11#include "llvm/ExecutionEngine/Orc/AbsoluteSymbols.h"
12#include "llvm/ExecutionEngine/Orc/DebugUtils.h"
13#include "llvm/Support/Error.h"
14
15#define DEBUG_TYPE "orc"
16
17namespacellvm {
18namespaceorc {
19
20Expected<std::unique_ptr<EPCDynamicLibrarySearchGenerator>>
21EPCDynamicLibrarySearchGenerator::Load(
22ExecutionSession &ES,constchar *LibraryPath,SymbolPredicate Allow,
23AddAbsoluteSymbolsFn AddAbsoluteSymbols) {
24auto Handle =
25 ES.getExecutorProcessControl().getDylibMgr().loadDylib(LibraryPath);
26if (!Handle)
27return Handle.takeError();
28
29return std::make_unique<EPCDynamicLibrarySearchGenerator>(
30 ES, *Handle, std::move(Allow), std::move(AddAbsoluteSymbols));
31}
32
33ErrorEPCDynamicLibrarySearchGenerator::tryToGenerate(
34LookupState &LS,LookupKind K,JITDylib &JD,
35JITDylibLookupFlags JDLookupFlags,constSymbolLookupSet &Symbols) {
36
37if (Symbols.empty())
38returnError::success();
39
40LLVM_DEBUG({
41dbgs() <<"EPCDynamicLibrarySearchGenerator trying to generate "
42 << Symbols <<"\n";
43 });
44
45SymbolLookupSet LookupSymbols;
46
47for (auto &KV : Symbols) {
48// Skip symbols that don't match the filter.
49if (Allow && !Allow(KV.first))
50continue;
51 LookupSymbols.add(KV.first,SymbolLookupFlags::WeaklyReferencedSymbol);
52 }
53
54DylibManager::LookupRequest Request(H, LookupSymbols);
55// Copy-capture LookupSymbols, since LookupRequest keeps a reference.
56 EPC.getDylibMgr().lookupSymbolsAsync(Request, [this, &JD, LS = std::move(LS),
57 LookupSymbols](
58autoResult)mutable {
59if (!Result) {
60LLVM_DEBUG({
61dbgs() <<"EPCDynamicLibrarySearchGenerator lookup failed due to error";
62 });
63return LS.continueLookup(Result.takeError());
64 }
65
66assert(Result->size() == 1 &&"Results for more than one library returned");
67assert(Result->front().size() == LookupSymbols.size() &&
68"Result has incorrect number of elements");
69
70SymbolMap NewSymbols;
71auto ResultI =Result->front().begin();
72for (auto &KV : LookupSymbols) {
73if (ResultI->getAddress())
74 NewSymbols[KV.first] = *ResultI;
75 ++ResultI;
76 }
77
78LLVM_DEBUG({
79dbgs() <<"EPCDynamicLibrarySearchGenerator lookup returned "
80 << NewSymbols <<"\n";
81 });
82
83// If there were no resolved symbols bail out.
84if (NewSymbols.empty())
85return LS.continueLookup(Error::success());
86
87// Define resolved symbols.
88Error Err = AddAbsoluteSymbols
89 ? AddAbsoluteSymbols(JD, std::move(NewSymbols))
90 : JD.define(absoluteSymbols(std::move(NewSymbols)));
91
92 LS.continueLookup(std::move(Err));
93 });
94
95returnError::success();
96}
97
98}// end namespace orc
99}// end namespace llvm
AbsoluteSymbols.h
DebugUtils.h
LLVM_DEBUG
#define LLVM_DEBUG(...)
Definition:Debug.h:106
EPCDynamicLibrarySearchGenerator.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::DenseMapBase::empty
bool empty() const
Definition:DenseMap.h:98
llvm::DenseMap< SymbolStringPtr, ExecutorSymbolDef >
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition:Error.h:160
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition:Error.h:337
llvm::orc::DylibManager::lookupSymbolsAsync
virtual void lookupSymbolsAsync(ArrayRef< LookupRequest > Request, SymbolLookupCompleteFn F)=0
Search for symbols in the target process.
llvm::orc::DylibManager::loadDylib
virtual Expected< tpctypes::DylibHandle > loadDylib(const char *DylibPath)=0
Load the dynamic library at the given path and return a handle to it.
llvm::orc::EPCDynamicLibrarySearchGenerator::Load
static Expected< std::unique_ptr< EPCDynamicLibrarySearchGenerator > > Load(ExecutionSession &ES, const char *LibraryPath, SymbolPredicate Allow=SymbolPredicate(), AddAbsoluteSymbolsFn AddAbsoluteSymbols=nullptr)
Permanently loads the library at the given path and, on success, returns a DynamicLibrarySearchGenera...
Definition:EPCDynamicLibrarySearchGenerator.cpp:21
llvm::orc::EPCDynamicLibrarySearchGenerator::tryToGenerate
Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD, JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) override
DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.
Definition:EPCDynamicLibrarySearchGenerator.cpp:33
llvm::orc::ExecutionSession
An ExecutionSession represents a running JIT program.
Definition:Core.h:1340
llvm::orc::ExecutionSession::getExecutorProcessControl
ExecutorProcessControl & getExecutorProcessControl()
Get the ExecutorProcessControl object associated with this ExecutionSession.
Definition:Core.h:1380
llvm::orc::ExecutorProcessControl::getDylibMgr
DylibManager & getDylibMgr() const
Return the DylibManager for the target process.
Definition:ExecutorProcessControl.h:225
llvm::orc::JITDylib
Represents a JIT'd dynamic library.
Definition:Core.h:897
llvm::orc::JITDylib::define
Error define(std::unique_ptr< MaterializationUnitType > &&MU, ResourceTrackerSP RT=nullptr)
Define all symbols provided by the materialization unit to be part of this JITDylib.
Definition:Core.h:1823
llvm::orc::LookupState
Wraps state for a lookup-in-progress.
Definition:Core.h:829
llvm::orc::SymbolLookupSet
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Definition:Core.h:194
llvm::orc::SymbolLookupSet::add
SymbolLookupSet & add(SymbolStringPtr Name, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Add an element to the set.
Definition:Core.h:260
llvm::unique_function< bool(const SymbolStringPtr &)>
Error.h
llvm::orc::SimpleRemoteEPCOpcode::Result
@ Result
llvm::orc::absoluteSymbols
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
Definition:AbsoluteSymbols.h:52
llvm::orc::SymbolLookupFlags::WeaklyReferencedSymbol
@ WeaklyReferencedSymbol
llvm::orc::JITDylibLookupFlags
JITDylibLookupFlags
Lookup flags that apply to each dylib in the search order for a lookup.
Definition:Core.h:146
llvm::orc::LookupKind
LookupKind
Describes the kind of lookup being performed.
Definition:Core.h:168
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition:Debug.cpp:163
llvm::orc::DylibManager::LookupRequest
A pair of a dylib and a set of symbols to be looked up.
Definition:DylibManager.h:31

Generated on Fri Jul 18 2025 11:27:11 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp