[llvm] [Orc][LibResolver] Refactor resolver internals and simplify symbol resolution. (PR #169161)
Vassil Vassilev via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 7 02:37:26 PST 2025
================
@@ -25,80 +25,136 @@
namespace llvm {
namespace orc {
-/// Manages library metadata and state for symbol resolution.
-///
-/// Tracks libraries by load state and kind (user/system), and stores
-/// associated Bloom filters and hash maps to speed up symbol lookups.
-/// Thread-safe for concurrent access.
-class LibraryManager {
+class LibraryManager;
+
+enum class LibState : uint8_t { Unloaded = 0, Loaded = 1, Queried = 2 };
+
+class LibraryInfo {
public:
- enum class LibState : uint8_t { Unloaded = 0, Loaded = 1, Queried = 2 };
+ LibraryInfo(const LibraryInfo &) = delete;
+ LibraryInfo &operator=(const LibraryInfo &) = delete;
- class LibraryInfo {
- public:
- LibraryInfo(const LibraryInfo &) = delete;
- LibraryInfo &operator=(const LibraryInfo &) = delete;
+ LibraryInfo(std::string FilePath, LibState S, PathType K,
+ std::optional<BloomFilter> Filter = std::nullopt)
+ : FilePath(std::move(FilePath)), S(S), K(K), Filter(std::move(Filter)) {}
- LibraryInfo(std::string FilePath, LibState S, PathType K,
- std::optional<BloomFilter> Filter = std::nullopt)
- : FilePath(std::move(FilePath)), S(S), K(K), Filter(std::move(Filter)) {
- }
+ StringRef getBasePath() const { return sys::path::parent_path(FilePath); }
+ StringRef getFileName() const { return sys::path::filename(FilePath); }
- StringRef getBasePath() const { return sys::path::parent_path(FilePath); }
- StringRef getFileName() const { return sys::path::filename(FilePath); }
+ std::string getFullPath() const { return FilePath; }
- std::string getFullPath() const { return FilePath; }
+ void setFilter(BloomFilter F) {
+ std::lock_guard<std::shared_mutex> Lock(Mtx);
+ if (Filter)
+ return;
+ Filter.emplace(std::move(F));
+ }
- void setFilter(BloomFilter F) {
- std::lock_guard<std::shared_mutex> Lock(Mtx);
- if (Filter)
- return;
- Filter.emplace(std::move(F));
- }
+ void ensureFilterBuilt(const BloomFilterBuilder &FB,
+ ArrayRef<StringRef> Symbols) {
+ std::lock_guard<std::shared_mutex> Lock(Mtx);
+ if (Filter)
+ return;
+ Filter.emplace(FB.build(Symbols));
+ }
- void ensureFilterBuilt(const BloomFilterBuilder &FB,
- ArrayRef<StringRef> Symbols) {
- std::lock_guard<std::shared_mutex> Lock(Mtx);
- if (Filter)
- return;
- Filter.emplace(FB.build(Symbols));
- }
+ bool mayContain(StringRef Symbol) const {
+ assert(hasFilter());
+ std::shared_lock<std::shared_mutex> Lock(Mtx);
+ return Filter->mayContain(Symbol);
+ }
- bool mayContain(StringRef Symbol) const {
- assert(hasFilter());
- std::shared_lock<std::shared_mutex> Lock(Mtx);
- return Filter->mayContain(Symbol);
- }
+ bool hasFilter() const {
+ std::shared_lock<std::shared_mutex> Lock(Mtx);
+ return Filter.has_value();
+ }
- bool hasFilter() const {
- std::shared_lock<std::shared_mutex> Lock(Mtx);
- return Filter.has_value();
- }
+ LibState getState() const { return S.load(); }
+ PathType getKind() const { return K; }
- LibState getState() const { return S.load(); }
- PathType getKind() const { return K; }
+ void setState(LibState s) { S.store(s); }
- void setState(LibState s) { S.store(s); }
+ bool operator==(const LibraryInfo &other) const {
+ return FilePath == other.FilePath;
+ }
+
+private:
+ std::string FilePath;
+ std::atomic<LibState> S;
+ PathType K;
+ std::optional<BloomFilter> Filter;
+ mutable std::shared_mutex Mtx;
+};
- bool operator==(const LibraryInfo &other) const {
- return FilePath == other.FilePath;
+class LibraryCursor {
----------------
vgvassilev wrote:
We should add doxygen documentation here.
https://github.com/llvm/llvm-project/pull/169161
More information about the llvm-commits
mailing list