diff options
author | Sean Fertile <sfertile@ca.ibm.com> | 2017-11-15 16:53:41 +0000 |
---|---|---|
committer | Sean Fertile <sfertile@ca.ibm.com> | 2017-11-15 16:53:41 +0000 |
commit | 7b056b3048b4c53bbba0e0388570bc6d3aad29a8 (patch) | |
tree | 4e55d85e222cbf6186b2125964575d1548c4f73a /llvm/lib | |
parent | ac7e3d6451ae834634e56fbeff6934774cb3003d (diff) | |
download | bcm5719-llvm-7b056b3048b4c53bbba0e0388570bc6d3aad29a8.tar.gz bcm5719-llvm-7b056b3048b4c53bbba0e0388570bc6d3aad29a8.zip |
[PowerPC] Split out the tailcall calling convention checks. NFC.
Move the calling convention checks for tail-call eligibility for the 64-bit
SysV ABI into a separate function. This is so that it can be shared with
'mayBeEmittedAsTailCall' in a subsequent change.
llvm-svn: 318305
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Target/PowerPC/PPCISelLowering.cpp | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp index 62ade966145..2d15b738a31 100644 --- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp +++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp @@ -4392,6 +4392,20 @@ hasSameArgumentList(const Function *CallerFn, ImmutableCallSite CS) { return true; } +// Returns true if TCO is possible between the callers and callees +// calling conventions. +static bool +areCallingConvEligibleForTCO_64SVR4(CallingConv::ID CallerCC, + CallingConv::ID CalleeCC) { + // Tail or Sibling call optimization (TCO/SCO) needs callee and caller to + // have the same calling convention. + if (CallerCC != CalleeCC) + return false; + + // Tail or Sibling calls can be done with fastcc/ccc. + return (CallerCC == CallingConv::Fast || CallerCC == CallingConv::C); +} + bool PPCTargetLowering::IsEligibleForTailCallOptimization_64SVR4( SDValue Callee, @@ -4408,15 +4422,9 @@ PPCTargetLowering::IsEligibleForTailCallOptimization_64SVR4( // Variadic argument functions are not supported. if (isVarArg) return false; - MachineFunction &MF = DAG.getMachineFunction(); - CallingConv::ID CallerCC = MF.getFunction()->getCallingConv(); - - // Tail or Sibling call optimization (TCO/SCO) needs callee and caller has - // the same calling convention - if (CallerCC != CalleeCC) return false; - - // SCO support C calling convention - if (CalleeCC != CallingConv::Fast && CalleeCC != CallingConv::C) + auto *Caller = DAG.getMachineFunction().getFunction(); + // Check that the calling conventions are compatible for tco. + if (!areCallingConvEligibleForTCO_64SVR4(Caller->getCallingConv(), CalleeCC)) return false; // Caller contains any byval parameter is not supported. @@ -4438,7 +4446,7 @@ PPCTargetLowering::IsEligibleForTailCallOptimization_64SVR4( // If the caller and callee potentially have different TOC bases then we // cannot tail call since we need to restore the TOC pointer after the call. // ref: https://bugzilla.mozilla.org/show_bug.cgi?id=973977 - if (!callsShareTOCBase(MF.getFunction(), Callee, getTargetMachine())) + if (!callsShareTOCBase(Caller, Callee, getTargetMachine())) return false; // TCO allows altering callee ABI, so we don't have to check further. @@ -4450,7 +4458,7 @@ PPCTargetLowering::IsEligibleForTailCallOptimization_64SVR4( // If callee use the same argument list that caller is using, then we can // apply SCO on this case. If it is not, then we need to check if callee needs // stack for passing arguments. - if (!hasSameArgumentList(MF.getFunction(), CS) && + if (!hasSameArgumentList(Caller, CS) && needStackSlotPassParameters(Subtarget, Outs)) { return false; } |