From: Robert Widmann Date: Fri, 5 Apr 2019 20:32:43 +0000 (+0000) Subject: [LLVM-C] Add bindings to insert basic blocks X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=083f0c85ec618fe2263f9087ab38a707652aebce;p=llvm [LLVM-C] Add bindings to insert basic blocks Summary: Now that we can create standalone basic blocks, it's useful to be able to append them. Add bindings to - Insert a basic block after the current insertion block - Append a basic block to the end of a function's list of basic blocks Reviewers: whitequark, deadalnix, harlanhaskins Reviewed By: whitequark, harlanhaskins Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59658 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357812 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h index 393250f7f8c..6adb4d80011 100644 --- a/include/llvm-c/Core.h +++ b/include/llvm-c/Core.h @@ -2916,6 +2916,24 @@ LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB); */ 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 LLVMInsertExistingBasicBlockAfterInsertBlock(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 LLVMAppendExistingBasicBlock(LLVMValueRef Fn, + LLVMBasicBlockRef BB); + /** * Create a new basic block without inserting it into a function. * diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index aa6bc542b4e..997f5330dec 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -2609,6 +2609,20 @@ LLVMBasicBlockRef LLVMCreateBasicBlockInContext(LLVMContextRef C, return wrap(llvm::BasicBlock::Create(*unwrap(C), Name)); } +void LLVMInsertExistingBasicBlockAfterInsertBlock(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 LLVMAppendExistingBasicBlock(LLVMValueRef Fn, + LLVMBasicBlockRef BB) { + unwrap(Fn)->getBasicBlockList().push_back(unwrap(BB)); +} + LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C, LLVMValueRef FnRef, const char *Name) {