@@ -400,6 +400,36 @@ void AMDGPUAsmPrinter::emitCommonFunctionComments(
400
400
false );
401
401
}
402
402
403
+ SmallString<128 > AMDGPUAsmPrinter::getMCExprStr (const MCExpr *Value) {
404
+ SmallString<128 > Str;
405
+ raw_svector_ostream OSS (Str);
406
+ int64_t IVal;
407
+ if (Value->evaluateAsAbsolute (IVal)) {
408
+ OSS << static_cast <uint64_t >(IVal);
409
+ } else {
410
+ Value->print (OSS, MAI);
411
+ }
412
+ return Str;
413
+ }
414
+
415
+ void AMDGPUAsmPrinter::emitCommonFunctionComments (
416
+ const MCExpr *NumVGPR, const MCExpr *NumAGPR, const MCExpr *TotalNumVGPR,
417
+ const MCExpr *NumSGPR, const MCExpr *ScratchSize, uint64_t CodeSize,
418
+ const AMDGPUMachineFunction *MFI) {
419
+ OutStreamer->emitRawComment (" codeLenInByte = " + Twine (CodeSize), false );
420
+ OutStreamer->emitRawComment (" NumSgprs: " + getMCExprStr (NumSGPR), false );
421
+ OutStreamer->emitRawComment (" NumVgprs: " + getMCExprStr (NumVGPR), false );
422
+ if (NumAGPR && TotalNumVGPR) {
423
+ OutStreamer->emitRawComment (" NumAgprs: " + getMCExprStr (NumAGPR), false );
424
+ OutStreamer->emitRawComment (" TotalNumVgprs: " + getMCExprStr (TotalNumVGPR),
425
+ false );
426
+ }
427
+ OutStreamer->emitRawComment (" ScratchSize: " + getMCExprStr (ScratchSize),
428
+ false );
429
+ OutStreamer->emitRawComment (" MemoryBound: " + Twine (MFI->isMemoryBound ()),
430
+ false );
431
+ }
432
+
403
433
uint16_t AMDGPUAsmPrinter::getAmdhsaKernelCodeProperties (
404
434
const MachineFunction &MF) const {
405
435
const SIMachineFunctionInfo &MFI = *MF.getInfo <SIMachineFunctionInfo>();
@@ -554,13 +584,10 @@ bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
554
584
555
585
OutStreamer->emitRawComment (" Kernel info:" , false );
556
586
emitCommonFunctionComments (
557
- getMCExprValue (CurrentProgramInfo.NumArchVGPR , Ctx),
558
- STM.hasMAIInsts () ? getMCExprValue (CurrentProgramInfo.NumAccVGPR , Ctx)
559
- : std::optional<uint32_t >(),
560
- getMCExprValue (CurrentProgramInfo.NumVGPR , Ctx),
561
- getMCExprValue (CurrentProgramInfo.NumSGPR , Ctx),
562
- getMCExprValue (CurrentProgramInfo.ScratchSize , Ctx),
563
- getFunctionCodeSize (MF), MFI);
587
+ CurrentProgramInfo.NumArchVGPR ,
588
+ STM.hasMAIInsts () ? CurrentProgramInfo.NumAccVGPR : nullptr ,
589
+ CurrentProgramInfo.NumVGPR , CurrentProgramInfo.NumSGPR ,
590
+ CurrentProgramInfo.ScratchSize , getFunctionCodeSize (MF), MFI);
564
591
565
592
OutStreamer->emitRawComment (
566
593
" FloatMode: " + Twine (CurrentProgramInfo.FloatMode ), false );
@@ -571,43 +598,38 @@ bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
571
598
" bytes/workgroup (compile time only)" , false );
572
599
573
600
OutStreamer->emitRawComment (
574
- " SGPRBlocks: " +
575
- Twine (getMCExprValue (CurrentProgramInfo.SGPRBlocks , Ctx)),
576
- false );
601
+ " SGPRBlocks: " + getMCExprStr (CurrentProgramInfo.SGPRBlocks ), false );
602
+
577
603
OutStreamer->emitRawComment (
578
- " VGPRBlocks: " +
579
- Twine (getMCExprValue (CurrentProgramInfo.VGPRBlocks , Ctx)),
580
- false );
604
+ " VGPRBlocks: " + getMCExprStr (CurrentProgramInfo.VGPRBlocks ), false );
581
605
582
606
OutStreamer->emitRawComment (
583
607
" NumSGPRsForWavesPerEU: " +
584
- Twine (
585
- getMCExprValue (CurrentProgramInfo.NumSGPRsForWavesPerEU , Ctx)),
608
+ getMCExprStr (CurrentProgramInfo.NumSGPRsForWavesPerEU ),
586
609
false );
587
610
OutStreamer->emitRawComment (
588
611
" NumVGPRsForWavesPerEU: " +
589
- Twine (
590
- getMCExprValue (CurrentProgramInfo.NumVGPRsForWavesPerEU , Ctx)),
612
+ getMCExprStr (CurrentProgramInfo.NumVGPRsForWavesPerEU ),
591
613
false );
592
614
593
- if (STM.hasGFX90AInsts ())
615
+ if (STM.hasGFX90AInsts ()) {
616
+ const MCExpr *AdjustedAccum = MCBinaryExpr::createAdd (
617
+ CurrentProgramInfo.AccumOffset , MCConstantExpr::create (1 , Ctx), Ctx);
618
+ AdjustedAccum = MCBinaryExpr::createMul (
619
+ AdjustedAccum, MCConstantExpr::create (4 , Ctx), Ctx);
594
620
OutStreamer->emitRawComment (
595
- " AccumOffset: " +
596
- Twine ((getMCExprValue (CurrentProgramInfo.AccumOffset , Ctx) + 1 ) *
597
- 4 ),
598
- false );
621
+ " AccumOffset: " + getMCExprStr (AdjustedAccum), false );
622
+ }
599
623
600
624
OutStreamer->emitRawComment (
601
- " Occupancy: " +
602
- Twine (getMCExprValue (CurrentProgramInfo.Occupancy , Ctx)),
603
- false );
625
+ " Occupancy: " + getMCExprStr (CurrentProgramInfo.Occupancy ), false );
604
626
605
627
OutStreamer->emitRawComment (
606
628
" WaveLimiterHint : " + Twine (MFI->needsWaveLimiter ()), false );
607
629
608
630
OutStreamer->emitRawComment (
609
631
" COMPUTE_PGM_RSRC2:SCRATCH_EN: " +
610
- Twine ( getMCExprValue ( CurrentProgramInfo.ScratchEnable , Ctx) ),
632
+ getMCExprStr ( CurrentProgramInfo.ScratchEnable ),
611
633
false );
612
634
OutStreamer->emitRawComment (" COMPUTE_PGM_RSRC2:USER_SGPR: " +
613
635
Twine (CurrentProgramInfo.UserSGPR ),
@@ -628,20 +650,25 @@ bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
628
650
Twine (CurrentProgramInfo.TIdIGCompCount ),
629
651
false );
630
652
653
+ int64_t PGMRSrc3;
631
654
assert (STM.hasGFX90AInsts () ||
632
- getMCExprValue (CurrentProgramInfo.ComputePGMRSrc3GFX90A , Ctx) == 0 );
655
+ (CurrentProgramInfo.ComputePGMRSrc3GFX90A ->evaluateAsAbsolute (
656
+ PGMRSrc3) &&
657
+ static_cast <uint64_t >(PGMRSrc3) == 0 ));
633
658
if (STM.hasGFX90AInsts ()) {
634
659
OutStreamer->emitRawComment (
635
660
" COMPUTE_PGM_RSRC3_GFX90A:ACCUM_OFFSET: " +
636
- Twine ((AMDHSA_BITS_GET (
637
- getMCExprValue (CurrentProgramInfo.ComputePGMRSrc3GFX90A , Ctx),
638
- amdhsa::COMPUTE_PGM_RSRC3_GFX90A_ACCUM_OFFSET))),
661
+ getMCExprStr (MCKernelDescriptor::bits_get (
662
+ CurrentProgramInfo.ComputePGMRSrc3GFX90A ,
663
+ amdhsa::COMPUTE_PGM_RSRC3_GFX90A_ACCUM_OFFSET_SHIFT,
664
+ amdhsa::COMPUTE_PGM_RSRC3_GFX90A_ACCUM_OFFSET, Ctx)),
639
665
false );
640
666
OutStreamer->emitRawComment (
641
667
" COMPUTE_PGM_RSRC3_GFX90A:TG_SPLIT: " +
642
- Twine ((AMDHSA_BITS_GET (
643
- getMCExprValue (CurrentProgramInfo.ComputePGMRSrc3GFX90A , Ctx),
644
- amdhsa::COMPUTE_PGM_RSRC3_GFX90A_TG_SPLIT))),
668
+ getMCExprStr (MCKernelDescriptor::bits_get (
669
+ CurrentProgramInfo.ComputePGMRSrc3GFX90A ,
670
+ amdhsa::COMPUTE_PGM_RSRC3_GFX90A_TG_SPLIT_SHIFT,
671
+ amdhsa::COMPUTE_PGM_RSRC3_GFX90A_TG_SPLIT, Ctx)),
645
672
false );
646
673
}
647
674
}
@@ -1463,28 +1490,26 @@ void AMDGPUAsmPrinter::emitResourceUsageRemarks(
1463
1490
// remarks to simulate newlines. If and when clang does accept newlines, this
1464
1491
// formatting should be aggregated into one remark with newlines to avoid
1465
1492
// printing multiple diagnostic location and diag opts.
1466
- MCContext &MCCtx = MF.getContext ();
1467
1493
EmitResourceUsageRemark (" FunctionName" , " Function Name" ,
1468
1494
MF.getFunction ().getName ());
1469
1495
EmitResourceUsageRemark (" NumSGPR" , " SGPRs" ,
1470
- getMCExprValue (CurrentProgramInfo.NumSGPR , MCCtx));
1471
- EmitResourceUsageRemark (
1472
- " NumVGPR" , " VGPRs" ,
1473
- getMCExprValue (CurrentProgramInfo.NumArchVGPR , MCCtx));
1496
+ getMCExprStr (CurrentProgramInfo.NumSGPR ));
1497
+ EmitResourceUsageRemark (" NumVGPR" , " VGPRs" ,
1498
+ getMCExprStr (CurrentProgramInfo.NumArchVGPR ));
1474
1499
if (hasMAIInsts) {
1475
- EmitResourceUsageRemark (
1476
- " NumAGPR" , " AGPRs" ,
1477
- getMCExprValue (CurrentProgramInfo.NumAccVGPR , MCCtx));
1500
+ EmitResourceUsageRemark (" NumAGPR" , " AGPRs" ,
1501
+ getMCExprStr (CurrentProgramInfo.NumAccVGPR ));
1478
1502
}
1479
- EmitResourceUsageRemark (
1480
- " ScratchSize" , " ScratchSize [bytes/lane]" ,
1481
- getMCExprValue (CurrentProgramInfo.ScratchSize , MCCtx));
1503
+ EmitResourceUsageRemark (" ScratchSize" , " ScratchSize [bytes/lane]" ,
1504
+ getMCExprStr (CurrentProgramInfo.ScratchSize ));
1505
+ int64_t DynStack;
1506
+ bool DynStackEvaluatable =
1507
+ CurrentProgramInfo.DynamicCallStack ->evaluateAsAbsolute (DynStack);
1482
1508
StringRef DynamicStackStr =
1483
- getMCExprValue (CurrentProgramInfo.DynamicCallStack , MCCtx) ? " True"
1484
- : " False" ;
1509
+ DynStackEvaluatable && DynStack ? " True" : " False" ;
1485
1510
EmitResourceUsageRemark (" DynamicStack" , " Dynamic Stack" , DynamicStackStr);
1486
1511
EmitResourceUsageRemark (" Occupancy" , " Occupancy [waves/SIMD]" ,
1487
- getMCExprValue (CurrentProgramInfo.Occupancy , MCCtx ));
1512
+ getMCExprStr (CurrentProgramInfo.Occupancy ));
1488
1513
EmitResourceUsageRemark (" SGPRSpill" , " SGPRs Spill" ,
1489
1514
CurrentProgramInfo.SGPRSpill );
1490
1515
EmitResourceUsageRemark (" VGPRSpill" , " VGPRs Spill" ,
0 commit comments