Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b382b43
REBASED
JonPsson Feb 6, 2023
55ba17f
Rebase. Updates per latest review.
JonPsson1 Apr 24, 2025
c844226
Add handling of new BotIdx and NumRegionInstrs.
JonPsson1 Aug 7, 2025
042f15c
Try without the special handling for long lat in tiny region.
JonPsson1 Aug 7, 2025
0f067e2
Revert "Try without the special handling for long lat in tiny region."
JonPsson1 Aug 7, 2025
8cbf504
Experiment with BotRPTracker
JonPsson1 Aug 11, 2025
d49a3b3
Improve comment in initializePressureSets().
JonPsson1 Aug 18, 2025
9193b2d
Remove OPERAND_MEMORY check in one place (NFC).
JonPsson1 Aug 18, 2025
bd30247
- Improve the heuristic as to when use latency reduction. Do this onl…
JonPsson1 Aug 28, 2025
8228743
Squash.
JonPsson1 Aug 28, 2025
7fa69cd
Remove TODO comments that have now been tried.
JonPsson1 Sep 22, 2025
bcb2e3a
Fixing of comments
JonPsson1 Sep 23, 2025
6d889bd
Simplify detection of a killing store (NFC).
JonPsson1 Sep 23, 2025
567c80d
Commenting
JonPsson1 Sep 23, 2025
335565b
Commenting. Remove two stale #include:s.
JonPsson1 Sep 23, 2025
89d131e
EXPERIMENT: Use UsesLiveAll also with PreservesSchedLat.
JonPsson1 Sep 24, 2025
c5ab432
Revert "EXPERIMENT: Use UsesLiveAll also with PreservesSchedLat."
JonPsson1 Sep 24, 2025
2e545a3
EXPERIMENT: Use UsesLivePrio also with HasDistToTop.
JonPsson1 Sep 25, 2025
71fec89
Revert "EXPERIMENT: Use UsesLivePrio also with HasDistToTop."
JonPsson1 Sep 25, 2025
1914d53
NFC refactoring and some commenting.
JonPsson1 Sep 26, 2025
3dc7da1
Settle for always using PressureDiffs when checking liveness.
JonPsson1 Sep 26, 2025
9e8eba2
Minor knit.
JonPsson1 Sep 27, 2025
a225b37
Simplifications:
JonPsson1 Oct 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion llvm/include/llvm/CodeGen/MachineScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,7 @@ class GenericSchedulerBase : public MachineSchedStrategy {
NoCand,
Only1,
PhysReg,
LivenessReduce,
RegExcess,
RegCritical,
Stall,
Expand Down Expand Up @@ -1223,12 +1224,13 @@ class GenericSchedulerBase : public MachineSchedStrategy {
void traceCandidate(const SchedCandidate &Cand);
#endif

private:
protected:
bool shouldReduceLatency(const CandPolicy &Policy, SchedBoundary &CurrZone,
bool ComputeRemLatency, unsigned &RemLatency) const;
};

// Utility functions used by heuristics in tryCandidate().
LLVM_ABI unsigned computeRemLatency(SchedBoundary &CurrZone);
LLVM_ABI bool tryLess(int TryVal, int CandVal,
GenericSchedulerBase::SchedCandidate &TryCand,
GenericSchedulerBase::SchedCandidate &Cand,
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/CodeGen/RegisterPressure.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ class RegPressureTracker {
/// tracker before the first call to advance/recede.
LLVM_ABI void addLiveRegs(ArrayRef<VRegMaskOrUnit> Regs);

bool isRegLive(Register Reg) const { return LiveRegs.contains(Reg).any(); }

/// Get the MI position corresponding to this register pressure.
MachineBasicBlock::const_iterator getPos() const { return CurrPos; }

Expand Down
61 changes: 36 additions & 25 deletions llvm/lib/CodeGen/MachineScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ STATISTIC(NumOnly1PreRA,
"Number of scheduling units chosen for Only1 heuristic pre-RA");
STATISTIC(NumPhysRegPreRA,
"Number of scheduling units chosen for PhysReg heuristic pre-RA");
STATISTIC(NumLiveReducePreRA,
"Number of scheduling units chosen for LiveReduce heuristic pre-RA");
STATISTIC(NumRegExcessPreRA,
"Number of scheduling units chosen for RegExcess heuristic pre-RA");
STATISTIC(NumRegCriticalPreRA,
Expand Down Expand Up @@ -140,6 +142,8 @@ STATISTIC(NumOnly1PostRA,
"Number of scheduling units chosen for Only1 heuristic post-RA");
STATISTIC(NumPhysRegPostRA,
"Number of scheduling units chosen for PhysReg heuristic post-RA");
STATISTIC(NumLiveReducePostRA,
"Number of scheduling units chosen for LiveReduce heuristic post-RA");
STATISTIC(NumRegExcessPostRA,
"Number of scheduling units chosen for RegExcess heuristic post-RA");
STATISTIC(
Expand Down Expand Up @@ -3263,31 +3267,6 @@ initResourceDelta(const ScheduleDAGMI *DAG,
}
}

/// Compute remaining latency. We need this both to determine whether the
/// overall schedule has become latency-limited and whether the instructions
/// outside this zone are resource or latency limited.
///
/// The "dependent" latency is updated incrementally during scheduling as the
/// max height/depth of scheduled nodes minus the cycles since it was
/// scheduled:
/// DLat = max (N.depth - (CurrCycle - N.ReadyCycle) for N in Zone
///
/// The "independent" latency is the max ready queue depth:
/// ILat = max N.depth for N in Available|Pending
///
/// RemainingLatency is the greater of independent and dependent latency.
///
/// These computations are expensive, especially in DAGs with many edges, so
/// only do them if necessary.
static unsigned computeRemLatency(SchedBoundary &CurrZone) {
unsigned RemLatency = CurrZone.getDependentLatency();
RemLatency = std::max(RemLatency,
CurrZone.findMaxLatency(CurrZone.Available.elements()));
RemLatency = std::max(RemLatency,
CurrZone.findMaxLatency(CurrZone.Pending.elements()));
return RemLatency;
}

/// Returns true if the current cycle plus remaning latency is greater than
/// the critical path in the scheduling region.
bool GenericSchedulerBase::shouldReduceLatency(const CandPolicy &Policy,
Expand Down Expand Up @@ -3373,6 +3352,7 @@ const char *GenericSchedulerBase::getReasonStr(
case NoCand: return "NOCAND ";
case Only1: return "ONLY1 ";
case PhysReg: return "PHYS-REG ";
case LivenessReduce: return "LIVE-REDUC";
case RegExcess: return "REG-EXCESS";
case RegCritical: return "REG-CRIT ";
case Stall: return "STALL ";
Expand Down Expand Up @@ -3446,6 +3426,31 @@ void GenericSchedulerBase::traceCandidate(const SchedCandidate &Cand) {
#endif

namespace llvm {
/// Compute remaining latency. We need this both to determine whether the
/// overall schedule has become latency-limited and whether the instructions
/// outside this zone are resource or latency limited.
///
/// The "dependent" latency is updated incrementally during scheduling as the
/// max height/depth of scheduled nodes minus the cycles since it was
/// scheduled:
/// DLat = max (N.depth - (CurrCycle - N.ReadyCycle) for N in Zone
///
/// The "independent" latency is the max ready queue depth:
/// ILat = max N.depth for N in Available|Pending
///
/// RemainingLatency is the greater of independent and dependent latency.
///
/// These computations are expensive, especially in DAGs with many edges, so
/// only do them if necessary.
unsigned computeRemLatency(SchedBoundary &CurrZone) {
unsigned RemLatency = CurrZone.getDependentLatency();
RemLatency = std::max(RemLatency,
CurrZone.findMaxLatency(CurrZone.Available.elements()));
RemLatency = std::max(RemLatency,
CurrZone.findMaxLatency(CurrZone.Pending.elements()));
return RemLatency;
}

/// Return true if this heuristic determines order.
/// TODO: Consider refactor return type of these functions as integer or enum,
/// as we may need to differentiate whether TryCand is better than Cand.
Expand Down Expand Up @@ -3537,6 +3542,9 @@ static void tracePick(GenericSchedulerBase::CandReason Reason, bool IsTop,
case GenericScheduler::PhysReg:
NumPhysRegPostRA++;
return;
case GenericScheduler::LivenessReduce:
NumLiveReducePostRA++;
return;
case GenericScheduler::RegExcess:
NumRegExcessPostRA++;
return;
Expand Down Expand Up @@ -3596,6 +3604,9 @@ static void tracePick(GenericSchedulerBase::CandReason Reason, bool IsTop,
case GenericScheduler::PhysReg:
NumPhysRegPreRA++;
return;
case GenericScheduler::LivenessReduce:
NumLiveReducePreRA++;
return;
case GenericScheduler::RegExcess:
NumRegExcessPreRA++;
return;
Expand Down
Loading
Loading