[llvm] 955fc63 - [llvm-c] Add LLVMSetTailCallKind and LLVMGetTailCallKind
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 31 08:30:53 PDT 2023
Author: YAMAMOTO Takashi
Date: 2023-07-31T08:30:39-07:00
New Revision: 955fc63ab9c585cf2e7afda724ad90d1368e5173
URL: https://github.com/llvm/llvm-project/commit/955fc63ab9c585cf2e7afda724ad90d1368e5173
DIFF: https://github.com/llvm/llvm-project/commit/955fc63ab9c585cf2e7afda724ad90d1368e5173.diff
LOG: [llvm-c] Add LLVMSetTailCallKind and LLVMGetTailCallKind
Reviewed By: aeubanks
Differential Revision: https://reviews.llvm.org/D153107
Added:
Modified:
llvm/docs/ReleaseNotes.rst
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
Removed:
################################################################################
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 59918ca763dc3e..51af9a2e1b5594 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -116,6 +116,10 @@ Changes to the Python bindings
Changes to the C API
--------------------
+* Added ``LLVMGetTailCallKind`` and ``LLVMSetTailCallKind`` to
+ allow getting and setting ``tail``, ``musttail``, and ``notail``
+ attributes on call instructions.
+
Changes to the CodeGen infrastructure
-------------------------------------
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index fbba8ca42a8c76..8f5fb152a7d72d 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -468,6 +468,20 @@ enum {
LLVMAttributeFunctionIndex = -1,
};
+/**
+ * Tail call kind for LLVMSetTailCallKind and LLVMGetTailCallKind.
+ *
+ * Note that 'musttail' implies 'tail'.
+ *
+ * @see CallInst::TailCallKind
+ */
+typedef enum {
+ LLVMTailCallKindNone = 0,
+ LLVMTailCallKindTail = 1,
+ LLVMTailCallKindMustTail = 2,
+ LLVMTailCallKindNoTail = 3,
+} LLVMTailCallKind;
+
typedef unsigned LLVMAttributeIndex;
/**
@@ -3429,6 +3443,20 @@ LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
*/
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.
*
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index f7b6d54013de54..129e91b5ba3d19 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -2896,6 +2896,14 @@ void LLVMSetTailCall(LLVMValueRef Call, LLVMBool isTailCall) {
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) {
diff --git a/llvm/test/Bindings/llvm-c/echo.ll b/llvm/test/Bindings/llvm-c/echo.ll
index 438a2be5b8489e..3f20fb87578547 100644
--- a/llvm/test/Bindings/llvm-c/echo.ll
+++ b/llvm/test/Bindings/llvm-c/echo.ll
@@ -98,6 +98,21 @@ define i32 @call() {
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 @notailcall() {
+ %1 = notail call i32 @call()
+ ret i32 %1
+}
+
define i32 @cond(i32 %a, i32 %b) {
br label %br
unreachable:
diff --git a/llvm/tools/llvm-c-test/echo.cpp b/llvm/tools/llvm-c-test/echo.cpp
index b0535c7c271768..91c554510d32aa 100644
--- a/llvm/tools/llvm-c-test/echo.cpp
+++ b/llvm/tools/llvm-c-test/echo.cpp
@@ -736,7 +736,7 @@ struct FunCloner {
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;
}
More information about the llvm-commits
mailing list