From 715eb502c34ee94f6bd3caa8ae8aa3bb24360753 Mon Sep 17 00:00:00 2001 From: Peter Zotov Date: Tue, 28 Oct 2014 19:46:56 +0000 Subject: [PATCH] [C API] PR19859: Add functions to query and modify branches. Patch by Gabriel Radanne . git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220817 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm-c/Core.h | 61 +++++++++++++++++++++++++++++++++++++++++++ lib/IR/Core.cpp | 28 ++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h index 485cf9481f2..30c75950a5a 100644 --- a/include/llvm-c/Core.h +++ b/include/llvm-c/Core.h @@ -2496,6 +2496,63 @@ void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall); * @} */ +/** + * @defgroup LLVMCCoreValueInstructionTerminator Terminators + * + * Functions in this group only apply to instructions that map to + * llvm::TerminatorInst instances. + * + * @{ + */ + +/** + * Return the number of successors that this terminator has. + * + * @see llvm::TerminatorInst::getNumSuccessors + */ +unsigned LLVMGetNumSuccessors(LLVMValueRef Term); + +/** + * Return the specified successor. + * + * @see llvm::TerminatorInst::getSuccessor + */ +LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i); + +/** + * Update the specified successor to point at the provided block. + * + * @see llvm::TerminatorInst::setSuccessor + */ +void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block); + +/** + * Return if a branch is conditional. + * + * This only works on llvm::BranchInst instructions. + * + * @see llvm::BranchInst::isConditional + */ +LLVMBool LLVMIsConditional(LLVMValueRef Branch); + +/** + * Return the condition of a branch instruction. + * + * This only works on llvm::BranchInst instructions. + * + * @see llvm::BranchInst::getCondition + */ +LLVMValueRef LLVMGetCondition(LLVMValueRef Branch); + +/** + * Set the condition of a branch instruction. + * + * This only works on llvm::BranchInst instructions. + * + * @see llvm::BranchInst::setCondition + */ +void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond); + /** * Obtain the default destination basic block of a switch instruction. * @@ -2505,6 +2562,10 @@ void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall); */ LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr); +/** + * @} + */ + /** * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes * diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index e8cfc79679d..f6ab9197244 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -1985,6 +1985,34 @@ void LLVMSetTailCall(LLVMValueRef Call, LLVMBool isTailCall) { unwrap(Call)->setTailCall(isTailCall); } +/*--.. Operations on terminators ...........................................--*/ + +unsigned LLVMGetNumSuccessors(LLVMValueRef Term) { + return unwrap(Term)->getNumSuccessors(); +} + +LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i) { + return wrap(unwrap(Term)->getSuccessor(i)); +} + +void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block) { + return unwrap(Term)->setSuccessor(i,unwrap(block)); +} + +/*--.. Operations on branch instructions (only) ............................--*/ + +LLVMBool LLVMIsConditional(LLVMValueRef Branch) { + return unwrap(Branch)->isConditional(); +} + +LLVMValueRef LLVMGetCondition(LLVMValueRef Branch) { + return wrap(unwrap(Branch)->getCondition()); +} + +void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond) { + return unwrap(Branch)->setCondition(unwrap(Cond)); +} + /*--.. Operations on switch instructions (only) ............................--*/ LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef Switch) { -- 2.34.1