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 @@ -2915,6 +2915,14 @@ */ void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest); +/** + * Replace an operand at a specific index in a llvm::MDNode value. + * + * @see llvm::MDNode::replaceOperandWith() + */ +void LLVMReplaceMDNodeOperandWith(LLVMValueRef V, unsigned Index, + LLVMMetadataRef Replacement); + /** Deprecated: Use LLVMMDStringInContext2 instead. */ LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str, unsigned SLen); 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 @@ -1248,6 +1248,13 @@ Dest[i] = getMDNodeOperandImpl(Context, N, i); } +void LLVMReplaceMDNodeOperandWith(LLVMValueRef V, unsigned Index, + LLVMMetadataRef Replacement) { + auto *MD = cast(unwrap(V)); + auto *N = cast(MD->getMetadata()); + N->replaceOperandWith(Index, unwrap(Replacement)); +} + unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char *Name) { if (NamedMDNode *N = unwrap(M)->getNamedMetadata(Name)) { return N->getNumOperands();