From: Robert Widmann Date: Tue, 8 Jan 2019 06:24:19 +0000 (+0000) Subject: [LLVM-C] Allow For Creating a BasicBlock without a Parent Function X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=146b0f2c22073bc9c8f1a2585db2769cdc958106;p=llvm [LLVM-C] Allow For Creating a BasicBlock without a Parent Function Summary: Add a utility function for creating a basic block without a parent function. A useful operation for compilers that need to synthesize and conditionally insert code without having to bother with appending and immediately unlinking a block. Reviewers: whitequark, deadalnix Reviewed By: whitequark Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D56279 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350608 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h index 264cf838536..e22e4b78eec 100644 --- a/include/llvm-c/Core.h +++ b/include/llvm-c/Core.h @@ -2806,6 +2806,15 @@ LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB); */ LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn); +/** + * Create a new basic block without inserting it into a function. + * + * @see llvm::BasicBlock::Create() + */ +LLVMBasicBlockRef LLVMCreateBasicBlockInContext(LLVMContextRef C, + const char *Name, + size_t NameLen); + /** * Append a basic block to the end of a function. * diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index 921c830cbf7..6f7c7afc59d 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -2532,6 +2532,12 @@ LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB) { return wrap(&*--I); } +LLVMBasicBlockRef LLVMCreateBasicBlockInContext(LLVMContextRef C, + const char *Name, + size_t NameLen) { + return wrap(llvm::BasicBlock::Create(*unwrap(C), StringRef(Name, NameLen))); +} + LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C, LLVMValueRef FnRef, const char *Name) {