[PATCH] D52968: [TI removal] Update the C API for the move away from `TerminatorInst`.

Chandler Carruth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 7 02:05:57 PDT 2018


chandlerc created this revision.
chandlerc added a reviewer: echristo.
Herald added subscribers: hiraditya, mcrosier, sanjoy.
Herald added a reviewer: deadalnix.
chandlerc added a comment.

Sending this for pre-commit review as I want to be sure I'm doing the right thing w/ the C-API here.


This is the most critical part of the C API update. It adds a predicate
matching `Instruction::isTerminator` and moves the generic methods to
work on `Instruction` instances that satisfy this predicate rather than
requiring a specific type.

There remain two other uses of `TerminatorInst` in the C API: the return
type of the C API wrapping `BasicBlock::getTerminator` and the core type
hierarchy. Each of those will be removed as the corresponding aspect of
the IR's C++ API is updated. These should not in fact be breaking
changes however.


Repository:
  rL LLVM

https://reviews.llvm.org/D52968

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
@@ -2522,6 +2522,12 @@
   return nullptr;
 }
 
+LLVMBool LLVMIsTerminator(LLVMValueRef Inst) {
+  if (Instruction *I = dyn_cast<Instruction>(unwrap(Inst)))
+    return I->isTerminator();
+  return false;
+}
+
 unsigned LLVMGetNumArgOperands(LLVMValueRef Instr) {
   if (FuncletPadInst *FPI = dyn_cast<FuncletPadInst>(unwrap(Instr))) {
     return FPI->getNumArgOperands();
@@ -2637,15 +2643,15 @@
 /*--.. Operations on terminators ...........................................--*/
 
 unsigned LLVMGetNumSuccessors(LLVMValueRef Term) {
-  return unwrap<TerminatorInst>(Term)->getNumSuccessors();
+  return unwrap<Instruction>(Term)->getNumSuccessors();
 }
 
 LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i) {
-  return wrap(unwrap<TerminatorInst>(Term)->getSuccessor(i));
+  return wrap(unwrap<Instruction>(Term)->getSuccessor(i));
 }
 
 void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block) {
-  return unwrap<TerminatorInst>(Term)->setSuccessor(i,unwrap(block));
+  return unwrap<Instruction>(Term)->setSuccessor(i,unwrap(block));
 }
 
 /*--.. Operations on branch instructions (only) ............................--*/
Index: llvm/include/llvm-c/Core.h
===================================================================
--- llvm/include/llvm-c/Core.h
+++ llvm/include/llvm-c/Core.h
@@ -2913,6 +2913,13 @@
  */
 LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst);
 
+/**
+ * Determine whether an instruction is a terminator.
+ *
+ * @see llvm::Instruction::isTerminator()
+ */
+LLVMBool LLVMIsTerminator(LLVMValueRef Inst);
+
 /**
  * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
  *
@@ -3053,30 +3060,30 @@
 /**
  * @defgroup LLVMCCoreValueInstructionTerminator Terminators
  *
- * Functions in this group only apply to instructions that map to
- * llvm::TerminatorInst instances.
+ * Functions in this group only apply to instructions for which LLVMIsTerminator
+ * returns true.
  *
  * @{
  */
 
 /**
  * Return the number of successors that this terminator has.
  *
- * @see llvm::TerminatorInst::getNumSuccessors
+ * @see llvm::Instruction::getNumSuccessors
  */
 unsigned LLVMGetNumSuccessors(LLVMValueRef Term);
 
 /**
  * Return the specified successor.
  *
- * @see llvm::TerminatorInst::getSuccessor
+ * @see llvm::Instruction::getSuccessor
  */
 LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i);
 
 /**
  * Update the specified successor to point at the provided block.
  *
- * @see llvm::TerminatorInst::setSuccessor
+ * @see llvm::Instruction::setSuccessor
  */
 void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52968.168585.patch
Type: text/x-patch
Size: 2785 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181007/fa57f97b/attachment.bin>


More information about the llvm-commits mailing list