[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

llvm-svn: 350608
This commit is contained in:
Robert Widmann 2019-01-08 06:24:19 +00:00
parent 40dc48be0e
commit 616ed17221
2 changed files with 15 additions and 0 deletions

View File

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

View File

@ -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) {