[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 264cf83..e22e4b7 100644
--- a/include/llvm-c/Core.h
+++ b/include/llvm-c/Core.h
@@ -2807,6 +2807,15 @@
 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.
  *
  * @see llvm::BasicBlock::Create()
diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp
index 921c830..6f7c7af 100644
--- a/lib/IR/Core.cpp
+++ b/lib/IR/Core.cpp
@@ -2532,6 +2532,12 @@
   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) {