@@ -993,72 +993,12 @@ void AMDGPUAsmPrinter::getSIProgramInfo(SIProgramInfo &ProgInfo,
993993 const Function &F = MF.getFunction ();
994994
995995 // Ensure there are enough SGPRs and VGPRs for wave dispatch, where wave
996- // dispatch registers are function args.
997- unsigned WaveDispatchNumSGPR = 0 , WaveDispatchNumVGPR = 0 ;
996+ // dispatch registers as function args.
997+ unsigned WaveDispatchNumSGPR = MFI->getNumWaveDispatchSGPRs (),
998+ WaveDispatchNumVGPR = MFI->getNumWaveDispatchVGPRs ();
998999
1000+ // FIXME: Cleanup
9991001 if (isShader (F.getCallingConv ())) {
1000- bool IsPixelShader =
1001- F.getCallingConv () == CallingConv::AMDGPU_PS && !STM.isAmdHsaOS ();
1002-
1003- // Calculate the number of VGPR registers based on the SPI input registers
1004- uint32_t InputEna = 0 ;
1005- uint32_t InputAddr = 0 ;
1006- unsigned LastEna = 0 ;
1007-
1008- if (IsPixelShader) {
1009- // Note for IsPixelShader:
1010- // By this stage, all enabled inputs are tagged in InputAddr as well.
1011- // We will use InputAddr to determine whether the input counts against the
1012- // vgpr total and only use the InputEnable to determine the last input
1013- // that is relevant - if extra arguments are used, then we have to honour
1014- // the InputAddr for any intermediate non-enabled inputs.
1015- InputEna = MFI->getPSInputEnable ();
1016- InputAddr = MFI->getPSInputAddr ();
1017-
1018- // We only need to consider input args up to the last used arg.
1019- assert ((InputEna || InputAddr) &&
1020- " PSInputAddr and PSInputEnable should "
1021- " never both be 0 for AMDGPU_PS shaders" );
1022- // There are some rare circumstances where InputAddr is non-zero and
1023- // InputEna can be set to 0. In this case we default to setting LastEna
1024- // to 1.
1025- LastEna = InputEna ? llvm::Log2_32 (InputEna) + 1 : 1 ;
1026- }
1027-
1028- // FIXME: We should be using the number of registers determined during
1029- // calling convention lowering to legalize the types.
1030- const DataLayout &DL = F.getDataLayout ();
1031- unsigned PSArgCount = 0 ;
1032- unsigned IntermediateVGPR = 0 ;
1033- for (auto &Arg : F.args ()) {
1034- unsigned NumRegs = (DL.getTypeSizeInBits (Arg.getType ()) + 31 ) / 32 ;
1035- if (Arg.hasAttribute (Attribute::InReg)) {
1036- WaveDispatchNumSGPR += NumRegs;
1037- } else {
1038- // If this is a PS shader and we're processing the PS Input args (first
1039- // 16 VGPR), use the InputEna and InputAddr bits to define how many
1040- // VGPRs are actually used.
1041- // Any extra VGPR arguments are handled as normal arguments (and
1042- // contribute to the VGPR count whether they're used or not).
1043- if (IsPixelShader && PSArgCount < 16 ) {
1044- if ((1 << PSArgCount) & InputAddr) {
1045- if (PSArgCount < LastEna)
1046- WaveDispatchNumVGPR += NumRegs;
1047- else
1048- IntermediateVGPR += NumRegs;
1049- }
1050- PSArgCount++;
1051- } else {
1052- // If there are extra arguments we have to include the allocation for
1053- // the non-used (but enabled with InputAddr) input arguments
1054- if (IntermediateVGPR) {
1055- WaveDispatchNumVGPR += IntermediateVGPR;
1056- IntermediateVGPR = 0 ;
1057- }
1058- WaveDispatchNumVGPR += NumRegs;
1059- }
1060- }
1061- }
10621002 ProgInfo.NumSGPR = AMDGPUMCExpr::createMax (
10631003 {ProgInfo.NumSGPR ,
10641004 MCBinaryExpr::createAdd (CreateExpr (WaveDispatchNumSGPR), ExtraSGPRs,
0 commit comments