[llvm-branch-commits] [llvm] [AMDGPU][NewInsertWaitcnt] Event Tracker (2/2) (PR #232344)
Pierre van Houtryve via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Nov 5 02:11:07 PST 2026
================
@@ -189,6 +268,93 @@ LLVM_DUMP_METHOD void EventTracker::dump() const {
}
#endif
+bool EventTracker::compareRecords(const EventTrackerRecord &A,
+ const EventTrackerRecord &B) {
+ // Different height.
+ if (A.getHeight() != B.getHeight())
+ return A.getHeight() > B.getHeight();
+
+ // Same height but different kind.
+ unsigned AKindV = A.getKind().rawValue();
+ unsigned BKindV = B.getKind().rawValue();
+ if (AKindV != BKindV)
+ return AKindV > BKindV;
+
+ const MachineInstr *AMI = A.getMI();
+ const MachineInstr *BMI = B.getMI();
+ if (AMI == BMI)
+ return false;
+
+ // Same height/kind but MIs are in different MBBs: the one in the MBB with the
+ // lower number comes first.
+ const MachineBasicBlock *Bbb = BMI->getParent();
+ const MachineBasicBlock *Abb = AMI->getParent();
+ if (Abb != Bbb)
+ return Abb->getNumber() < Bbb->getNumber();
+
+ llvm_unreachable("We cannot have two distinct instructions from the same "
+ "MBB, at the same height and with the same event kind!");
+}
+
+void EventTracker::clear() {
+ for (CounterData &C : Counters) {
+ C.Timeline.clear();
+ C.Count = 0;
+ }
+}
+
+void EventTracker::recordIncomings(ArrayRef<EventTracker *> Preds) {
+ LLVM_DEBUG(if (!Preds.empty()) {
+ dbgs() << "[EventTracker] Recording incoming events (merge) from "
+ "predecessors:\n";
+ for (EventTracker *Pred : Preds) {
+ Pred->print(dbgs(), /*IgnoreEmpty=*/true, /*Indent=*/2);
+ }
+ });
+
+ // Iterate over all counters that are available to us.
+ for (CounterData &CData : Counters) {
+ assert(CData.Timeline.empty());
+
+ DenseMap<hash_code, EventTrackerRecord> Acc;
+
+ for (EventTracker *Pred : Preds) {
+ auto &PredCData = Pred->Counters[CData.CI->CounterT];
+
+ // The merged count is the max across predecessors.
+ CData.Count = std::max(CData.Count, PredCData.Count);
+
+ for (EventTrackerRecord &PredEntry : PredCData.Timeline) {
+ // At a join, collapse records from all predecessors with the same
+ // identity (MI+Kind) into a single record whose height is the minimum
+ // across predecessors.
+ hash_code Identity = PredEntry.getIdentity();
+ auto It = Acc.find(Identity);
+ if (It != Acc.end()) {
+ auto &AccVal = It->second;
+ AccVal.setHeight(std::min(AccVal.getHeight(), PredEntry.getHeight()));
+ } else
+ Acc.insert({Identity, PredEntry});
----------------
Pierre-vh wrote:
fixed
https://github.com/llvm/llvm-project/pull/232344
More information about the llvm-branch-commits
mailing list