[llvm] [IR] Store Metadata attachments in vector (PR #189551)

Alexis Engelke via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 31 06:11:00 PDT 2026


================
@@ -1665,50 +1627,62 @@ void Value::setMetadata(StringRef Kind, MDNode *Node) {
 }
 
 void Value::addMetadata(unsigned KindID, MDNode &MD) {
-  assert(isa<Instruction>(this) || isa<GlobalObject>(this));
   if (!HasMetadata)
     HasMetadata = true;
-  getContext().pImpl->ValueMetadata[this].insert(KindID, MD);
+  const LLVMContext &Ctx = getContext();
+  unsigned &Idx = getMetadataIndex();
+  unsigned NewIdx = Ctx.pImpl->MetadataRecycleHead;
+  if (NewIdx == 0) {
+    NewIdx = Ctx.pImpl->Metadatas.size();
+    if (NewIdx == 0) {
+      Ctx.pImpl->MetadataRecycleSize = 1;
----------------
aengelke wrote:

Originally my intent was that MetadataRecycleSize is the size of Metadatas. Changed this now and also update MetadataRecycleSize only in assert builds.

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


More information about the llvm-commits mailing list