[llvm] [AMDGPU][SIInsertWaitcnt][NFC] Move eventCounter() function (PR #178949)

via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 2 08:21:02 PST 2026


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

>From d016e3707bd6d3fbbea228a424127c15cb7e8326 Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vasileios.porpodas at amd.com>
Date: Tue, 27 Jan 2026 22:47:19 +0000
Subject: [PATCH 1/2] [AMDGPU][SIInsertWaitcnt][NFC] Move eventCounter()
 function

The eventCounter() function searches through the array of events.
This array is owned by the WaitcntGenerator class.

This patch moves the function into the WaitcntGenerator class which helps
hide the event array from the user.
It also renames it to getCounterFromEvent().

This should be NFC.
---
 llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp | 26 ++++++++++++---------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
index b39975fdb0561..21082c9f3a9bf 100644
--- a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
@@ -410,15 +410,6 @@ void WaitEventSet::dump() const {
   dbgs() << "\n";
 }
 
-// Mapping from event to counter according to the table masks.
-InstCounterType eventCounter(const WaitEventSet *masks, WaitEventType E) {
-  for (auto T : inst_counter_types()) {
-    if (masks[T].contains(E))
-      return T;
-  }
-  llvm_unreachable("event type has no associated counter");
-}
-
 class WaitcntBrackets;
 
 // This abstracts the logic for generating and updating S_WAIT* instructions
@@ -487,6 +478,16 @@ class WaitcntGenerator {
   // WaitEventType to corresponding counter values in InstCounterType.
   virtual const WaitEventSet *getWaitEventMask() const = 0;
 
+  /// \Returns the counter that corresponds to event \p E.
+  InstCounterType getCounterFromEvent(WaitEventType E) const {
+    const WaitEventSet *WaitEvents = getWaitEventMask();
+    for (auto T : inst_counter_types()) {
+      if (WaitEvents[T].contains(E))
+        return T;
+    }
+    llvm_unreachable("event type has no associated counter");
+  }
+
   // Returns a new waitcnt with all counters except VScnt set to 0. If
   // IncludeVSCnt is true, VScnt is set to 0, otherwise it is set to ~0u.
   virtual AMDGPU::Waitcnt getAllZeroWaitcnt(bool IncludeVSCnt) const = 0;
@@ -737,6 +738,9 @@ class SIInsertWaitcnts {
   const WaitEventSet *getWaitEventMask() const {
     return WCG->getWaitEventMask();
   }
+  InstCounterType getCounterFromEvent(WaitEventType E) const {
+    return WCG->getCounterFromEvent(E);
+  }
 };
 
 // This objects maintains the current score brackets of each wait counter, and
@@ -1090,7 +1094,7 @@ bool WaitcntBrackets::hasPointSamplePendingVmemTypes(const MachineInstr &MI,
 }
 
 void WaitcntBrackets::updateByEvent(WaitEventType E, MachineInstr &Inst) {
-  InstCounterType T = eventCounter(Context->getWaitEventMask(), E);
+  InstCounterType T = Context->getCounterFromEvent(E);
   assert(T < Context->MaxCounter);
 
   unsigned UB = getScoreUB(T);
@@ -3402,7 +3406,7 @@ bool SIInsertWaitcnts::run(MachineFunction &MF) {
   for (auto T : inst_counter_types())
     ForceEmitWaitcnt[T] = false;
 
-  SmemAccessCounter = eventCounter(WCG->getWaitEventMask(), SMEM_ACCESS);
+  SmemAccessCounter = WCG->getCounterFromEvent(SMEM_ACCESS);
 
   BlockInfos.clear();
   bool Modified = false;

>From 7b51b4740ab89b490209bb95f5abdbdfd3199242 Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vasileios.porpodas at amd.com>
Date: Mon, 2 Feb 2026 16:18:56 +0000
Subject: [PATCH 2/2] fixup! [AMDGPU][SIInsertWaitcnt][NFC] Move eventCounter()
 function

---
 llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
index 21082c9f3a9bf..09355180822d3 100644
--- a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
@@ -3406,7 +3406,7 @@ bool SIInsertWaitcnts::run(MachineFunction &MF) {
   for (auto T : inst_counter_types())
     ForceEmitWaitcnt[T] = false;
 
-  SmemAccessCounter = WCG->getCounterFromEvent(SMEM_ACCESS);
+  SmemAccessCounter = getCounterFromEvent(SMEM_ACCESS);
 
   BlockInfos.clear();
   bool Modified = false;



More information about the llvm-commits mailing list