[PATCH] D153107: [llvm-c] Add LLVMSetTailCallKind and LLVMGetTailCallKind
YAMAMOTO Takashi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 23 08:58:41 PDT 2023
yamt updated this revision to Diff 533979.
yamt added a comment.
add a test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D153107/new/
https://reviews.llvm.org/D153107
Files:
llvm/include/llvm-c/Core.h
llvm/lib/IR/Core.cpp
llvm/test/Bindings/llvm-c/echo.ll
llvm/tools/llvm-c-test/echo.cpp
Index: llvm/tools/llvm-c-test/echo.cpp
===================================================================
--- llvm/tools/llvm-c-test/echo.cpp
+++ llvm/tools/llvm-c-test/echo.cpp
@@ -736,7 +736,7 @@
LLVMTypeRef FnTy = CloneType(LLVMGetCalledFunctionType(Src));
LLVMValueRef Fn = CloneValue(LLVMGetCalledValue(Src));
Dst = LLVMBuildCall2(Builder, FnTy, Fn, Args.data(), ArgCount, Name);
- LLVMSetTailCall(Dst, LLVMIsTailCall(Src));
+ LLVMSetTailCallKind(Dst, LLVMGetTailCallKind(Src));
CloneAttrs(Src, Dst);
break;
}
Index: llvm/test/Bindings/llvm-c/echo.ll
===================================================================
--- llvm/test/Bindings/llvm-c/echo.ll
+++ llvm/test/Bindings/llvm-c/echo.ll
@@ -98,6 +98,16 @@
ret i32 %1
}
+define i32 @tailcall() {
+ %1 = tail call i32 @call()
+ ret i32 %1
+}
+
+define i32 @musttailcall() {
+ %1 = musttail call i32 @call()
+ ret i32 %1
+}
+
define i32 @cond(i32 %a, i32 %b) {
br label %br
unreachable:
Index: llvm/lib/IR/Core.cpp
===================================================================
--- llvm/lib/IR/Core.cpp
+++ llvm/lib/IR/Core.cpp
@@ -2896,6 +2896,14 @@
unwrap<CallInst>(Call)->setTailCall(isTailCall);
}
+LLVMTailCallKind LLVMGetTailCallKind(LLVMValueRef Call) {
+ return (LLVMTailCallKind)unwrap<CallInst>(Call)->getTailCallKind();
+}
+
+void LLVMSetTailCallKind(LLVMValueRef Call, LLVMTailCallKind kind) {
+ unwrap<CallInst>(Call)->setTailCallKind((CallInst::TailCallKind)kind);
+}
+
/*--.. Operations on invoke instructions (only) ............................--*/
LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef Invoke) {
Index: llvm/include/llvm-c/Core.h
===================================================================
--- llvm/include/llvm-c/Core.h
+++ llvm/include/llvm-c/Core.h
@@ -468,6 +468,18 @@
LLVMAttributeFunctionIndex = -1,
};
+/**
+ * Tail call kind for LLVMSetTailCallKind and LLVMGetTailCallKind.
+ *
+ * Note that 'musttail' implies 'tail'.
+ */
+typedef enum {
+ LLVMTailCallKindNone = 0,
+ LLVMTailCallKindTail = 1,
+ LLVMTailCallKindMustTail = 2,
+ LLVMTailCallKindNoTail = 3,
+} LLVMTailCallKind;
+
typedef unsigned LLVMAttributeIndex;
/**
@@ -3429,6 +3441,20 @@
*/
void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
+/**
+ * Obtain a tail call kind of the call instruction.
+ *
+ * @see llvm::CallInst::setTailCallKind()
+ */
+LLVMTailCallKind LLVMGetTailCallKind(LLVMValueRef CallInst);
+
+/**
+ * Set the call kind of the call instruction.
+ *
+ * @see llvm::CallInst::getTailCallKind()
+ */
+void LLVMSetTailCallKind(LLVMValueRef CallInst, LLVMTailCallKind kind);
+
/**
* Return the normal destination basic block.
*
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153107.533979.patch
Type: text/x-patch
Size: 2745 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230623/e385f8ad/attachment.bin>
More information about the llvm-commits
mailing list