[llvm] [Orc][LibResolver] Refactor resolver internals and simplify symbol resolution. (PR #169161)

Vassil Vassilev via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 24 06:05:31 PST 2025


================
@@ -24,81 +24,136 @@
 
 namespace llvm {
 namespace orc {
+class LibraryManager;
 
-/// 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 {
+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 {
+public:
+  LibraryCursor(const std::vector<const LibraryInfo *> &L, LibState S)
+      : Lists(L), S(S) {}
+
+  const LibraryInfo *nextValidLib() {
+    while (Pos < Lists.size()) {
+      const LibraryInfo *Lib = Lists[Pos++];
+      if (Lib->getState() == S)
+        return Lib;
     }
 
-  private:
-    std::string FilePath;
-    std::atomic<LibState> S;
-    PathType K;
-    std::optional<BloomFilter> Filter;
-    mutable std::shared_mutex Mtx;
-  };
+    return nullptr;
+  }
+
+  bool hasMoreValidLib() const { return Pos < Lists.size(); }
 
+private:
+  const std::vector<const LibraryInfo *> &Lists;
+  LibState S;
+  size_t Pos = 0; // cursor position
----------------
vgvassilev wrote:

Not sure what's the orc convention but usually in clang that goes in the beginning of the class with omitted `private` keyword.

https://github.com/llvm/llvm-project/pull/169161


More information about the llvm-commits mailing list