[llvm] [AMDGPU][SIInsertWaitcnt][NFC] Move eventCounter() function (PR #178949)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 4 08:36:06 PST 2026
https://github.com/vporpo updated https://github.com/llvm/llvm-project/pull/178949
>From 14bdeacd170da675ad4a058ce2ed25366fc89c55 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/3] [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 35a7c21dc97e2..0aa1bdff99267 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 1bfb55be4ad36d6937dd0b472802d0d6e24c1836 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/3] 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 0aa1bdff99267..9fcfeccd9c9e5 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;
>From dbab11a707993313e9e5968f7655a2906772f65d Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vasileios.porpodas at amd.com>
Date: Wed, 4 Feb 2026 16:30:44 +0000
Subject: [PATCH 3/3] fixup! 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 9fcfeccd9c9e5..9a2a7b4923881 100644
--- a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
@@ -478,7 +478,7 @@ class WaitcntGenerator {
// WaitEventType to corresponding counter values in InstCounterType.
virtual const WaitEventSet *getWaitEventMask() const = 0;
- /// \Returns the counter that corresponds to event \p E.
+ /// \returns the counter that corresponds to event \p E.
InstCounterType getCounterFromEvent(WaitEventType E) const {
const WaitEventSet *WaitEvents = getWaitEventMask();
for (auto T : inst_counter_types()) {
More information about the llvm-commits
mailing list