Skip to content

[AMDGPU][SIInsertWaitcnts][NFC] Introduce Counter::advance()#193381

Open
vporpo wants to merge 1 commit intousers/vporpo/waitcnt10-3from
users/vporpo/waitcnt10-4
Open

[AMDGPU][SIInsertWaitcnts][NFC] Introduce Counter::advance()#193381
vporpo wants to merge 1 commit intousers/vporpo/waitcnt10-3from
users/vporpo/waitcnt10-4

Conversation

@vporpo
Copy link
Copy Markdown
Contributor

@vporpo vporpo commented Apr 22, 2026

This patch moves the logic that advances the counter into the Counter itself.
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Apr 22, 2026

@llvm/pr-subscribers-backend-amdgpu

Author: vporpo (vporpo)

Changes

This patch moves the logic that advances the counter into the Counter itself.


Previous PRs:

  1. [AMDGPU][SIInsertWaitcnts][NFC] Introduce Counter class #193368
  2. [AMDGPU][SIInsertWaitcnts][NFC] Introduce Counter::merge() #193369
  3. [AMDGPU][SIInsertWaitcnts][NFC] Introduce Counter::getWait() #193374

Full diff: https://github.com/llvm/llvm-project/pull/193381.diff

1 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp (+11-6)
diff --git a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
index cfa6ec691002a..7d9ad6bf38686 100644
--- a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
@@ -815,6 +815,15 @@ class WaitcntBrackets {
       /// \returns true if the counter includes \p Score, i.e., it has
       /// contributed to its current value, or in other words it is pending.
       bool contains(unsigned Score) const { return LB < Score && Score <= UB; }
+      /// Increment the counter.
+      unsigned advance() {
+        // We are setting the value with setUB() to make sure it goes through
+        // the EXP_CNT limit enforcing code.
+        setUB(UB + 1);
+        if (UB == 0)
+          report_fatal_error("InsertWaitcnt score wraparound");
+        return UB;
+      }
     };
 
     std::array<Counter, AMDGPU::NUM_INST_CNTS> Counters;
@@ -1167,15 +1176,11 @@ void WaitcntBrackets::updateByEvent(WaitEventType E, MachineInstr &Inst) {
   AMDGPU::InstCounterType T = Context->getCounterFromEvent(E);
   assert(T < Context->MaxCounter);
 
-  unsigned UB = getScoreUB(T);
-  unsigned CurrScore = UB + 1;
-  if (CurrScore == 0)
-    report_fatal_error("InsertWaitcnt score wraparound");
-  // PendingEvents and ScoreUB need to be update regardless if this event
+  unsigned CurrScore = Counters[T].advance();
+  // PendingEvents and ScoreUB need to be updated regardless if this event
   // changes the score of a register or not.
   // Examples including vm_cnt when buffer-store or lgkm_cnt when send-message.
   PendingEvents.insert(E);
-  setScoreUB(T, CurrScore);
 
   const SIRegisterInfo &TRI = Context->TRI;
   const MachineRegisterInfo &MRI = Context->MRI;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants