================
@@ -1265,13 +1368,59 @@ void 
WaitcntBrackets::determineWaitForScore(InstCounterType T,
     } else {
       // If a counter has been maxed out avoid overflow by waiting for
       // MAX(CounterType) - 1 instead.
-      unsigned NeededWait =
-          std::min(UB - ScoreToWait, Context->getWaitCountMax(T) - 1);
+      unsigned NeededWait = getClampedWait(T, ScoreToWait);
       addWait(Wait, T, NeededWait);
     }
   }
 }
 
+AMDGPU::Waitcnt WaitcntBrackets::determineAsyncWait(unsigned N) {
+  LLVM_DEBUG({
+    dbgs() << "Need " << N << " async markers. Found " << AsyncMarkers.size()
+           << ":\n";
+    for (const auto &Marker : AsyncMarkers) {
+      llvm::interleaveComma(Marker, dbgs());
+      dbgs() << '\n';
+    }
+  });
+
+  AMDGPU::Waitcnt Wait;
+  if (AsyncMarkers.size() <= N) {
+    LLVM_DEBUG(dbgs() << "No additional wait for async marker.\n");
+    return Wait;
+  }
+
+  size_t MarkerIndex = AsyncMarkers.size() - N - 1;
+  const auto &RequiredMarker = AsyncMarkers[MarkerIndex];
+  for (InstCounterType T : inst_counter_types()) {
+    unsigned ScoreToWait = RequiredMarker[T];
+    if (ScoreToWait == 0) {
+      continue;
+    }
----------------
Pierre-vh wrote:

```suggestion
    if (ScoreToWait == 0) 
      continue;
```

https://github.com/llvm/llvm-project/pull/173259
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to