diff options
author | Min-Yih Hsu <min.hsu@sifive.com> | 2025-04-08 10:31:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-08 10:31:05 -0700 |
commit | 9bfb4b8fb194c1df5b082888abc03d095e39b6e9 (patch) | |
tree | 828f69446d8f1173c75392ea81d4f871602af384 /llvm/lib/CodeGen/MachineScheduler.cpp | |
parent | b7b3758e88f15a7ec27f212cd46e3dcf4e2f39f5 (diff) | |
download | llvm-9bfb4b8fb194c1df5b082888abc03d095e39b6e9.zip llvm-9bfb4b8fb194c1df5b082888abc03d095e39b6e9.tar.gz llvm-9bfb4b8fb194c1df5b082888abc03d095e39b6e9.tar.bz2 |
[MachineScheduler] Add more debug prints w.r.t hazards and pending SUnits (#134328)
While we already have some detailed debug messages on the candidate
selection process -- which selects a SUnit from the Available queue, we
didn't say much about why a SUnit was _not_ moved from Pending queue to
Available queue in the first place, which is just as important as why we
scheduled a node IMHO. Therefore, I added some debug prints for this
very purpose.
I decide to print these extra messages by default (instead of being
guarded by command line like `-misched-detail-resource-booking`) because
we have been printing some of the hazard remarks, so I thought we might
as well print these new messages -- which are mostly about hazard -- by
default.
Diffstat (limited to 'llvm/lib/CodeGen/MachineScheduler.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineScheduler.cpp | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/llvm/lib/CodeGen/MachineScheduler.cpp b/llvm/lib/CodeGen/MachineScheduler.cpp index 5086ee8..97f2727 100644 --- a/llvm/lib/CodeGen/MachineScheduler.cpp +++ b/llvm/lib/CodeGen/MachineScheduler.cpp @@ -2617,21 +2617,25 @@ SchedBoundary::getNextResourceCycle(const MCSchedClassDesc *SC, unsigned PIdx, bool SchedBoundary::checkHazard(SUnit *SU) { if (HazardRec->isEnabled() && HazardRec->getHazardType(SU) != ScheduleHazardRecognizer::NoHazard) { + LLVM_DEBUG(dbgs().indent(2) + << "hazard: SU(" << SU->NodeNum << ") reported by HazardRec\n"); return true; } unsigned uops = SchedModel->getNumMicroOps(SU->getInstr()); if ((CurrMOps > 0) && (CurrMOps + uops > SchedModel->getIssueWidth())) { - LLVM_DEBUG(dbgs() << " SU(" << SU->NodeNum << ") uops=" - << SchedModel->getNumMicroOps(SU->getInstr()) << '\n'); + LLVM_DEBUG(dbgs().indent(2) << "hazard: SU(" << SU->NodeNum << ") uops=" + << uops << ", CurrMOps = " << CurrMOps << ", " + << "CurrMOps + uops > issue width of " + << SchedModel->getIssueWidth() << "\n"); return true; } if (CurrMOps > 0 && ((isTop() && SchedModel->mustBeginGroup(SU->getInstr())) || (!isTop() && SchedModel->mustEndGroup(SU->getInstr())))) { - LLVM_DEBUG(dbgs() << " hazard: SU(" << SU->NodeNum << ") must " - << (isTop() ? "begin" : "end") << " group\n"); + LLVM_DEBUG(dbgs().indent(2) << "hazard: SU(" << SU->NodeNum << ") must " + << (isTop() ? "begin" : "end") << " group\n"); return true; } @@ -2650,10 +2654,12 @@ bool SchedBoundary::checkHazard(SUnit *SU) { #if LLVM_ENABLE_ABI_BREAKING_CHECKS MaxObservedStall = std::max(ReleaseAtCycle, MaxObservedStall); #endif - LLVM_DEBUG(dbgs() << " SU(" << SU->NodeNum << ") " - << SchedModel->getResourceName(ResIdx) - << '[' << InstanceIdx - ReservedCyclesIndex[ResIdx] << ']' - << "=" << NRCycle << "c\n"); + LLVM_DEBUG(dbgs().indent(2) + << "hazard: SU(" << SU->NodeNum << ") " + << SchedModel->getResourceName(ResIdx) << '[' + << InstanceIdx - ReservedCyclesIndex[ResIdx] << ']' << "=" + << NRCycle << "c, is later than " + << "CurrCycle = " << CurrCycle << "c\n"); return true; } } @@ -2728,11 +2734,25 @@ void SchedBoundary::releaseNode(SUnit *SU, unsigned ReadyCycle, bool InPQueue, // Check for interlocks first. For the purpose of other heuristics, an // instruction that cannot issue appears as if it's not in the ReadyQueue. bool IsBuffered = SchedModel->getMicroOpBufferSize() != 0; - bool HazardDetected = (!IsBuffered && ReadyCycle > CurrCycle) || - checkHazard(SU) || (Available.size() >= ReadyListLimit); + bool HazardDetected = !IsBuffered && ReadyCycle > CurrCycle; + if (HazardDetected) + LLVM_DEBUG(dbgs().indent(2) << "hazard: SU(" << SU->NodeNum + << ") ReadyCycle = " << ReadyCycle + << " is later than CurrCycle = " << CurrCycle + << " on an unbuffered resource" << "\n"); + else + HazardDetected = checkHazard(SU); + + if (!HazardDetected && Available.size() >= ReadyListLimit) { + HazardDetected = true; + LLVM_DEBUG(dbgs().indent(2) << "hazard: Available Q is full (size: " + << Available.size() << ")\n"); + } if (!HazardDetected) { Available.push(SU); + LLVM_DEBUG(dbgs().indent(2) + << "Move SU(" << SU->NodeNum << ") into Available Q\n"); if (InPQueue) Pending.remove(Pending.begin() + Idx); @@ -3011,6 +3031,8 @@ void SchedBoundary::releasePending() { SUnit *SU = *(Pending.begin() + I); unsigned ReadyCycle = isTop() ? SU->TopReadyCycle : SU->BotReadyCycle; + LLVM_DEBUG(dbgs() << "Checking pending node SU(" << SU->NodeNum << ")\n"); + if (ReadyCycle < MinReadyCycle) MinReadyCycle = ReadyCycle; |