Skip to content

Commit

Permalink
Decorate thunk target calls as tail-calls (=> jumps)
Browse files Browse the repository at this point in the history
I noticed that the C++ thunks would adjust the `this` pointer and then
jump directly to the actual target function.
The D thunks (on Linux, verified by disassembling) on the other hand
performed a regular call + return. Requesting tail-calls here leads to
direct jumps for D thunks as well, improving performance when calling
virtual functions via interfaces.
  • Loading branch information
kinke committed Sep 26, 2016
1 parent 9e99411 commit 642d755
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ir/irclass.cpp
Expand Up @@ -419,15 +419,15 @@ llvm::GlobalVariable *IrAggr::getInterfaceVtbl(BaseClass *b, bool new_instance,
gIR->DBuilder.EmitStopPoint(fd->loc);

// call the real vtbl function.
llvm::CallSite call = gIR->ir->CreateCall(irFunc->func, args);
call.setCallingConv(irFunc->func->getCallingConv());
llvm::CallInst *call = gIR->ir->CreateCall(irFunc->func, args);
call->setCallingConv(irFunc->func->getCallingConv());
call->setTailCallKind(llvm::CallInst::TCK_Tail);

// return from the thunk
if (thunk->getReturnType() == LLType::getVoidTy(gIR->context())) {
llvm::ReturnInst::Create(gIR->context(), beginbb);
} else {
llvm::ReturnInst::Create(gIR->context(), call.getInstruction(),
beginbb);
llvm::ReturnInst::Create(gIR->context(), call, beginbb);
}

gIR->DBuilder.EmitFuncEnd(thunkFd);
Expand Down

0 comments on commit 642d755

Please sign in to comment.