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 @@ -452,6 +452,13 @@ typedef unsigned LLVMAttributeIndex; +typedef enum { + LLVMTailCallKindNone, + LLVMTailCallKindTail, + LLVMTailCallKindMustTail, + LLVMTailCallKindNoTail +} LLVMTailCallKind; + /** * @} */ @@ -3263,6 +3270,24 @@ */ void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall); +/** + * Obtains the kind of tail call for a call instruction. + * + * This only works on llvm::CallInst instructions. + * + * @see llvm::CallInst::getTailCallKind() + */ +LLVMTailCallKind LLVMGetTailCallKind(LLVMValueRef CallInst); + +/** + * Set the kind of tail call for a call instruction. + * + * This only works on llvm::CallInst instructions. + * + * @see llvm::CallInst::setTailCallKind() + */ +void LLVMSetTailCallKind(LLVMValueRef CallInst, LLVMTailCallKind TCK); + /** * 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 @@ -2844,6 +2844,39 @@ unwrap(Call)->setTailCall(isTailCall); } +LLVMTailCallKind LLVMGetTailCallKind(LLVMValueRef Call) { + switch (unwrap(Call)->getTailCallKind()) { + case CallInst::TailCallKind::TCK_None: + return LLVMTailCallKindNone; + case CallInst::TailCallKind::TCK_Tail: + return LLVMTailCallKindTail; + case CallInst::TailCallKind::TCK_MustTail: + return LLVMTailCallKindMustTail; + case CallInst::TailCallKind::TCK_NoTail: + return LLVMTailCallKindNoTail; + } +} + +void LLVMSetTailCallKind(LLVMValueRef Call, LLVMTailCallKind TCK) { + CallInst::TailCallKind kind; + switch (TCK) { + case LLVMTailCallKindNone: + kind = CallInst::TailCallKind::TCK_None; + break; + case LLVMTailCallKindTail: + kind = CallInst::TailCallKind::TCK_Tail; + break; + case LLVMTailCallKindMustTail: + kind = CallInst::TailCallKind::TCK_MustTail; + break; + case LLVMTailCallKindNoTail: + kind = CallInst::TailCallKind::TCK_NoTail; + break; + } + + unwrap(Call)->setTailCallKind(kind); +} + /*--.. Operations on invoke instructions (only) ............................--*/ LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef Invoke) { diff --git a/llvm/test/Bindings/llvm-c/invoke.ll b/llvm/test/Bindings/llvm-c/invoke.ll --- a/llvm/test/Bindings/llvm-c/invoke.ll +++ b/llvm/test/Bindings/llvm-c/invoke.ll @@ -55,12 +55,12 @@ ret i32 %merge unwind3: ; preds = %landingPad - %8 = tail call i32 @llvm.eh.typeid.for(i8* nonnull bitcast (%C6object9ClassInfo* @C6object9Exception__ClassInfo to i8*)) + %8 = musttail call i32 @llvm.eh.typeid.for(i8* nonnull bitcast (%C6object9ClassInfo* @C6object9Exception__ClassInfo to i8*)) %9 = icmp eq i32 %8, %5 br i1 %9, label %catch, label %unwind5 unwind5: ; preds = %unwind3 - %10 = tail call i32 @llvm.eh.typeid.for(i8* nonnull bitcast (%C6object9ClassInfo* @C6object9Throwable__ClassInfo to i8*)) + %10 = notail call i32 @llvm.eh.typeid.for(i8* nonnull bitcast (%C6object9ClassInfo* @C6object9Throwable__ClassInfo to i8*)) %11 = icmp eq i32 %10, %5 br i1 %11, label %catch, label %unwind7 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 @@ -643,7 +643,7 @@ Args.push_back(CloneValue(LLVMGetOperand(Src, i))); LLVMValueRef Fn = CloneValue(LLVMGetCalledValue(Src)); Dst = LLVMBuildCall(Builder, Fn, Args.data(), ArgCount, Name); - LLVMSetTailCall(Dst, LLVMIsTailCall(Src)); + LLVMSetTailCallKind(Dst, LLVMGetTailCallKind(Src)); CloneAttrs(Src, Dst); break; }