diff --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/llvm/bindings/ocaml/llvm/llvm_ocaml.c --- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c +++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c @@ -1975,12 +1975,23 @@ return Val_bool(LLVMIsTailCall(Value_val(CallInst))); } +/* llvalue -> int */ +value llvm_get_tail_call_kind(value CallInst) { + return Val_int(LLVMGetTailCallKind(Value_val(CallInst))); +} + /* bool -> llvalue -> unit */ value llvm_set_tail_call(value IsTailCall, value CallInst) { LLVMSetTailCall(Value_val(CallInst), Bool_val(IsTailCall)); return Val_unit; } +/* int -> llvalue -> unit */ +value llvm_set_tail_call_kind(value tailCallKind, value CallInst) { + LLVMSetTailCallKind(Value_val(CallInst), Int_val(tailCallKind)); + return Val_unit; +} + /* llvalue -> llbasicblock */ value llvm_get_normal_dest(value Val) { LLVMBasicBlockRef BB = LLVMGetNormalDest(Value_val(Val)); diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h --- a/llvm/include/llvm-c/Core.h +++ b/llvm/include/llvm-c/Core.h @@ -3420,6 +3420,15 @@ */ LLVMBool LLVMIsTailCall(LLVMValueRef CallInst); +/** + * Obtain the tail call kind of a call instruction. + * + * This only works on llvm::CallInst instructions. + * + * @see llvm::CallInst::getTailCallKind() + */ +unsigned LLVMGetTailCallKind(LLVMValueRef CallInst); + /** * Set whether a call instruction is a tail call. * @@ -3429,6 +3438,15 @@ */ void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall); +/** + * Set the tail call kind of a call instruction. + * + * This only works on llvm::CallInst instructions. + * + * @see llvm::CallInst::setTailCallKind() + */ +void LLVMSetTailCallKind(LLVMValueRef CallInst, unsigned TailCallKind); + /** * Return the normal destination basic block. * diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -2892,10 +2892,18 @@ return unwrap(Call)->isTailCall(); } +unsigned LLVMGetTailCallKind(LLVMValueRef Call) { + return unwrap(Call)->getTailCallKind(); +} + void LLVMSetTailCall(LLVMValueRef Call, LLVMBool isTailCall) { unwrap(Call)->setTailCall(isTailCall); } +void LLVMSetTailCallKind(LLVMValueRef Call, unsigned tailCallKind) { + unwrap(Call)->setTailCallKind((CallInst::TailCallKind)tailCallKind); +} + /*--.. Operations on invoke instructions (only) ............................--*/ LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef Invoke) { diff --git a/llvm/tools/llvm-c-test/echo.cpp b/llvm/tools/llvm-c-test/echo.cpp --- a/llvm/tools/llvm-c-test/echo.cpp +++ b/llvm/tools/llvm-c-test/echo.cpp @@ -737,6 +737,7 @@ 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; }