Index: llvm/include/llvm/IR/Instruction.h =================================================================== --- llvm/include/llvm/IR/Instruction.h +++ llvm/include/llvm/IR/Instruction.h @@ -188,6 +188,10 @@ getAllMetadataOtherThanDebugLocImpl(MDs); } + /// Get all the metadata IDs attached to this Instruction except the ones + /// associated with debug location. The Vector \p MDIDs is not cleared. + void getAllNonDebugMetadataIDs(SmallVectorImpl &MDIDs) const; + /// Fills the AAMDNodes structure with AA metadata from this instruction. /// When Merge is true, the existing AA metadata is merged with that from this /// instruction providing the most-general result. Index: llvm/lib/IR/LLVMContextImpl.h =================================================================== --- llvm/lib/IR/LLVMContextImpl.h +++ llvm/lib/IR/LLVMContextImpl.h @@ -993,6 +993,7 @@ /// Copies all the current attachments into \c Result, sorting by attachment /// ID. This function does \em not clear \c Result. void getAll(SmallVectorImpl> &Result) const; + void getAllIDs(SmallVectorImpl &Result) const; /// \brief Erase matching attachments. /// Index: llvm/lib/IR/Metadata.cpp =================================================================== --- llvm/lib/IR/Metadata.cpp +++ llvm/lib/IR/Metadata.cpp @@ -1106,6 +1106,11 @@ array_pod_sort(Result.begin(), Result.end()); } +void MDAttachmentMap::getAllIDs(SmallVectorImpl &Result) const { + for (auto &A : Attachments) + Result.push_back(A.first); +} + void MDGlobalAttachmentMap::insert(unsigned ID, MDNode &MD) { Attachments.push_back({ID, TrackingMDNodeRef(&MD)}); } @@ -1270,6 +1275,15 @@ Info.getAll(Result); } +void +Instruction::getAllNonDebugMetadataIDs(SmallVectorImpl &MDIDs) const { + if (!hasMetadataOtherThanDebugLoc()) + return; + const auto &Info = getContext().pImpl->InstructionMetadata.find(this)->second; + assert(!Info.empty() && "Shouldn't have called this"); + Info.getAllIDs(MDIDs); +} + bool Instruction::extractProfMetadata(uint64_t &TrueVal, uint64_t &FalseVal) const { assert(