[PATCH] D59658: [LLVM-C] Add bindings to insert basic blocks
Robert Widmann via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 21 11:28:51 PDT 2019
CodaFi created this revision.
CodaFi added reviewers: whitequark, deadalnix.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
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
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D59658
Files:
llvm/include/llvm-c/Core.h
llvm/lib/IR/Core.cpp
Index: llvm/lib/IR/Core.cpp
===================================================================
--- llvm/lib/IR/Core.cpp
+++ llvm/lib/IR/Core.cpp
@@ -2605,6 +2605,20 @@
return wrap(llvm::BasicBlock::Create(*unwrap(C), Name));
}
+void LLVMInsertBasicBlockAfterInsertBlock(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 LLVMAppendBasicBlockToFunction(LLVMValueRef Fn,
+ LLVMBasicBlockRef BB) {
+ unwrap<Function>(Fn)->getBasicBlockList().push_back(unwrap(BB));
+}
+
LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
LLVMValueRef FnRef,
const char *Name) {
Index: llvm/include/llvm-c/Core.h
===================================================================
--- llvm/include/llvm-c/Core.h
+++ llvm/include/llvm-c/Core.h
@@ -2909,6 +2909,24 @@
*/
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 LLVMInsertBasicBlockAfterInsertBlock(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 LLVMAppendBasicBlockToFunction(LLVMValueRef Fn,
+ LLVMBasicBlockRef BB);
+
/**
* Create a new basic block without inserting it into a function.
*
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59658.191751.patch
Type: text/x-patch
Size: 1995 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190321/3de5fe56/attachment.bin>
More information about the llvm-commits
mailing list