llvm.org GIT mirror llvm / de7caba
Expose TailCallKind via the LLVM C API Summary: This exposes `CallInst`'s tail call kind via new `LLVMGetTailCallKind` and `LLVMSetTailCallKind` functions. The motivation for this is to be able to see `musttail` for languages that require mandatory tail calls for correctness. Today only the weaker `LLVMSetTail` is exposed and there is no way to set `GuaranteedTailCallOpt` via the C API. Reviewers: CodaFi, jyknight, deadalnix, rnk Reviewed By: CodaFi Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66061 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368945 91177308-0d34-0410-b5e6-96231b3b80d8 Robert Widmann a month ago
4 changed file(s) with 61 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
450450 };
451451
452452 typedef unsigned LLVMAttributeIndex;
453
454 typedef enum {
455 LLVMTailCallKindNone,
456 LLVMTailCallKindTail,
457 LLVMTailCallKindMustTail,
458 LLVMTailCallKindNoTail
459 } LLVMTailCallKind;
453460
454461 /**
455462 * @}
32633270 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
32643271
32653272 /**
3273 * Obtains the kind of tail call for a call instruction.
3274 *
3275 * This only works on llvm::CallInst instructions.
3276 *
3277 * @see llvm::CallInst::getTailCallKind()
3278 */
3279 LLVMTailCallKind LLVMGetTailCallKind(LLVMValueRef CallInst);
3280
3281 /**
3282 * Set the kind of tail call for a call instruction.
3283 *
3284 * This only works on llvm::CallInst instructions.
3285 *
3286 * @see llvm::CallInst::setTailCallKind()
3287 */
3288 void LLVMSetTailCallKind(LLVMValueRef CallInst, LLVMTailCallKind TCK);
3289
3290 /**
32663291 * Return the normal destination basic block.
32673292 *
32683293 * This only works on llvm::InvokeInst instructions.
28432843 unwrap(Call)->setTailCall(isTailCall);
28442844 }
28452845
2846 LLVMTailCallKind LLVMGetTailCallKind(LLVMValueRef Call) {
2847 switch (unwrap(Call)->getTailCallKind()) {
2848 case CallInst::TailCallKind::TCK_None:
2849 return LLVMTailCallKindNone;
2850 case CallInst::TailCallKind::TCK_Tail:
2851 return LLVMTailCallKindTail;
2852 case CallInst::TailCallKind::TCK_MustTail:
2853 return LLVMTailCallKindMustTail;
2854 case CallInst::TailCallKind::TCK_NoTail:
2855 return LLVMTailCallKindNoTail;
2856 }
2857 }
2858
2859 void LLVMSetTailCallKind(LLVMValueRef Call, LLVMTailCallKind TCK) {
2860 CallInst::TailCallKind kind;
2861 switch (TCK) {
2862 case LLVMTailCallKindNone:
2863 kind = CallInst::TailCallKind::TCK_None;
2864 break;
2865 case LLVMTailCallKindTail:
2866 kind = CallInst::TailCallKind::TCK_Tail;
2867 break;
2868 case LLVMTailCallKindMustTail:
2869 kind = CallInst::TailCallKind::TCK_MustTail;
2870 break;
2871 case LLVMTailCallKindNoTail:
2872 kind = CallInst::TailCallKind::TCK_NoTail;
2873 break;
2874 }
2875
2876 unwrap(Call)->setTailCallKind(kind);
2877 }
2878
28462879 /*--.. Operations on invoke instructions (only) ............................--*/
28472880
28482881 LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef Invoke) {
5454 ret i32 %merge
5555
5656 unwind3: ; preds = %landingPad
57 %8 = tail call i32 @llvm.eh.typeid.for(i8* nonnull bitcast (%C6object9ClassInfo* @C6object9Exception__ClassInfo to i8*))
57 %8 = musttail call i32 @llvm.eh.typeid.for(i8* nonnull bitcast (%C6object9ClassInfo* @C6object9Exception__ClassInfo to i8*))
5858 %9 = icmp eq i32 %8, %5
5959 br i1 %9, label %catch, label %unwind5
6060
6161 unwind5: ; preds = %unwind3
62 %10 = tail call i32 @llvm.eh.typeid.for(i8* nonnull bitcast (%C6object9ClassInfo* @C6object9Throwable__ClassInfo to i8*))
62 %10 = notail call i32 @llvm.eh.typeid.for(i8* nonnull bitcast (%C6object9ClassInfo* @C6object9Throwable__ClassInfo to i8*))
6363 %11 = icmp eq i32 %10, %5
6464 br i1 %11, label %catch, label %unwind7
6565
642642 Args.push_back(CloneValue(LLVMGetOperand(Src, i)));
643643 LLVMValueRef Fn = CloneValue(LLVMGetCalledValue(Src));
644644 Dst = LLVMBuildCall(Builder, Fn, Args.data(), ArgCount, Name);
645 LLVMSetTailCall(Dst, LLVMIsTailCall(Src));
645 LLVMSetTailCallKind(Dst, LLVMGetTailCallKind(Src));
646646 CloneAttrs(Src, Dst);
647647 break;
648648 }