[llvm] [AMDGPU][SIInsertWaitcnts][NFC] Common InstCounterType printer (PR #187559)

via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 8 11:11:55 PDT 2026


https://github.com/vporpo updated https://github.com/llvm/llvm-project/pull/187559

>From b70f9525c6104cb1c1b5627ee0238dce0cbd52bd Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vasileios.porpodas at amd.com>
Date: Wed, 8 Apr 2026 17:57:37 +0000
Subject: [PATCH] [AMDGPU][SIInsertWaitcnts][NFC] Common InstCounterType
 printer

This patch extends the functionality of the InstCounterType printer by adding the ST argument and checking if the target supports extended counters and printing the expected counter names accordingly.

This change helps us reuse this printer in a couple of places in the code.
---
 llvm/lib/Target/AMDGPU/AMDGPUWaitcntUtils.cpp | 12 ++-
 llvm/lib/Target/AMDGPU/AMDGPUWaitcntUtils.h   |  5 +-
 llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp   | 78 +------------------
 3 files changed, 14 insertions(+), 81 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUWaitcntUtils.cpp b/llvm/lib/Target/AMDGPU/AMDGPUWaitcntUtils.cpp
index 282eaba6586a7..4882a4d0c4e3d 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUWaitcntUtils.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUWaitcntUtils.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "AMDGPUWaitcntUtils.h"
+#include "GCNSubtarget.h"
 #include "Utils/AMDGPUBaseInfo.h"
 
 namespace llvm::AMDGPU {
@@ -15,16 +16,19 @@ iota_range<InstCounterType> inst_counter_types(InstCounterType MaxCounter) {
   return enum_seq(LOAD_CNT, MaxCounter);
 }
 
-StringLiteral getInstCounterName(InstCounterType T) {
+StringLiteral getInstCounterName(InstCounterType T, const GCNSubtarget *ST) {
   switch (T) {
   case LOAD_CNT:
-    return "LOAD_CNT";
+    return !ST || ST->hasExtendedWaitCounts() ? StringLiteral("LOAD_CNT")
+                                              : StringLiteral("VM_CNT");
   case DS_CNT:
-    return "DS_CNT";
+    return !ST || ST->hasExtendedWaitCounts() ? StringLiteral("DS_CNT")
+                                              : StringLiteral("LGKM_CNT");
   case EXP_CNT:
     return "EXP_CNT";
   case STORE_CNT:
-    return "STORE_CNT";
+    return !ST || ST->hasExtendedWaitCounts() ? StringLiteral("STORE_CNT")
+                                              : StringLiteral("VS_CNT");
   case SAMPLE_CNT:
     return "SAMPLE_CNT";
   case BVH_CNT:
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUWaitcntUtils.h b/llvm/lib/Target/AMDGPU/AMDGPUWaitcntUtils.h
index 111b28af3b47e..8c88cd79ded64 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUWaitcntUtils.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPUWaitcntUtils.h
@@ -17,6 +17,8 @@
 
 namespace llvm {
 
+class GCNSubtarget;
+
 namespace AMDGPU {
 
 enum InstCounterType {
@@ -37,7 +39,8 @@ enum InstCounterType {
   NUM_INST_CNTS = NUM_EXPERT_INST_CNTS
 };
 
-StringLiteral getInstCounterName(InstCounterType T);
+StringLiteral getInstCounterName(InstCounterType T,
+                                 const GCNSubtarget *ST = nullptr);
 
 // Return an iterator over all counters between LOAD_CNT (the first counter)
 // and \c MaxCounter (exclusive, default value yields an enumeration over
diff --git a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
index abd03d5f9bf73..f3a82caa5ab57 100644
--- a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
@@ -1300,47 +1300,7 @@ void WaitcntBrackets::print(raw_ostream &OS) const {
 
   for (auto T : inst_counter_types(Context->MaxCounter)) {
     unsigned SR = getScoreRange(T);
-    switch (T) {
-    case LOAD_CNT:
-      OS << "    " << (ST.hasExtendedWaitCounts() ? "LOAD" : "VM") << "_CNT("
-         << SR << "):";
-      break;
-    case DS_CNT:
-      OS << "    " << (ST.hasExtendedWaitCounts() ? "DS" : "LGKM") << "_CNT("
-         << SR << "):";
-      break;
-    case EXP_CNT:
-      OS << "    EXP_CNT(" << SR << "):";
-      break;
-    case STORE_CNT:
-      OS << "    " << (ST.hasExtendedWaitCounts() ? "STORE" : "VS") << "_CNT("
-         << SR << "):";
-      break;
-    case SAMPLE_CNT:
-      OS << "    SAMPLE_CNT(" << SR << "):";
-      break;
-    case BVH_CNT:
-      OS << "    BVH_CNT(" << SR << "):";
-      break;
-    case KM_CNT:
-      OS << "    KM_CNT(" << SR << "):";
-      break;
-    case X_CNT:
-      OS << "    X_CNT(" << SR << "):";
-      break;
-    case ASYNC_CNT:
-      OS << "    ASYNC_CNT(" << SR << "):";
-      break;
-    case VA_VDST:
-      OS << "    VA_VDST(" << SR << "): ";
-      break;
-    case VM_VSRC:
-      OS << "    VM_VSRC(" << SR << "): ";
-      break;
-    default:
-      OS << "    UNKNOWN(" << SR << "):";
-      break;
-    }
+    OS << "    " << getInstCounterName(T, &ST) << "(" << SR << "):";
 
     if (SR != 0) {
       // Print vgpr scores.
@@ -1407,41 +1367,7 @@ void WaitcntBrackets::print(raw_ostream &OS) const {
   for (const auto &Mark : AsyncMarks) {
     for (auto T : inst_counter_types()) {
       unsigned MarkedScore = Mark[T];
-      switch (T) {
-      case LOAD_CNT:
-        OS << "  " << (ST.hasExtendedWaitCounts() ? "LOAD" : "VM")
-           << "_CNT: " << MarkedScore;
-        break;
-      case DS_CNT:
-        OS << "  " << (ST.hasExtendedWaitCounts() ? "DS" : "LGKM")
-           << "_CNT: " << MarkedScore;
-        break;
-      case EXP_CNT:
-        OS << "  EXP_CNT: " << MarkedScore;
-        break;
-      case STORE_CNT:
-        OS << "  " << (ST.hasExtendedWaitCounts() ? "STORE" : "VS")
-           << "_CNT: " << MarkedScore;
-        break;
-      case SAMPLE_CNT:
-        OS << "  SAMPLE_CNT: " << MarkedScore;
-        break;
-      case BVH_CNT:
-        OS << "  BVH_CNT: " << MarkedScore;
-        break;
-      case KM_CNT:
-        OS << "  KM_CNT: " << MarkedScore;
-        break;
-      case X_CNT:
-        OS << "  X_CNT: " << MarkedScore;
-        break;
-      case ASYNC_CNT:
-        OS << "  ASYNC_CNT: " << MarkedScore;
-        break;
-      default:
-        OS << "  UNKNOWN: " << MarkedScore;
-        break;
-      }
+      OS << getInstCounterName(T, &ST) << MarkedScore;
     }
     OS << '\n';
   }



More information about the llvm-commits mailing list