[llvm] [IR] Store Metadata attachments in vector (PR #189551)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 31 04:00:10 PDT 2026
================
@@ -1606,56 +1566,58 @@ MDNode *Value::getMetadata(StringRef Kind) const {
MDNode *Value::getMetadataImpl(unsigned KindID) const {
const LLVMContext &Ctx = getContext();
- const MDAttachments &Attachements = Ctx.pImpl->ValueMetadata.at(this);
- return Attachements.lookup(KindID);
+ unsigned Idx = getMetadataIndex();
+ while (Idx) {
+ const MDAttachment &A = Ctx.pImpl->Metadatas[Idx];
+ if (A.MDKind == KindID)
+ return A.Node;
+ Idx = A.Next;
+ }
+ return nullptr;
}
void Value::getMetadata(unsigned KindID, SmallVectorImpl<MDNode *> &MDs) const {
- if (hasMetadata())
- getContext().pImpl->ValueMetadata.at(this).get(KindID, MDs);
+ const LLVMContext &Ctx = getContext();
+ unsigned Idx = getMetadataIndex();
+ while (Idx) {
+ const MDAttachment &A = Ctx.pImpl->Metadatas[Idx];
+ if (A.MDKind == KindID)
+ MDs.push_back(A.Node);
+ Idx = A.Next;
+ }
+ // We store metadata in reverse order, so reverse for output.
+ std::reverse(MDs.begin(), MDs.end());
----------------
nikic wrote:
Does this mean that the non-vector getMetadata() now returns the last occurrence instead of the first?
https://github.com/llvm/llvm-project/pull/189551
More information about the llvm-commits
mailing list