diff options
author | Jessica Paquette <jpaquette@apple.com> | 2019-09-18 22:42:25 +0000 |
---|---|---|
committer | Jessica Paquette <jpaquette@apple.com> | 2019-09-18 22:42:25 +0000 |
commit | ce65ebc39e5bac42308038aab90507611d319d26 (patch) | |
tree | f006c97f7dfa4b235407f897c5eb4cfb41b35f25 /llvm/lib/Target/AArch64/AArch64CallLowering.cpp | |
parent | 0779dffbd4a927d7bf9523482481248c51796907 (diff) | |
download | bcm5719-llvm-ce65ebc39e5bac42308038aab90507611d319d26.tar.gz bcm5719-llvm-ce65ebc39e5bac42308038aab90507611d319d26.zip |
[AArch64][GlobalISel] Support lowering musttail calls
Since we now lower most tail calls, it makes sense to support musttail.
Instead of always falling back to SelectionDAG, only fall back when a musttail
call was not able to be emitted as a tail call. Once we can handle most
incoming and outgoing arguments, we can change this to a `report_fatal_error`
like in ISelLowering.
Remove the assert that we don't have varargs and a musttail, and replace it
with a return false. Implementing this requires that we implement
`saveVarArgRegisters` from AArch64ISelLowering, which is an entirely different
patch.
Add GlobalISel lines to vararg-tallcall.ll to make sure that we produce correct
code. Right now we only fall back, but eventually this will be relevant.
Differential Revision: https://reviews.llvm.org/D67681
llvm-svn: 372273
Diffstat (limited to 'llvm/lib/Target/AArch64/AArch64CallLowering.cpp')
-rw-r--r-- | llvm/lib/Target/AArch64/AArch64CallLowering.cpp | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/llvm/lib/Target/AArch64/AArch64CallLowering.cpp b/llvm/lib/Target/AArch64/AArch64CallLowering.cpp index f331c170e85..a4f2bac8d60 100644 --- a/llvm/lib/Target/AArch64/AArch64CallLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64CallLowering.cpp @@ -596,6 +596,11 @@ bool AArch64CallLowering::isEligibleForTailCallOptimization( MachineIRBuilder &MIRBuilder, CallLoweringInfo &Info, SmallVectorImpl<ArgInfo> &InArgs, SmallVectorImpl<ArgInfo> &OutArgs) const { + + // Must pass all target-independent checks in order to tail call optimize. + if (!Info.IsTailCall) + return false; + CallingConv::ID CalleeCC = Info.CallConv; MachineFunction &MF = MIRBuilder.getMF(); const Function &CallerF = MF.getFunction(); @@ -675,8 +680,12 @@ bool AArch64CallLowering::isEligibleForTailCallOptimization( // Before we can musttail varargs, we need to forward parameters like in // r345641. Make sure that we don't enable musttail with varargs without // addressing that! - assert(!(Info.IsVarArg && Info.IsMustTailCall) && - "musttail support for varargs not implemented yet!"); + if (Info.IsVarArg && Info.IsMustTailCall) { + LLVM_DEBUG( + dbgs() + << "... Cannot handle vararg musttail functions yet.\n"); + return false; + } // Verify that the incoming and outgoing arguments from the callee are // safe to tail call. @@ -841,12 +850,6 @@ bool AArch64CallLowering::lowerCall(MachineIRBuilder &MIRBuilder, auto &DL = F.getParent()->getDataLayout(); const AArch64TargetLowering &TLI = *getTLI<AArch64TargetLowering>(); - if (Info.IsMustTailCall) { - // TODO: Until we lower all tail calls, we should fall back on this. - LLVM_DEBUG(dbgs() << "Cannot lower musttail calls yet.\n"); - return false; - } - SmallVector<ArgInfo, 8> OutArgs; for (auto &OrigArg : Info.OrigArgs) { splitToValueTypes(OrigArg, OutArgs, DL, MRI, Info.CallConv); @@ -860,8 +863,19 @@ bool AArch64CallLowering::lowerCall(MachineIRBuilder &MIRBuilder, splitToValueTypes(Info.OrigRet, InArgs, DL, MRI, F.getCallingConv()); // If we can lower as a tail call, do that instead. - if (Info.IsTailCall && - isEligibleForTailCallOptimization(MIRBuilder, Info, InArgs, OutArgs)) + bool CanTailCallOpt = + isEligibleForTailCallOptimization(MIRBuilder, Info, InArgs, OutArgs); + + // We must emit a tail call if we have musttail. + if (Info.IsMustTailCall && !CanTailCallOpt) { + // There are types of incoming/outgoing arguments we can't handle yet, so + // it doesn't make sense to actually die here like in ISelLowering. Instead, + // fall back to SelectionDAG and let it try to handle this. + LLVM_DEBUG(dbgs() << "Failed to lower musttail call as tail call\n"); + return false; + } + + if (CanTailCallOpt) return lowerTailCall(MIRBuilder, Info, OutArgs); // Find out which ABI gets to decide where things go. |