[clang] [llvm] Compute GUIDs once and store in metadata (PR #184065)

Teresa Johnson via cfe-commits cfe-commits at lists.llvm.org
Fri May 1 12:17:02 PDT 2026


================
@@ -576,10 +577,31 @@ class LLVM_ABI Module {
   // Use global_size() to get the total number of global variables.
   // Use globals() to get the range of all global variables.
 
+  std::optional<GlobalValue::GUID> getGUID(const Value *V) const {
+    const auto It = ValueToGUIDMap.find(V);
+    if (It == ValueToGUIDMap.end())
+      return std::nullopt;
+
+    return It->getSecond();
+  }
+
+  void insertGUID(const Value *V, GlobalValue::GUID GUID) {
+    const auto [It, WasInserted] = ValueToGUIDMap.insert({V, GUID});
+
+    (void)It, (void)WasInserted;
+#ifndef NDEBUG
+    if (!WasInserted) {
+      assert((It->second == GUID) && "insertGUID called with different value");
+    }
+#endif
+  }
+
 private:
-/// @}
-/// @name Direct access to the globals list, functions list, and symbol table
-/// @{
+  DenseMap<const Value *, GlobalValue::GUID> ValueToGUIDMap;
----------------
teresajohnson wrote:

Add comments about what this is for and when used instead of the metadata. I had already forgotten but from the comments in getGUIDIfAssigned it seems it is just during lazy loading of metadata?

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


More information about the cfe-commits mailing list