[llvm] [IR] Use persistent metadata IDs for pass snapshots (PR #216838)

Alexis Engelke via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 20 02:14:33 PDT 2026


================
@@ -1056,17 +1079,36 @@ static SlotTracker *createSlotTracker(const Value *V) {
 
 // Module level constructor. Causes the contents of the Module (sans functions)
 // to be added to the slot table.
-SlotTracker::SlotTracker(const Module *M, bool ShouldInitializeAllMetadata)
-    : TheModule(M), ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
+SlotTracker::SlotTracker(const Module *M, bool ShouldInitializeAllMetadata,
+                         MetadataPrintMode MetadataMode)
+    : TheModule(M), ShouldInitializeAllMetadata(ShouldInitializeAllMetadata),
+      MetadataMode(MetadataMode) {
+  assert((!ShouldInitializeAllMetadata || !usePersistentMetadataIDs()) &&
+         "cannot initialize compact metadata slots with persistent IDs");
+  if (usePersistentMetadataIDs()) {
+    assert(M && "persistent metadata IDs require a module");
+    mdnNext = M->getContext().pImpl->getNextMetadataPrintID();
+  }
+}
 
 // Function level constructor. Causes the contents of the Module and the one
 // function provided to be added to the slot table.
-SlotTracker::SlotTracker(const Function *F, bool ShouldInitializeAllMetadata)
+SlotTracker::SlotTracker(const Function *F, bool ShouldInitializeAllMetadata,
+                         MetadataPrintMode MetadataMode)
     : TheModule(F ? F->getParent() : nullptr), TheFunction(F),
-      ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
+      ShouldInitializeAllMetadata(ShouldInitializeAllMetadata),
+      MetadataMode(MetadataMode) {
+  assert((!ShouldInitializeAllMetadata || !usePersistentMetadataIDs()) &&
+         "cannot initialize compact metadata slots with persistent IDs");
+  if (usePersistentMetadataIDs()) {
+    assert(F && "persistent metadata IDs require a function");
+    mdnNext = F->getContext().pImpl->getNextMetadataPrintID();
----------------
aengelke wrote:

Why is this needed? References to temporaries? If so, maybe we should number temporaries as well?

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


More information about the llvm-commits mailing list