[llvm] [AMDGPU][AMDGPUBaseInfo] Replace Waitcnt members with array (PR #182927)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 10 03:17:50 PDT 2026


================
@@ -1112,118 +1115,87 @@ namespace AMDGPU {
 /// Large values (including the maximum possible integer) can be used to
 /// represent "don't care" waits.
 class Waitcnt {
-  unsigned LoadCnt = ~0u; // Corresponds to Vmcnt prior to gfx12.
-  unsigned ExpCnt = ~0u;
-  unsigned DsCnt = ~0u;     // Corresponds to LGKMcnt prior to gfx12.
-  unsigned StoreCnt = ~0u;  // Corresponds to VScnt on gfx10/gfx11.
-  unsigned SampleCnt = ~0u; // gfx12+ only.
-  unsigned BvhCnt = ~0u;    // gfx12+ only.
-  unsigned KmCnt = ~0u;     // gfx12+ only.
-  unsigned XCnt = ~0u;      // gfx1250.
-  unsigned VaVdst = ~0u;    // gfx12+ expert scheduling mode only.
-  unsigned VmVsrc = ~0u;    // gfx12+ expert scheduling mode only.
+  std::array<unsigned, NUM_INST_CNTS> Cnt;
 
 public:
-  unsigned get(InstCounterType T) const {
-    switch (T) {
-    case LOAD_CNT:
-      return LoadCnt;
-    case EXP_CNT:
-      return ExpCnt;
-    case DS_CNT:
-      return DsCnt;
-    case STORE_CNT:
-      return StoreCnt;
-    case SAMPLE_CNT:
-      return SampleCnt;
-    case BVH_CNT:
-      return BvhCnt;
-    case KM_CNT:
-      return KmCnt;
-    case X_CNT:
-      return XCnt;
-    case VA_VDST:
-      return VaVdst;
-    case VM_VSRC:
-      return VmVsrc;
-    default:
-      llvm_unreachable("bad InstCounterType");
-    }
-  }
-  void set(InstCounterType T, unsigned Val) {
-    switch (T) {
-    case LOAD_CNT:
-      LoadCnt = Val;
-      break;
-    case EXP_CNT:
-      ExpCnt = Val;
-      break;
-    case DS_CNT:
-      DsCnt = Val;
-      break;
-    case STORE_CNT:
-      StoreCnt = Val;
-      break;
-    case SAMPLE_CNT:
-      SampleCnt = Val;
-      break;
-    case BVH_CNT:
-      BvhCnt = Val;
-      break;
-    case KM_CNT:
-      KmCnt = Val;
-      break;
-    case X_CNT:
-      XCnt = Val;
-      break;
-    case VA_VDST:
-      VaVdst = Val;
-      break;
-    case VM_VSRC:
-      VmVsrc = Val;
-      break;
-    default:
-      llvm_unreachable("bad InstCounterType");
-    }
-  }
+  unsigned get(InstCounterType T) const { return Cnt[T]; }
+  void set(InstCounterType T, unsigned Val) { Cnt[T] = Val; }
 
-  Waitcnt() = default;
+  Waitcnt() { fill(Cnt, ~0u); }
   // Pre-gfx12 constructor.
   Waitcnt(unsigned VmCnt, unsigned ExpCnt, unsigned LgkmCnt, unsigned VsCnt)
-      : LoadCnt(VmCnt), ExpCnt(ExpCnt), DsCnt(LgkmCnt), StoreCnt(VsCnt) {}
+      : Waitcnt() {
+    Cnt[LOAD_CNT] = VmCnt;
+    Cnt[EXP_CNT] = ExpCnt;
+    Cnt[DS_CNT] = LgkmCnt;
+    Cnt[STORE_CNT] = VsCnt;
+  }
 
   // gfx12+ constructor.
   Waitcnt(unsigned LoadCnt, unsigned ExpCnt, unsigned DsCnt, unsigned StoreCnt,
           unsigned SampleCnt, unsigned BvhCnt, unsigned KmCnt, unsigned XCnt,
           unsigned VaVdst, unsigned VmVsrc)
-      : LoadCnt(LoadCnt), ExpCnt(ExpCnt), DsCnt(DsCnt), StoreCnt(StoreCnt),
-        SampleCnt(SampleCnt), BvhCnt(BvhCnt), KmCnt(KmCnt), XCnt(XCnt),
-        VaVdst(VaVdst), VmVsrc(VmVsrc) {}
+      : Waitcnt() {
+    Cnt[LOAD_CNT] = LoadCnt;
+    Cnt[DS_CNT] = DsCnt;
+    Cnt[EXP_CNT] = ExpCnt;
+    Cnt[STORE_CNT] = StoreCnt;
+    Cnt[SAMPLE_CNT] = SampleCnt;
+    Cnt[BVH_CNT] = BvhCnt;
+    Cnt[KM_CNT] = KmCnt;
+    Cnt[X_CNT] = XCnt;
+    Cnt[VA_VDST] = VaVdst;
+    Cnt[VM_VSRC] = VmVsrc;
+  }
 
-  bool hasWait() const { return StoreCnt != ~0u || hasWaitExceptStoreCnt(); }
+  bool hasWait() const {
+    return any_of(Cnt, [](unsigned Val) { return Val != ~0u; });
+  }
 
   bool hasWaitExceptStoreCnt() const {
-    return LoadCnt != ~0u || ExpCnt != ~0u || DsCnt != ~0u ||
-           SampleCnt != ~0u || BvhCnt != ~0u || KmCnt != ~0u || XCnt != ~0u ||
-           VaVdst != ~0u || VmVsrc != ~0u;
+    for (InstCounterType T : inst_counter_types()) {
+      if (T == STORE_CNT)
+        continue;
+      if (Cnt[T] != ~0u)
+        return true;
+    }
+    return false;
   }
 
-  bool hasWaitStoreCnt() const { return StoreCnt != ~0u; }
+  bool hasWaitStoreCnt() const { return Cnt[STORE_CNT] != ~0u; }
 
-  bool hasWaitDepctr() const { return VaVdst != ~0u || VmVsrc != ~0u; }
+  bool hasWaitDepctr() const {
+    return Cnt[VA_VDST] != ~0u || Cnt[VM_VSRC] != ~0u;
+  }
 
   Waitcnt combined(const Waitcnt &Other) const {
     // Does the right thing provided self and Other are either both pre-gfx12
     // or both gfx12+.
-    return Waitcnt(
-        std::min(LoadCnt, Other.LoadCnt), std::min(ExpCnt, Other.ExpCnt),
-        std::min(DsCnt, Other.DsCnt), std::min(StoreCnt, Other.StoreCnt),
-        std::min(SampleCnt, Other.SampleCnt), std::min(BvhCnt, Other.BvhCnt),
-        std::min(KmCnt, Other.KmCnt), std::min(XCnt, Other.XCnt),
-        std::min(VaVdst, Other.VaVdst), std::min(VmVsrc, Other.VmVsrc));
+    Waitcnt Wait;
+    for (InstCounterType T : inst_counter_types()) {
+      Wait.Cnt[T] = std::min(Cnt[T], Other.Cnt[T]);
+    }
+    return Wait;
+  }
+
+  void print(raw_ostream &OS) const {
+    ListSeparator LS;
+    for (InstCounterType T : inst_counter_types()) {
----------------
jayfoad wrote:

Nit: don't need braces

https://github.com/llvm/llvm-project/pull/182927


More information about the llvm-commits mailing list