Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@ class LibraryManager {
return FilteredView(Libraries.begin(), Libraries.end(), S, K);
}

std::vector<std::shared_ptr<LibraryInfo>> getLibraries(LibState S,
PathType K) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::vector<std::shared_ptr<LibraryInfo>> getLibraries(LibState S,
PathType K) const {
void getLibraries(LibState S, PathType K, std::vector<std::shared_ptr<LibraryInfo>>& Outs) const {

Why this became a shared_ptr? Are we going to lose performance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was already StringMap<std::shared_ptr<LibraryInfo>> Libraries; in LibraryManager.
Would using raw pointers or references be safe in a concurrent environment?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s keep the stared_ptr like this and measure the performance on the downstream client.

std::vector<std::shared_ptr<LibraryInfo>> Outs;
std::shared_lock<std::shared_mutex> Lock(Mtx);
for (const auto &[_, Entry] : Libraries) {
if (Entry->getKind() == K && Entry->getState() == S)
Outs.push_back(Entry);
}
return Outs;
}

void forEachLibrary(const LibraryVisitor &visitor) const {
std::unique_lock<std::shared_mutex> Lock(Mtx);
for (const auto &[_, entry] : Libraries) {
Expand All @@ -220,14 +231,14 @@ class LibraryManager {
}

bool isLoaded(StringRef Path) const {
std::unique_lock<std::shared_mutex> Lock(Mtx);
std::shared_lock<std::shared_mutex> Lock(Mtx);
if (auto It = Libraries.find(Path.str()); It != Libraries.end())
return It->second->getState() == LibState::Loaded;
return false;
}

bool isQueried(StringRef Path) const {
std::unique_lock<std::shared_mutex> Lock(Mtx);
std::shared_lock<std::shared_mutex> Lock(Mtx);
if (auto It = Libraries.find(Path.str()); It != Libraries.end())
return It->second->getState() == LibState::Queried;
return false;
Expand Down
15 changes: 7 additions & 8 deletions llvm/lib/ExecutionEngine/Orc/TargetProcess/LibraryResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,18 @@ void LibraryResolver::resolveSymbolsInLibrary(
return EnumerateResult::Continue;
},
Opts);
};

if (!Lib.hasFilter()) {
LLVM_DEBUG(dbgs() << "Building filter for library: " << Lib.getFullPath()
<< "\n";);
enumerateSymbolsIfNeeded();
if (DiscoveredSymbols.empty()) {
LLVM_DEBUG(dbgs() << " No symbols and remove library : "
<< Lib.getFullPath() << "\n";);
LibMgr.removeLibrary(Lib.getFullPath());
return;
}
};

if (!Lib.hasFilter()) {
LLVM_DEBUG(dbgs() << "Building filter for library: " << Lib.getFullPath()
<< "\n";);
enumerateSymbolsIfNeeded();
SmallVector<StringRef> SymbolVec;
SymbolVec.reserve(DiscoveredSymbols.size());
for (const auto &KV : DiscoveredSymbols)
Expand Down Expand Up @@ -288,8 +287,8 @@ void LibraryResolver::searchSymbolsInLibraries(

SymbolSearchContext Ctx(Q);
while (!Ctx.allResolved()) {

for (auto &Lib : LibMgr.getView(S, K)) {
auto Libs = LibMgr.getLibraries(S, K);
for (auto &Lib : Libs) {
if (Ctx.hasSearched(Lib.get()))
continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void handleError(Error Err, StringRef context = "") {
}

bool ObjectFileLoader::isArchitectureCompatible(const object::ObjectFile &Obj) {
Triple HostTriple(sys::getDefaultTargetTriple());
Triple HostTriple(sys::getProcessTriple());
Triple ObjTriple = Obj.makeTriple();

LLVM_DEBUG({
Expand Down