Skip to content

Commit b9e6492

Browse files
authored
Merge pull request #3016 from etcwilde/swift-next/cherry-pick-swifttailcc-musttail
Cherry-Pick -enable-swifttail-musttail-check flag
2 parents 917f76a + 7220c40 commit b9e6492

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3453,7 +3453,26 @@ static AttrBuilder getParameterABIAttributes(int I, AttributeList Attrs) {
34533453
return Copy;
34543454
}
34553455

3456+
static cl::opt<bool>
3457+
EnableSwiftTailCCMustTailCheck("enable-swifttailcc-musttail-check",
3458+
cl::init(false), cl::desc("Check that tail calls from swifttailcc functions to"
3459+
" swifttailcc functions are marked musttail."));
3460+
34563461
void Verifier::verifyMustTailCall(CallInst &CI) {
3462+
if (!CI.isMustTailCall()) {
3463+
#ifndef NDEBUG
3464+
if (EnableSwiftTailCCMustTailCheck &&
3465+
CI.getCallingConv() == CallingConv::SwiftTail &&
3466+
CI.getCaller()->getCallingConv() == CallingConv::SwiftTail &&
3467+
isa_and_nonnull<ReturnInst>(CI.getNextNode())) {
3468+
Assert(
3469+
false, "tail call from swifttail->swiftail should be marked musttail",
3470+
&CI);
3471+
}
3472+
#endif
3473+
return;
3474+
}
3475+
34573476
Assert(!CI.isInlineAsm(), "cannot use musttail call with inline asm", &CI);
34583477

34593478
Function *F = CI.getParent()->getParent();
@@ -3538,9 +3557,7 @@ void Verifier::verifyMustTailCall(CallInst &CI) {
35383557

35393558
void Verifier::visitCallInst(CallInst &CI) {
35403559
visitCallBase(CI);
3541-
3542-
if (CI.isMustTailCall())
3543-
verifyMustTailCall(CI);
3560+
verifyMustTailCall(CI);
35443561
}
35453562

35463563
void Verifier::visitInvokeInst(InvokeInst &II) {

llvm/lib/Transforms/IPO/MergeFunctions.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,11 @@ void MergeFunctions::writeThunk(Function *F, Function *G) {
709709

710710
CallInst *CI = Builder.CreateCall(F, Args);
711711
ReturnInst *RI = nullptr;
712-
CI->setTailCall();
712+
bool isSwiftTailCall =
713+
F->getCallingConv() == CallingConv::SwiftTail &&
714+
G->getCallingConv() == CallingConv::SwiftTail;
715+
CI->setTailCallKind(
716+
isSwiftTailCall ? llvm::CallInst::TCK_MustTail : llvm::CallInst::TCK_Tail);
713717
CI->setCallingConv(F->getCallingConv());
714718
CI->setAttributes(F->getAttributes());
715719
if (H->getReturnType()->isVoidTy()) {

0 commit comments

Comments
 (0)