[llvm] [CGData] Lazy loading support for stable function map (PR #151660)

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 8 11:10:59 PDT 2025


================
@@ -114,25 +117,61 @@ size_t StableFunctionMap::size(SizeType Type) const {
   case UniqueHashCount:
     return HashToFuncs.size();
   case TotalFunctionCount: {
+    const_cast<StableFunctionMap *>(this)->deserializeLazyLoadingEntries();
     size_t Count = 0;
     for (auto &Funcs : HashToFuncs)
-      Count += Funcs.second.size();
+      Count += Funcs.second.Entries.size();
     return Count;
   }
   case MergeableFunctionCount: {
+    const_cast<StableFunctionMap *>(this)->deserializeLazyLoadingEntries();
     size_t Count = 0;
     for (auto &[Hash, Funcs] : HashToFuncs)
-      if (Funcs.size() >= 2)
-        Count += Funcs.size();
+      if (Funcs.Entries.size() >= 2)
+        Count += Funcs.Entries.size();
     return Count;
   }
   }
   llvm_unreachable("Unhandled size type");
 }
 
+const StableFunctionMap::StableFunctionEntries &
+StableFunctionMap::at(HashFuncsMapType::key_type FunctionHash) const {
+  auto It = HashToFuncs.find(FunctionHash);
+  if (isLazilyLoaded())
+    const_cast<StableFunctionMap *>(this)->deserializeLazyLoadingEntry(It);
+  return It->second.Entries;
+}
+
+void StableFunctionMap::deserializeLazyLoadingEntry(
+    HashFuncsMapType::iterator It) {
+  assert(isLazilyLoaded() && "Cannot deserialize non-lazily-loaded map");
+  std::call_once(It->second.LazyLoadFlag, [this, It]() {
----------------
ellishg wrote:

I've encountered a weird "bug" where "Structured bindings cannot be captured by lambda expressions" until C++20. A workaround is to rename the captured variable

https://en.cppreference.com/w/cpp/language/structured_binding.html

```suggestion
  const auto& [Hash, Storage] = *It;
  std::call_once(It->second.LazyLoadFlag, [this, HashArg = Hash, StorageArg = Storage]() {
```

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


More information about the llvm-commits mailing list