]> granicus.if.org Git - llvm/commitdiff
[LLVM-C] Allow For Creating a BasicBlock without a Parent Function
authorRobert Widmann <devteam.codafi@gmail.com>
Tue, 8 Jan 2019 06:24:19 +0000 (06:24 +0000)
committerRobert Widmann <devteam.codafi@gmail.com>
Tue, 8 Jan 2019 06:24:19 +0000 (06:24 +0000)
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

include/llvm-c/Core.h
lib/IR/Core.cpp

index 264cf83853616bb3c81d5373e7d7091bf874867b..e22e4b78eec63359b58de718050e4c360275d3c3 100644 (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.
  *
index 921c830cbf785f7fba8de9bd54acd2bc5451f20b..6f7c7afc59de2cc2af32458c79f765c8892e353d 100644 (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) {