Index: llvm/include/llvm-c/Core.h =================================================================== --- llvm/include/llvm-c/Core.h +++ llvm/include/llvm-c/Core.h @@ -2913,6 +2913,13 @@ */ LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst); +/** + * Determine whether an instruction is a terminator. + * + * @see llvm::Instruction::isTerminator() + */ +LLVMBool LLVMIsTerminator(LLVMValueRef Inst); + /** * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations * @@ -3053,8 +3060,8 @@ /** * @defgroup LLVMCCoreValueInstructionTerminator Terminators * - * Functions in this group only apply to instructions that map to - * llvm::TerminatorInst instances. + * Functions in this group only apply to instructions for which LLVMIsTerminator + * returns true. * * @{ */ @@ -3062,21 +3069,21 @@ /** * Return the number of successors that this terminator has. * - * @see llvm::TerminatorInst::getNumSuccessors + * @see llvm::Instruction::getNumSuccessors */ unsigned LLVMGetNumSuccessors(LLVMValueRef Term); /** * Return the specified successor. * - * @see llvm::TerminatorInst::getSuccessor + * @see llvm::Instruction::getSuccessor */ LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i); /** * Update the specified successor to point at the provided block. * - * @see llvm::TerminatorInst::setSuccessor + * @see llvm::Instruction::setSuccessor */ void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block); Index: llvm/lib/IR/Core.cpp =================================================================== --- llvm/lib/IR/Core.cpp +++ llvm/lib/IR/Core.cpp @@ -2522,6 +2522,12 @@ return nullptr; } +LLVMBool LLVMIsTerminator(LLVMValueRef Inst) { + if (Instruction *I = dyn_cast(unwrap(Inst))) + return I->isTerminator(); + return false; +} + unsigned LLVMGetNumArgOperands(LLVMValueRef Instr) { if (FuncletPadInst *FPI = dyn_cast(unwrap(Instr))) { return FPI->getNumArgOperands(); @@ -2637,15 +2643,15 @@ /*--.. Operations on terminators ...........................................--*/ unsigned LLVMGetNumSuccessors(LLVMValueRef Term) { - return unwrap(Term)->getNumSuccessors(); + return unwrap(Term)->getNumSuccessors(); } LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i) { - return wrap(unwrap(Term)->getSuccessor(i)); + return wrap(unwrap(Term)->getSuccessor(i)); } void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block) { - return unwrap(Term)->setSuccessor(i,unwrap(block)); + return unwrap(Term)->setSuccessor(i,unwrap(block)); } /*--.. Operations on branch instructions (only) ............................--*/