summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ExecutionEngine/Orc/Core.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/ExecutionEngine/Orc/Core.cpp')
-rw-r--r--llvm/lib/ExecutionEngine/Orc/Core.cpp151
1 files changed, 65 insertions, 86 deletions
diff --git a/llvm/lib/ExecutionEngine/Orc/Core.cpp b/llvm/lib/ExecutionEngine/Orc/Core.cpp
index 8a9740e0be0..df4d0028a4a 100644
--- a/llvm/lib/ExecutionEngine/Orc/Core.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Core.cpp
@@ -205,16 +205,14 @@ raw_ostream &operator<<(raw_ostream &OS, const MaterializationUnit &MU) {
return OS << ")";
}
-raw_ostream &operator<<(raw_ostream &OS, const JITDylibSearchList &JDs) {
+raw_ostream &operator<<(raw_ostream &OS, const JITDylibList &JDs) {
OS << "[";
if (!JDs.empty()) {
- assert(JDs.front().first && "JITDylibList entries must not be null");
- OS << " (\"" << JDs.front().first->getName() << "\", "
- << (JDs.front().second ? "true" : "false") << ")";
- for (auto &KV : make_range(std::next(JDs.begin()), JDs.end())) {
- assert(KV.first && "JITDylibList entries must not be null");
- OS << ", (\"" << KV.first->getName() << "\", "
- << (KV.second ? "true" : "false") << ")";
+ assert(JDs.front() && "JITDylibList entries must not be null");
+ OS << " " << JDs.front()->getName();
+ for (auto *JD : make_range(std::next(JDs.begin()), JDs.end())) {
+ assert(JD && "JITDylibList entries must not be null");
+ OS << ", " << JD->getName();
}
}
OS << " ]";
@@ -528,11 +526,9 @@ AbsoluteSymbolsMaterializationUnit::extractFlags(const SymbolMap &Symbols) {
}
ReExportsMaterializationUnit::ReExportsMaterializationUnit(
- JITDylib *SourceJD, bool MatchNonExported, SymbolAliasMap Aliases,
- VModuleKey K)
+ JITDylib *SourceJD, SymbolAliasMap Aliases, VModuleKey K)
: MaterializationUnit(extractFlags(Aliases), std::move(K)),
- SourceJD(SourceJD), MatchNonExported(MatchNonExported),
- Aliases(std::move(Aliases)) {}
+ SourceJD(SourceJD), Aliases(std::move(Aliases)) {}
StringRef ReExportsMaterializationUnit::getName() const {
return "<Reexports>";
@@ -560,7 +556,7 @@ void ReExportsMaterializationUnit::materialize(
if (!Aliases.empty()) {
if (SourceJD)
- R.replace(reexports(*SourceJD, std::move(Aliases), MatchNonExported));
+ R.replace(reexports(*SourceJD, std::move(Aliases)));
else
R.replace(symbolAliases(std::move(Aliases)));
}
@@ -660,8 +656,8 @@ void ReExportsMaterializationUnit::materialize(
auto OnReady = [&ES](Error Err) { ES.reportError(std::move(Err)); };
- ES.lookup({{&SrcJD, MatchNonExported}}, QuerySymbols, std::move(OnResolve),
- std::move(OnReady), std::move(RegisterDependencies));
+ ES.lookup({&SrcJD}, QuerySymbols, std::move(OnResolve), std::move(OnReady),
+ std::move(RegisterDependencies), nullptr, true);
}
}
@@ -702,10 +698,8 @@ buildSimpleReexportsAliasMap(JITDylib &SourceJD, const SymbolNameSet &Symbols) {
}
ReexportsGenerator::ReexportsGenerator(JITDylib &SourceJD,
- bool MatchNonExported,
SymbolPredicate Allow)
- : SourceJD(SourceJD), MatchNonExported(MatchNonExported),
- Allow(std::move(Allow)) {}
+ : SourceJD(SourceJD), Allow(std::move(Allow)) {}
SymbolNameSet ReexportsGenerator::operator()(JITDylib &JD,
const SymbolNameSet &Names) {
@@ -722,7 +716,7 @@ SymbolNameSet ReexportsGenerator::operator()(JITDylib &JD,
}
if (!Added.empty())
- cantFail(JD.define(reexports(SourceJD, AliasMap, MatchNonExported)));
+ cantFail(JD.define(reexports(SourceJD, AliasMap)));
return Added;
}
@@ -1047,41 +1041,30 @@ void JITDylib::notifyFailed(const SymbolNameSet &FailedSymbols) {
Q->handleFailed(make_error<FailedToMaterialize>(FailedSymbols));
}
-void JITDylib::setSearchOrder(JITDylibSearchList NewSearchOrder,
- bool SearchThisJITDylibFirst,
- bool MatchNonExportedInThisDylib) {
- if (SearchThisJITDylibFirst && NewSearchOrder.front().first != this)
- NewSearchOrder.insert(NewSearchOrder.begin(),
- {this, MatchNonExportedInThisDylib});
+void JITDylib::setSearchOrder(JITDylibList NewSearchOrder,
+ bool SearchThisJITDylibFirst) {
+ if (SearchThisJITDylibFirst && NewSearchOrder.front() != this)
+ NewSearchOrder.insert(NewSearchOrder.begin(), this);
ES.runSessionLocked([&]() { SearchOrder = std::move(NewSearchOrder); });
}
-void JITDylib::addToSearchOrder(JITDylib &JD, bool MatchNonExported) {
- ES.runSessionLocked([&]() {
- SearchOrder.push_back({&JD, MatchNonExported});
- });
+void JITDylib::addToSearchOrder(JITDylib &JD) {
+ ES.runSessionLocked([&]() { SearchOrder.push_back(&JD); });
}
-void JITDylib::replaceInSearchOrder(JITDylib &OldJD, JITDylib &NewJD,
- bool MatchNonExported) {
+void JITDylib::replaceInSearchOrder(JITDylib &OldJD, JITDylib &NewJD) {
ES.runSessionLocked([&]() {
- auto I = std::find_if(SearchOrder.begin(), SearchOrder.end(),
- [&](const JITDylibSearchList::value_type &KV) {
- return KV.first == &OldJD;
- });
+ auto I = std::find(SearchOrder.begin(), SearchOrder.end(), &OldJD);
if (I != SearchOrder.end())
- *I = {&NewJD, MatchNonExported};
+ *I = &NewJD;
});
}
void JITDylib::removeFromSearchOrder(JITDylib &JD) {
ES.runSessionLocked([&]() {
- auto I = std::find_if(SearchOrder.begin(), SearchOrder.end(),
- [&](const JITDylibSearchList::value_type &KV) {
- return KV.first == &JD;
- });
+ auto I = std::find(SearchOrder.begin(), SearchOrder.end(), &JD);
if (I != SearchOrder.end())
SearchOrder.erase(I);
});
@@ -1178,17 +1161,18 @@ SymbolNameSet JITDylib::lookupFlagsImpl(SymbolFlagsMap &Flags,
}
void JITDylib::lodgeQuery(std::shared_ptr<AsynchronousSymbolQuery> &Q,
- SymbolNameSet &Unresolved, bool MatchNonExported,
+ SymbolNameSet &Unresolved,
+ JITDylib *MatchNonExportedInJD, bool MatchNonExported,
MaterializationUnitList &MUs) {
assert(Q && "Query can not be null");
- lodgeQueryImpl(Q, Unresolved, MatchNonExported, MUs);
+ lodgeQueryImpl(Q, Unresolved, MatchNonExportedInJD, MatchNonExported, MUs);
if (DefGenerator && !Unresolved.empty()) {
auto NewDefs = DefGenerator(*this, Unresolved);
if (!NewDefs.empty()) {
for (auto &D : NewDefs)
Unresolved.erase(D);
- lodgeQueryImpl(Q, NewDefs, MatchNonExported, MUs);
+ lodgeQueryImpl(Q, NewDefs, MatchNonExportedInJD, MatchNonExported, MUs);
assert(NewDefs.empty() &&
"All fallback defs should have been found by lookupImpl");
}
@@ -1197,7 +1181,7 @@ void JITDylib::lodgeQuery(std::shared_ptr<AsynchronousSymbolQuery> &Q,
void JITDylib::lodgeQueryImpl(
std::shared_ptr<AsynchronousSymbolQuery> &Q, SymbolNameSet &Unresolved,
- bool MatchNonExported,
+ JITDylib *MatchNonExportedInJD, bool MatchNonExported,
std::vector<std::unique_ptr<MaterializationUnit>> &MUs) {
std::vector<SymbolStringPtr> ToRemove;
@@ -1207,9 +1191,12 @@ void JITDylib::lodgeQueryImpl(
if (SymI == Symbols.end())
continue;
- // If this is a non exported symbol and we're skipping those then skip it.
- if (!SymI->second.getFlags().isExported() && !MatchNonExported)
- continue;
+ // If this is a non-exported symbol, then check the values of
+ // MatchNonExportedInJD and MatchNonExported. Skip if we should not match
+ // against this symbol.
+ if (!SymI->second.getFlags().isExported())
+ if (!MatchNonExported && MatchNonExportedInJD != this)
+ continue;
// If we matched against Name in JD, mark it to be removed from the Unresolved
// set.
@@ -1395,9 +1382,8 @@ void JITDylib::dump(raw_ostream &OS) {
<< "\" (ES: " << format("0x%016x", reinterpret_cast<uintptr_t>(&ES))
<< "):\n"
<< "Search order: [";
- for (auto &KV : SearchOrder)
- OS << " (\"" << KV.first->getName() << "\", "
- << (KV.second ? "all" : "exported only") << ")";
+ for (auto *JD : SearchOrder)
+ OS << " \"" << JD->getName() << "\"";
OS << " ]\n"
<< "Symbol table:\n";
@@ -1445,7 +1431,7 @@ void JITDylib::dump(raw_ostream &OS) {
JITDylib::JITDylib(ExecutionSession &ES, std::string Name)
: ES(ES), JITDylibName(std::move(Name)) {
- SearchOrder.push_back({this, true});
+ SearchOrder.push_back(this);
}
Error JITDylib::defineImpl(MaterializationUnit &MU) {
@@ -1738,10 +1724,12 @@ Expected<SymbolMap> ExecutionSession::legacyLookup(
#endif
}
-void ExecutionSession::lookup(
- const JITDylibSearchList &SearchOrder, SymbolNameSet Symbols,
- SymbolsResolvedCallback OnResolve, SymbolsReadyCallback OnReady,
- RegisterDependenciesFunction RegisterDependencies) {
+void ExecutionSession::lookup(const JITDylibList &JDs, SymbolNameSet Symbols,
+ SymbolsResolvedCallback OnResolve,
+ SymbolsReadyCallback OnReady,
+ RegisterDependenciesFunction RegisterDependencies,
+ JITDylib *MatchNonExportedInJD,
+ bool MatchNonExported) {
// lookup can be re-entered recursively if running on a single thread. Run any
// outstanding MUs in case this query depends on them, otherwise this lookup
@@ -1757,14 +1745,12 @@ void ExecutionSession::lookup(
bool QueryFailed = false;
runSessionLocked([&]() {
- for (auto &KV : SearchOrder) {
- assert(KV.first && "JITDylibList entries must not be null");
- assert(!CollectedMUsMap.count(KV.first) &&
+ for (auto *JD : JDs) {
+ assert(JD && "JITDylibList entries must not be null");
+ assert(!CollectedMUsMap.count(JD) &&
"JITDylibList should not contain duplicate entries");
-
- auto &JD = *KV.first;
- auto MatchNonExported = KV.second;
- JD.lodgeQuery(Q, Unresolved, MatchNonExported, CollectedMUsMap[&JD]);
+ JD->lodgeQuery(Q, Unresolved, MatchNonExportedInJD, MatchNonExported,
+ CollectedMUsMap[JD]);
}
if (Unresolved.empty()) {
@@ -1815,9 +1801,11 @@ void ExecutionSession::lookup(
runOutstandingMUs();
}
-Expected<SymbolMap> ExecutionSession::lookup(
- const JITDylibSearchList &SearchOrder, const SymbolNameSet &Symbols,
- RegisterDependenciesFunction RegisterDependencies, bool WaitUntilReady) {
+Expected<SymbolMap>
+ExecutionSession::lookup(const JITDylibList &JDs, const SymbolNameSet &Symbols,
+ RegisterDependenciesFunction RegisterDependencies,
+ bool WaitUntilReady, JITDylib *MatchNonExportedInJD,
+ bool MatchNonExported) {
#if LLVM_ENABLE_THREADS
// In the threaded case we use promises to return the results.
std::promise<SymbolMap> PromisedResult;
@@ -1884,7 +1872,8 @@ Expected<SymbolMap> ExecutionSession::lookup(
#endif
// Perform the asynchronous lookup.
- lookup(SearchOrder, Symbols, OnResolve, OnReady, RegisterDependencies);
+ lookup(JDs, Symbols, OnResolve, OnReady, RegisterDependencies,
+ MatchNonExportedInJD, MatchNonExported);
#if LLVM_ENABLE_THREADS
auto ResultFuture = PromisedResult.get_future();
@@ -1927,13 +1916,14 @@ Expected<SymbolMap> ExecutionSession::lookup(
#endif
}
-Expected<JITEvaluatedSymbol>
-ExecutionSession::lookup(const JITDylibSearchList &SearchOrder,
- SymbolStringPtr Name) {
+/// Look up a symbol by searching a list of JDs.
+Expected<JITEvaluatedSymbol> ExecutionSession::lookup(const JITDylibList &JDs,
+ SymbolStringPtr Name,
+ bool MatchNonExported) {
SymbolNameSet Names({Name});
- if (auto ResultMap = lookup(SearchOrder, std::move(Names),
- NoDependenciesToRegister, true)) {
+ if (auto ResultMap = lookup(JDs, std::move(Names), NoDependenciesToRegister,
+ true, nullptr, MatchNonExported)) {
assert(ResultMap->size() == 1 && "Unexpected number of results");
assert(ResultMap->count(Name) && "Missing result for symbol");
return std::move(ResultMap->begin()->second);
@@ -1941,21 +1931,10 @@ ExecutionSession::lookup(const JITDylibSearchList &SearchOrder,
return ResultMap.takeError();
}
-Expected<JITEvaluatedSymbol>
-ExecutionSession::lookup(ArrayRef<JITDylib *> SearchOrder,
- SymbolStringPtr Name) {
- SymbolNameSet Names({Name});
-
- JITDylibSearchList FullSearchOrder(SearchOrder.size());
- for (auto *JD : SearchOrder)
- FullSearchOrder.push_back({JD, false});
-
- return lookup(FullSearchOrder, Name);
-}
-
-Expected<JITEvaluatedSymbol>
-ExecutionSession::lookup(ArrayRef<JITDylib *> SearchOrder, StringRef Name) {
- return lookup(SearchOrder, intern(Name));
+Expected<JITEvaluatedSymbol> ExecutionSession::lookup(const JITDylibList &JDs,
+ StringRef Name,
+ bool MatchNonExported) {
+ return lookup(JDs, intern(Name), MatchNonExported);
}
void ExecutionSession::dump(raw_ostream &OS) {
OpenPOWER on IntegriCloud