@@ -2021,6 +2021,22 @@ X86TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
2021
2021
if (CallConv == CallingConv::X86_INTR)
2022
2022
report_fatal_error (" X86 interrupts may not be called directly" );
2023
2023
2024
+ // Analyze operands of the call, assigning locations to each operand.
2025
+ SmallVector<CCValAssign, 16 > ArgLocs;
2026
+ CCState CCInfo (CallConv, isVarArg, MF, ArgLocs, *DAG.getContext ());
2027
+
2028
+ // Allocate shadow area for Win64.
2029
+ if (IsWin64)
2030
+ CCInfo.AllocateStack (32 , Align (8 ));
2031
+
2032
+ CCInfo.AnalyzeArguments (Outs, CC_X86);
2033
+
2034
+ // In vectorcall calling convention a second pass is required for the HVA
2035
+ // types.
2036
+ if (CallingConv::X86_VectorCall == CallConv) {
2037
+ CCInfo.AnalyzeArgumentsSecondPass (Outs, CC_X86);
2038
+ }
2039
+
2024
2040
bool IsMustTail = CLI.CB && CLI.CB ->isMustTailCall ();
2025
2041
if (Subtarget.isPICStyleGOT () && !IsGuaranteeTCO && !IsMustTail) {
2026
2042
// If we are using a GOT, disable tail calls to external symbols with
@@ -2036,9 +2052,8 @@ X86TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
2036
2052
2037
2053
if (isTailCall && !IsMustTail) {
2038
2054
// Check if it's really possible to do a tail call.
2039
- isTailCall = IsEligibleForTailCallOptimization (
2040
- Callee, CallConv, IsCalleePopSRet, isVarArg, CLI.RetTy , Outs, OutVals,
2041
- Ins, DAG);
2055
+ isTailCall = IsEligibleForTailCallOptimization (CLI, CCInfo, ArgLocs,
2056
+ IsCalleePopSRet);
2042
2057
2043
2058
// Sibcalls are automatically detected tailcalls which do not require
2044
2059
// ABI changes.
@@ -2056,22 +2071,6 @@ X86TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
2056
2071
assert (!(isVarArg && canGuaranteeTCO (CallConv)) &&
2057
2072
" Var args not supported with calling convention fastcc, ghc or hipe" );
2058
2073
2059
- // Analyze operands of the call, assigning locations to each operand.
2060
- SmallVector<CCValAssign, 16 > ArgLocs;
2061
- CCState CCInfo (CallConv, isVarArg, MF, ArgLocs, *DAG.getContext ());
2062
-
2063
- // Allocate shadow area for Win64.
2064
- if (IsWin64)
2065
- CCInfo.AllocateStack (32 , Align (8 ));
2066
-
2067
- CCInfo.AnalyzeArguments (Outs, CC_X86);
2068
-
2069
- // In vectorcall calling convention a second pass is required for the HVA
2070
- // types.
2071
- if (CallingConv::X86_VectorCall == CallConv) {
2072
- CCInfo.AnalyzeArgumentsSecondPass (Outs, CC_X86);
2073
- }
2074
-
2075
2074
// Get a count of how many bytes are to be pushed on the stack.
2076
2075
unsigned NumBytes = CCInfo.getAlignedCallFrameSize ();
2077
2076
if (IsSibcall)
@@ -2723,11 +2722,20 @@ bool MatchingStackOffset(SDValue Arg, unsigned Offset, ISD::ArgFlagsTy Flags,
2723
2722
2724
2723
// / Check whether the call is eligible for tail call optimization. Targets
2725
2724
// / that want to do tail call optimization should implement this function.
2725
+ // / Note that the x86 backend does not check musttail calls for eligibility! The
2726
+ // / rest of x86 tail call lowering must be prepared to forward arguments of any
2727
+ // / type.
2726
2728
bool X86TargetLowering::IsEligibleForTailCallOptimization (
2727
- SDValue Callee, CallingConv::ID CalleeCC, bool IsCalleePopSRet,
2728
- bool isVarArg, Type *RetTy, const SmallVectorImpl<ISD::OutputArg> &Outs,
2729
- const SmallVectorImpl<SDValue> &OutVals,
2730
- const SmallVectorImpl<ISD::InputArg> &Ins, SelectionDAG &DAG) const {
2729
+ TargetLowering::CallLoweringInfo &CLI, CCState &CCInfo,
2730
+ SmallVectorImpl<CCValAssign> &ArgLocs, bool IsCalleePopSRet) const {
2731
+ SelectionDAG &DAG = CLI.DAG ;
2732
+ const SmallVectorImpl<ISD::OutputArg> &Outs = CLI.Outs ;
2733
+ const SmallVectorImpl<SDValue> &OutVals = CLI.OutVals ;
2734
+ const SmallVectorImpl<ISD::InputArg> &Ins = CLI.Ins ;
2735
+ SDValue Callee = CLI.Callee ;
2736
+ CallingConv::ID CalleeCC = CLI.CallConv ;
2737
+ bool isVarArg = CLI.IsVarArg ;
2738
+
2731
2739
if (!mayTailCallThisCC (CalleeCC))
2732
2740
return false ;
2733
2741
@@ -2738,7 +2746,7 @@ bool X86TargetLowering::IsEligibleForTailCallOptimization(
2738
2746
// If the function return type is x86_fp80 and the callee return type is not,
2739
2747
// then the FP_EXTEND of the call result is not a nop. It's not safe to
2740
2748
// perform a tailcall optimization here.
2741
- if (CallerF.getReturnType ()->isX86_FP80Ty () && !RetTy->isX86_FP80Ty ())
2749
+ if (CallerF.getReturnType ()->isX86_FP80Ty () && !CLI. RetTy ->isX86_FP80Ty ())
2742
2750
return false ;
2743
2751
2744
2752
CallingConv::ID CallerCC = CallerF.getCallingConv ();
@@ -2791,9 +2799,6 @@ bool X86TargetLowering::IsEligibleForTailCallOptimization(
2791
2799
if (IsCalleeWin64 || IsCallerWin64)
2792
2800
return false ;
2793
2801
2794
- SmallVector<CCValAssign, 16 > ArgLocs;
2795
- CCState CCInfo (CalleeCC, isVarArg, MF, ArgLocs, C);
2796
- CCInfo.AnalyzeCallOperands (Outs, CC_X86);
2797
2802
for (const auto &VA : ArgLocs)
2798
2803
if (!VA.isRegLoc ())
2799
2804
return false ;
@@ -2811,8 +2816,8 @@ bool X86TargetLowering::IsEligibleForTailCallOptimization(
2811
2816
}
2812
2817
if (Unused) {
2813
2818
SmallVector<CCValAssign, 16 > RVLocs;
2814
- CCState CCInfo (CalleeCC, false , MF, RVLocs, C);
2815
- CCInfo .AnalyzeCallResult (Ins, RetCC_X86);
2819
+ CCState RVCCInfo (CalleeCC, false , MF, RVLocs, C);
2820
+ RVCCInfo .AnalyzeCallResult (Ins, RetCC_X86);
2816
2821
for (const auto &VA : RVLocs) {
2817
2822
if (VA.getLocReg () == X86::FP0 || VA.getLocReg () == X86::FP1)
2818
2823
return false ;
@@ -2832,24 +2837,12 @@ bool X86TargetLowering::IsEligibleForTailCallOptimization(
2832
2837
return false ;
2833
2838
}
2834
2839
2835
- unsigned StackArgsSize = 0 ;
2840
+ unsigned StackArgsSize = CCInfo. getStackSize () ;
2836
2841
2837
2842
// If the callee takes no arguments then go on to check the results of the
2838
2843
// call.
2839
2844
if (!Outs.empty ()) {
2840
- // Check if stack adjustment is needed. For now, do not do this if any
2841
- // argument is passed on the stack.
2842
- SmallVector<CCValAssign, 16 > ArgLocs;
2843
- CCState CCInfo (CalleeCC, isVarArg, MF, ArgLocs, C);
2844
-
2845
- // Allocate shadow area for Win64
2846
- if (IsCalleeWin64)
2847
- CCInfo.AllocateStack (32 , Align (8 ));
2848
-
2849
- CCInfo.AnalyzeCallOperands (Outs, CC_X86);
2850
- StackArgsSize = CCInfo.getStackSize ();
2851
-
2852
- if (CCInfo.getStackSize ()) {
2845
+ if (StackArgsSize > 0 ) {
2853
2846
// Check if the arguments are already laid out in the right way as
2854
2847
// the caller's fixed stack objects.
2855
2848
MachineFrameInfo &MFI = MF.getFrameInfo ();
0 commit comments