aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Core.cpp
diff options
context:
space:
mode:
authorDavide Bertola <bertola.davide@gmail.com>2023-01-31 09:02:50 -0800
committerAdrian Prantl <aprantl@apple.com>2023-01-31 09:58:03 -0800
commitc7d95ba051012e2d0d51bc365577777b48dd2093 (patch)
treeddb6aa678ef24070e1b15420850a2745c0e62223 /llvm/lib/IR/Core.cpp
parentd8982f72282bb88da6a3793f9d55fccd5621c825 (diff)
downloadllvm-c7d95ba051012e2d0d51bc365577777b48dd2093.zip
llvm-c7d95ba051012e2d0d51bc365577777b48dd2093.tar.gz
llvm-c7d95ba051012e2d0d51bc365577777b48dd2093.tar.bz2
[llvm-c] add LLVMReplaceMDNodeOperandWith
I'm working on a tool that visits debug info and massages it using the llvm-c API. I noticed that LLVMGetOperand special cases MDNodes so I can get their operands, but I can't replace them. This patch adds LLVMReplaceMDNodeOperandWith which boils down to MDNode::replaceOperandWith. The name was chosen for consistency with LLVMGetMDNodeOperands and LLVMGetMDNodeNumOperands. Differential Revision: https://reviews.llvm.org/D136637
Diffstat (limited to 'llvm/lib/IR/Core.cpp')
-rw-r--r--llvm/lib/IR/Core.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index b12c483..a93fc85 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -1009,6 +1009,13 @@ LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val) {
return nullptr;
}
+LLVMValueRef LLVMIsAValueAsMetadata(LLVMValueRef Val) {
+ if (auto *MD = dyn_cast_or_null<MetadataAsValue>(unwrap(Val)))
+ if (isa<ValueAsMetadata>(MD->getMetadata()))
+ return Val;
+ return nullptr;
+}
+
LLVMValueRef LLVMIsAMDString(LLVMValueRef Val) {
if (auto *MD = dyn_cast_or_null<MetadataAsValue>(unwrap(Val)))
if (isa<MDString>(MD->getMetadata()))
@@ -1268,6 +1275,13 @@ void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest) {
Dest[i] = getMDNodeOperandImpl(Context, N, i);
}
+void LLVMReplaceMDNodeOperandWith(LLVMValueRef V, unsigned Index,
+ LLVMMetadataRef Replacement) {
+ auto *MD = cast<MetadataAsValue>(unwrap(V));
+ auto *N = cast<MDNode>(MD->getMetadata());
+ N->replaceOperandWith(Index, unwrap<Metadata>(Replacement));
+}
+
unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char *Name) {
if (NamedMDNode *N = unwrap(M)->getNamedMetadata(Name)) {
return N->getNumOperands();