diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h --- a/llvm/include/llvm-c/Core.h +++ b/llvm/include/llvm-c/Core.h @@ -2902,6 +2902,13 @@ /** Deprecated: Use LLVMMDNodeInContext2 instead. */ LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count); +/** + * Replace all metadata uses of a value with another one. + * + * @see llvm::Value::replaceAllUsesWith() + */ +void LLVMReplaceAllMetadataUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal); + /** * @} */ diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -904,6 +904,10 @@ unwrap(OldVal)->replaceAllUsesWith(unwrap(NewVal)); } +void LLVMReplaceAllMetadataUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) { + ValueAsMetadata::handleRAUW(unwrap(OldVal), unwrap(NewVal)); +} + int LLVMHasMetadata(LLVMValueRef Inst) { return unwrap(Inst)->hasMetadata(); } diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/lib/IR/Metadata.cpp @@ -438,7 +438,6 @@ assert(From && "Expected valid value"); assert(To && "Expected valid value"); assert(From != To && "Expected changed value"); - assert(From->getType() == To->getType() && "Unexpected type change"); LLVMContext &Context = From->getType()->getContext(); auto &Store = Context.pImpl->ValuesAsMetadata;