[llvm] [AMDGPU][CoExecSched] Add free-proximity scheduling heuristic (PR #225334)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 22 02:31:22 PDT 2026
================
@@ -463,32 +476,163 @@ SUnit *HardwareUnitInfo::getNextTargetSU(bool LookDeep) const {
return TargetSU;
}
-void HardwareUnitInfo::insert(SUnit *SU, unsigned BlockingCycles) {
- if (!AllSUs.insert(SU))
- llvm_unreachable("HardwareUnit already contains SU!");
+int HardwareUnitInfo::compareDepth(SUnit *Candidate, SUnit *Existing) const {
+ const unsigned CurDepth = Existing->getDepth();
+ const unsigned CandDepth = Candidate->getDepth();
- TotalCycles += BlockingCycles;
+ if (CandDepth > CurDepth)
+ return -1;
+ if (CandDepth == CurDepth)
+ return 0;
+ return 1;
+}
+
+int HardwareUnitInfo::compareRegFreeProximity(SUnit *Candidate,
+ SUnit *Existing) const {
+ const MachineInstr *CandMI = Candidate->getInstr();
+ const bool IsMemOp = SIInstrInfo::isDS(*CandMI) ||
+ SIInstrInfo::isFLAT(*CandMI) ||
+ SIInstrInfo::isVMEM(*CandMI);
+ if (IsMemOp)
+ return compareDepth(Candidate, Existing);
+ auto getRegStats = [](const SUnit *SU) {
+ SmallDenseMap<Register, unsigned, 8> RegMaxUnsched;
+
+ for (const SDep &Pred : SU->Preds) {
+ if (Pred.getKind() != SDep::Data)
+ continue;
+ Register Reg = Pred.getReg();
+ if (!Reg)
+ continue;
+ const SUnit *PredSU = Pred.getSUnit();
+ unsigned Unscheduled = 0;
+ for (const SDep &Succ : PredSU->Succs)
+ if (Succ.getKind() == SDep::Data && !Succ.getSUnit()->isScheduled)
+ ++Unscheduled;
+
+ LLVM_DEBUG({
+ dbgs() << " pred SU(" << PredSU->NodeNum
+ << ") reg=" << printReg(Reg) << " unschedSuccs=" << Unscheduled
+ << " ";
+ if (PredSU->getInstr())
+ PredSU->getInstr()->print(dbgs(), /*IsStandalone=*/true,
+ /*SkipOpers=*/false, /*SkipDebugLoc=*/true);
+ else
+ dbgs() << "<no instr>";
+ dbgs() << "\n";
+ });
+ RegMaxUnsched[Reg] = std::max(RegMaxUnsched[Reg], Unscheduled);
----------------
kazutakahirata wrote:
Could we avoid duplicate hash lookups on `RegMaxUnsched` by binding a reference?
```suggestion
auto &MaxUnsched = RegMaxUnsched[Reg];
MaxUnsched = std::max(MaxUnsched, Unscheduled);
```
https://github.com/llvm/llvm-project/pull/225334
More information about the llvm-commits
mailing list