@@ -358,6 +358,32 @@ bool AMDGPUAsmPrinter::doInitialization(Module &M) {
358358 return AsmPrinter::doInitialization (M);
359359}
360360
361+ // / Mimics GCNSubtarget::computeOccupancy for MCExpr.
362+ // /
363+ // / Remove dependency on GCNSubtarget and depend only only the necessary values
364+ // / for said occupancy computation. Should match computeOccupancy implementation
365+ // / without passing \p STM on.
366+ const AMDGPUMCExpr *createOccupancy (unsigned InitOcc, const MCExpr *NumSGPRs,
367+ const MCExpr *NumVGPRs,
368+ unsigned DynamicVGPRBlockSize,
369+ const GCNSubtarget &STM, MCContext &Ctx) {
370+ unsigned MaxWaves = IsaInfo::getMaxWavesPerEU (&STM);
371+ unsigned Granule = IsaInfo::getVGPRAllocGranule (&STM, DynamicVGPRBlockSize);
372+ unsigned TargetTotalNumVGPRs = IsaInfo::getTotalNumVGPRs (&STM);
373+ unsigned Generation = STM.getGeneration ();
374+
375+ auto CreateExpr = [&Ctx](unsigned Value) {
376+ return MCConstantExpr::create (Value, Ctx);
377+ };
378+
379+ return AMDGPUMCExpr::create (AMDGPUMCExpr::AGVK_Occupancy,
380+ {CreateExpr (MaxWaves), CreateExpr (Granule),
381+ CreateExpr (TargetTotalNumVGPRs),
382+ CreateExpr (Generation), CreateExpr (InitOcc),
383+ NumSGPRs, NumVGPRs},
384+ Ctx);
385+ }
386+
361387void AMDGPUAsmPrinter::validateMCResourceInfo (Function &F) {
362388 if (F.isDeclaration () || !AMDGPU::isModuleEntryFunctionCC (F.getCallingConv ()))
363389 return ;
@@ -459,7 +485,7 @@ void AMDGPUAsmPrinter::validateMCResourceInfo(Function &F) {
459485 MaxWaves, MFI.getDynamicVGPRBlockSize ())});
460486 uint64_t NumSGPRsForWavesPerEU = std::max (
461487 {NumSgpr, (uint64_t )1 , (uint64_t )STM.getMinNumSGPRs (MaxWaves)});
462- const MCExpr *OccupancyExpr = AMDGPUMCExpr:: createOccupancy (
488+ const MCExpr *OccupancyExpr = createOccupancy (
463489 STM.getOccupancyWithWorkGroupSizes (*MF).second ,
464490 MCConstantExpr::create (NumSGPRsForWavesPerEU, OutContext),
465491 MCConstantExpr::create (NumVGPRsForWavesPerEU, OutContext),
@@ -1270,7 +1296,7 @@ void AMDGPUAsmPrinter::getSIProgramInfo(SIProgramInfo &ProgInfo,
12701296 amdhsa::COMPUTE_PGM_RSRC3_GFX125_NAMED_BAR_CNT,
12711297 amdhsa::COMPUTE_PGM_RSRC3_GFX125_NAMED_BAR_CNT_SHIFT);
12721298
1273- ProgInfo.Occupancy = AMDGPUMCExpr:: createOccupancy (
1299+ ProgInfo.Occupancy = createOccupancy (
12741300 STM.computeOccupancy (F, ProgInfo.LDSSize ).second ,
12751301 ProgInfo.NumSGPRsForWavesPerEU , ProgInfo.NumVGPRsForWavesPerEU ,
12761302 MFI->getDynamicVGPRBlockSize (), STM, Ctx);
0 commit comments