diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h --- a/llvm/include/llvm-c/Core.h +++ b/llvm/include/llvm-c/Core.h @@ -2909,6 +2909,24 @@ */ LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn); +/** + * Insert the given basic block after the insertion point of the given builder. + * + * The insertion point must be valid. + * + * @see llvm::Function::BasicBlockListType::insertAfter() + */ +void LLVMInsertBasicBlockAfterInsertBlock(LLVMBuilderRef Builder, + LLVMBasicBlockRef BB); + +/** + * Append the given basic block to the basic block list of the given function. + * + * @see llvm::Function::BasicBlockListType::push_back() + */ +void LLVMAppendBasicBlockToFunction(LLVMValueRef Fn, + LLVMBasicBlockRef BB); + /** * Create a new basic block without inserting it into a function. * diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -2605,6 +2605,20 @@ return wrap(llvm::BasicBlock::Create(*unwrap(C), Name)); } +void LLVMInsertBasicBlockAfterInsertBlock(LLVMBuilderRef Builder, + LLVMBasicBlockRef BB) { + BasicBlock *ToInsert = unwrap(BB); + BasicBlock *CurBB = unwrap(Builder)->GetInsertBlock(); + assert(CurBB && "current insertion point is invalid!"); + CurBB->getParent()->getBasicBlockList().insertAfter(CurBB->getIterator(), + ToInsert); +} + +void LLVMAppendBasicBlockToFunction(LLVMValueRef Fn, + LLVMBasicBlockRef BB) { + unwrap(Fn)->getBasicBlockList().push_back(unwrap(BB)); +} + LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C, LLVMValueRef FnRef, const char *Name) {