@@ -5182,28 +5182,21 @@ bool PPCTargetLowering::IsEligibleForTailCallOptimization_64SVR4(
51825182 return true;
51835183}
51845184
5185- static bool
5186- needStackSlotPassParameters_AIX(const PPCSubtarget &Subtarget,
5187- const SmallVectorImpl<ISD::OutputArg> &Outs) {
5185+ static void calculeStackSlotSizeForParameter_AIX(const PPCSubtarget &Subtarget,
5186+ MVT ArgVT,
5187+ ISD::ArgFlagsTy ArgFlags,
5188+ unsigned &StackSize,
5189+ Align &MaxStackArgAlign) {
51885190 const bool IsPPC64 = Subtarget.isPPC64();
51895191 const Align PtrAlign = IsPPC64 ? Align(8) : Align(4);
5190- const unsigned PhyGPRsNum = 8;
5191- const unsigned PhyVRsNum = 12;
5192- unsigned PhyGPRAllocated = 0;
5193- unsigned PhyVRAllocated = 0;
5194-
5195- for (unsigned i = 0; i != Outs.size(); ++i) {
5196- MVT ArgVT = Outs[i].VT;
5197- ISD::ArgFlagsTy ArgFlags = Outs[i].Flags;
5198- if (ArgFlags.isByVal()) {
5199- const unsigned ByValSize = ArgFlags.getByValSize();
5200- const unsigned StackSize = alignTo(ByValSize, PtrAlign);
5201- PhyGPRAllocated += StackSize / PtrAlign.value();
5202- if (PhyGPRAllocated > PhyGPRsNum)
5203- return true;
5204- continue;
5205- }
5192+ unsigned Size = 0;
5193+ Align Alignment = PtrAlign;
52065194
5195+ if (ArgFlags.isByVal()) {
5196+ Size = ArgFlags.getByValSize();
5197+ const Align ByValAlign(ArgFlags.getNonZeroByValAlign());
5198+ Alignment = ByValAlign > PtrAlign ? ByValAlign : PtrAlign;
5199+ } else {
52075200 switch (ArgVT.SimpleTy) {
52085201 default:
52095202 report_fatal_error("Unhandled value type for argument.");
@@ -5213,30 +5206,26 @@ needStackSlotPassParameters_AIX(const PPCSubtarget &Subtarget,
52135206 [[fallthrough]];
52145207 case MVT::i1:
52155208 case MVT::i32:
5216- if (++PhyGPRAllocated > PhyGPRsNum)
5217- return true;
5209+ Size = PtrAlign.value();
52185210 break;
52195211 case MVT::f32:
5220- case MVT::f64: {
5221- const unsigned StoreSize = ArgVT.getStoreSize();
5222- PhyGPRAllocated += StoreSize / PtrAlign.value();
5223- if (PhyGPRAllocated > PhyGPRsNum)
5224- return true;
5212+ case MVT::f64:
5213+ Size = ArgVT.getStoreSize();
5214+ Alignment = Align(4);
52255215 break;
5226- }
52275216 case MVT::v4f32:
52285217 case MVT::v4i32:
52295218 case MVT::v8i16:
52305219 case MVT::v16i8:
52315220 case MVT::v2i64:
52325221 case MVT::v2f64:
52335222 case MVT::v1i128:
5234- if (++PhyVRAllocated > PhyVRsNum)
5235- return true ;
5223+ Size = 16;
5224+ Alignment = Align(16) ;
52365225 }
52375226 }
5238-
5239- return false ;
5227+ StackSize = alignTo(StackSize, Alignment) + Size;
5228+ MaxStackArgAlign = std::max(Alignment, MaxStackArgAlign) ;
52405229}
52415230
52425231bool PPCTargetLowering::IsEligibleForTailCallOptimization_AIX(
@@ -5273,19 +5262,28 @@ bool PPCTargetLowering::IsEligibleForTailCallOptimization_AIX(
52735262 if (DisableSCO)
52745263 return false;
52755264
5276- if (CallerCC != CalleeCC && needStackSlotPassParameters_AIX(Subtarget, Outs))
5265+ unsigned CalleeArgSize = 0;
5266+ Align MaxAligment = Align(1);
5267+ for (auto OutArg : Outs)
5268+ calculeStackSlotSizeForParameter_AIX(Subtarget, OutArg.VT, OutArg.Flags,
5269+ CalleeArgSize, MaxAligment);
5270+ CalleeArgSize = alignTo(CalleeArgSize, MaxAligment);
5271+
5272+ // TODO: In the future, calculate the actual caller argument size
5273+ // instead of using the minimum parameter save area.
5274+ unsigned MinPSA = 8 * (Subtarget.isPPC64() ? 8 : 4);
5275+
5276+ if (CallerCC != CalleeCC && CalleeArgSize > MinPSA)
52775277 return false;
52785278
52795279 // If callee use the same argument list that caller is using, then we can
5280- // apply SCO on this case. If it is not, then we need to check if callee needs
5281- // stack for passing arguments.
5282- // PC Relative tail calls may not have a CallBase.
5283- // If there is no CallBase we cannot verify if we have the same argument
5284- // list so assume that we don't have the same argument list.
5285- if (CB && !hasSameArgumentList(CallerFunc, *CB) &&
5286- needStackSlotPassParameters_AIX(Subtarget, Outs))
5280+ // apply SCO on this case. If it is not, then we need to check if callee
5281+ // needs stack for passing arguments. PC Relative tail calls may not have
5282+ // a CallBase. If there is no CallBase we cannot verify if we have the
5283+ // same argument list so assume that we don't have the same argument list.
5284+ if (CB && !hasSameArgumentList(CallerFunc, *CB) && CalleeArgSize > MinPSA)
52875285 return false;
5288- else if (!CB && needStackSlotPassParameters_AIX(Subtarget, Outs) )
5286+ else if (!CB && CalleeArgSize > MinPSA )
52895287 return false;
52905288
52915289 return true;
0 commit comments