[llvm] [ORC] Add automatic shared library resolver for unresolved symbols. (PR #148410)

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 30 22:36:51 PDT 2025


================
@@ -0,0 +1,173 @@
+//===--- SymbolFilter.h - Utils for Symbol Filter ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_SYMBOLFILTER_H
+#define LLVM_EXECUTIONENGINE_ORC_SHARED_SYMBOLFILTER_H
+
+#include "llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h"
+
+#include <cmath>
+#include <type_traits>
+#include <vector>
+
+namespace llvm {
+namespace orc {
+
+namespace shared {
+using SPSBloomFilter =
+    SPSTuple<bool, uint32_t, uint32_t, uint32_t, SPSSequence<uint64_t>>;
+}
+
+class BloomFilter {
+public:
+  using HashFunc = std::function<uint32_t(StringRef)>;
+
+  BloomFilter() = default;
+  BloomFilter(BloomFilter &&) noexcept = default;
+  BloomFilter &operator=(BloomFilter &&) noexcept = default;
+  BloomFilter(const BloomFilter &) = delete;
+  BloomFilter &operator=(const BloomFilter &) = delete;
+
+  BloomFilter(uint32_t symbolCount, float falsePositiveRate, HashFunc hashFn)
+      : hashFunc(std::move(hashFn)) {
+    initialize(symbolCount, falsePositiveRate);
+  }
+  bool IsInitialized() const { return initialized; }
+
+  void add(StringRef symbol) {
+    assert(initialized);
+    addHash(hashFunc(symbol));
+  }
+
+  bool mayContain(StringRef symbol) const {
+    return !isEmpty() && testHash(hashFunc(symbol));
+  }
+
+  bool isEmpty() const { return symbolCount_ == 0; }
+
+private:
+  friend class shared::SPSSerializationTraits<shared::SPSBloomFilter,
+                                              BloomFilter>;
+  static constexpr uint32_t bitsPerEntry = 64;
+
+  bool initialized = false;
+  uint32_t symbolCount_ = 0;
----------------
lhames wrote:

Trailing underscore for member names isn't idiomatic in LLVM. I think it'd make more sense to put that on the constructor parameter.

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


More information about the llvm-commits mailing list