diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h index bfbc6322902..4f9da09a6d8 100644 --- a/include/llvm-c/Core.h +++ b/include/llvm-c/Core.h @@ -2408,6 +2408,16 @@ LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst); */ LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst); +/** + * Create a copy of 'this' instruction that is identical in all ways + * except the following: + * * The instruction has no parent + * * The instruction has no name + * + * @see llvm::Instruction::clone() + */ +LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst); + /** * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations * diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index acf63a36d26..f1e134233e6 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -1888,6 +1888,12 @@ LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst) { return (LLVMOpcode)0; } +LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst) { + if (Instruction *C = dyn_cast(unwrap(Inst))) + return wrap(C->clone()); + return nullptr; +} + /*--.. Call and invoke instructions ........................................--*/ unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) {