[C API] PR19859: Add functions to query and modify branches.

Patch by Gabriel Radanne <drupyog@zoho.com>.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220817 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Peter Zotov 2014-10-28 19:46:56 +00:00
parent 4c4f5ece75
commit 715eb502c3
2 changed files with 89 additions and 0 deletions

View File

@ -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
*

View File

@ -1985,6 +1985,34 @@ void LLVMSetTailCall(LLVMValueRef Call, LLVMBool isTailCall) {
unwrap<CallInst>(Call)->setTailCall(isTailCall);
}
/*--.. Operations on terminators ...........................................--*/
unsigned LLVMGetNumSuccessors(LLVMValueRef Term) {
return unwrap<TerminatorInst>(Term)->getNumSuccessors();
}
LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i) {
return wrap(unwrap<TerminatorInst>(Term)->getSuccessor(i));
}
void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block) {
return unwrap<TerminatorInst>(Term)->setSuccessor(i,unwrap(block));
}
/*--.. Operations on branch instructions (only) ............................--*/
LLVMBool LLVMIsConditional(LLVMValueRef Branch) {
return unwrap<BranchInst>(Branch)->isConditional();
}
LLVMValueRef LLVMGetCondition(LLVMValueRef Branch) {
return wrap(unwrap<BranchInst>(Branch)->getCondition());
}
void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond) {
return unwrap<BranchInst>(Branch)->setCondition(unwrap(Cond));
}
/*--.. Operations on switch instructions (only) ............................--*/
LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef Switch) {