[llvm] [AMDGPU][SIInsertWaitcnts][NFC] Introduce Counter class (PR #190271)
Shilei Tian via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 8 15:15:43 PDT 2026
================
@@ -733,14 +734,65 @@ class WaitcntBrackets {
bool empty(InstCounterType T) const { return getScoreRange(T) == 0; }
private:
+ /// A container that holds all counters.
+ class AllCounters {
+ /// A counter of a specific InstCounterType. Whenever this pass visits an
+ /// instruction that affects this counter type we "increment" the counter.
+ /// Conceptually the counter implements the value of the corresponding
+ /// AMDGPU hardware counter if none of the outstanding instructions that
+ /// affect this counter had completed. When a wait for this counter is
+ /// emitted then we "decrement" (or zero) the counter.
+ class Counter {
+ InstCounterType CntT;
+ const AMDGPU::HardwareLimits *Limits = nullptr;
+ unsigned LB = 0;
+ unsigned UB = 0;
+
+ public:
+ Counter() = default;
+ Counter(InstCounterType CntT, const AMDGPU::HardwareLimits &Limits)
+ : CntT(CntT), Limits(&Limits) {}
+ /// \returns the count of outstanding instrs tracked by this counter.
+ unsigned getValue() const { return UB - LB; }
+ // TODO: Make private: we should not provide raw access to the internals.
+ void setLB(unsigned NewLB) { LB = NewLB; }
+ // TODO: Make private: we should not provide raw access to the internals.
+ void setUB(unsigned NewUB) {
+ UB = NewUB;
+ if (CntT == EXP_CNT) {
+ if (getValue() > getWaitCountMax(*Limits, EXP_CNT))
+ LB = UB - getWaitCountMax(*Limits, EXP_CNT);
+ }
+ }
+ // TODO: Make private: we should not provide raw access to the internals.
+ unsigned getUB() const { return UB; }
+ // TODO: Make private: we should not provide raw access to the internals.
+ unsigned getLB() const { return LB; }
+
+ /// \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; }
----------------
shiltian wrote:
being nit-picky here: not sure `constains` is a good word for this. Maybe `isPending`?
https://github.com/llvm/llvm-project/pull/190271
More information about the llvm-commits
mailing list