Skip to content

Commit 61010d6

Browse files
committed
[MISched] Add statistics for heuristics
When diagnosing scheduling issues it can be useful to know which heuristics are driving the scheduler. This adds pre-RA and post-RA statistics for all heuristics.
1 parent 4cde945 commit 61010d6

File tree

1 file changed

+228
-13
lines changed

1 file changed

+228
-13
lines changed

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 228 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,97 @@ using namespace llvm;
7676

7777
STATISTIC(NumClustered, "Number of load/store pairs clustered");
7878

79+
STATISTIC(NumTopPreRA,
80+
"Number of scheduling units chosen from top queue pre-RA");
81+
STATISTIC(NumBotPreRA,
82+
"Number of scheduling units chosen from bottom queue pre-RA");
83+
STATISTIC(NumNoCandPreRA,
84+
"Number of scheduling units chosen for NoCand heuristic pre-RA");
85+
STATISTIC(NumOnly1PreRA,
86+
"Number of scheduling units chosen for Only1 heuristic pre-RA");
87+
STATISTIC(NumPhysRegPreRA,
88+
"Number of scheduling units chosen for PhysReg heuristic pre-RA");
89+
STATISTIC(NumRegExcessPreRA,
90+
"Number of scheduling units chosen for RegExcess heuristic pre-RA");
91+
STATISTIC(NumRegCriticalPreRA,
92+
"Number of scheduling units chosen for RegCritical heuristic pre-RA");
93+
STATISTIC(NumStallPreRA,
94+
"Number of scheduling units chosen for Stall heuristic pre-RA");
95+
STATISTIC(NumClusterPreRA,
96+
"Number of scheduling units chosen for Cluster heuristic pre-RA");
97+
STATISTIC(NumWeakPreRA,
98+
"Number of scheduling units chosen for Weak heuristic pre-RA");
99+
STATISTIC(NumRegMaxPreRA,
100+
"Number of scheduling units chosen for RegMax heuristic pre-RA");
101+
STATISTIC(
102+
NumResourceReducePreRA,
103+
"Number of scheduling units chosen for ResourceReduce heuristic pre-RA");
104+
STATISTIC(
105+
NumResourceDemandPreRA,
106+
"Number of scheduling units chosen for ResourceDemand heuristic pre-RA");
107+
STATISTIC(
108+
NumTopDepthReducePreRA,
109+
"Number of scheduling units chosen for TopDepthReduce heuristic pre-RA");
110+
STATISTIC(
111+
NumTopPathReducePreRA,
112+
"Number of scheduling units chosen for TopPathReduce heuristic pre-RA");
113+
STATISTIC(
114+
NumBotHeightReducePreRA,
115+
"Number of scheduling units chosen for BotHeightReduce heuristic pre-RA");
116+
STATISTIC(
117+
NumBotPathReducePreRA,
118+
"Number of scheduling units chosen for BotPathReduce heuristic pre-RA");
119+
STATISTIC(NumNodeOrderPreRA,
120+
"Number of scheduling units chosen for NodeOrder heuristic pre-RA");
121+
STATISTIC(NumFirstValidPreRA,
122+
"Number of scheduling units chosen for FirstValid heuristic pre-RA");
123+
124+
STATISTIC(NumTopPostRA,
125+
"Number of scheduling units chosen from top queue post-RA");
126+
STATISTIC(NumBotPostRA,
127+
"Number of scheduling units chosen from bottom queue post-RA");
128+
STATISTIC(NumNoCandPostRA,
129+
"Number of scheduling units chosen for NoCand heuristic post-RA");
130+
STATISTIC(NumOnly1PostRA,
131+
"Number of scheduling units chosen for Only1 heuristic post-RA");
132+
STATISTIC(NumPhysRegPostRA,
133+
"Number of scheduling units chosen for PhysReg heuristic post-RA");
134+
STATISTIC(NumRegExcessPostRA,
135+
"Number of scheduling units chosen for RegExcess heuristic post-RA");
136+
STATISTIC(
137+
NumRegCriticalPostRA,
138+
"Number of scheduling units chosen for RegCritical heuristic post-RA");
139+
STATISTIC(NumStallPostRA,
140+
"Number of scheduling units chosen for Stall heuristic post-RA");
141+
STATISTIC(NumClusterPostRA,
142+
"Number of scheduling units chosen for Cluster heuristic post-RA");
143+
STATISTIC(NumWeakPostRA,
144+
"Number of scheduling units chosen for Weak heuristic post-RA");
145+
STATISTIC(NumRegMaxPostRA,
146+
"Number of scheduling units chosen for RegMax heuristic post-RA");
147+
STATISTIC(
148+
NumResourceReducePostRA,
149+
"Number of scheduling units chosen for ResourceReduce heuristic post-RA");
150+
STATISTIC(
151+
NumResourceDemandPostRA,
152+
"Number of scheduling units chosen for ResourceDemand heuristic post-RA");
153+
STATISTIC(
154+
NumTopDepthReducePostRA,
155+
"Number of scheduling units chosen for TopDepthReduce heuristic post-RA");
156+
STATISTIC(
157+
NumTopPathReducePostRA,
158+
"Number of scheduling units chosen for TopPathReduce heuristic post-RA");
159+
STATISTIC(
160+
NumBotHeightReducePostRA,
161+
"Number of scheduling units chosen for BotHeightReduce heuristic post-RA");
162+
STATISTIC(
163+
NumBotPathReducePostRA,
164+
"Number of scheduling units chosen for BotPathReduce heuristic post-RA");
165+
STATISTIC(NumNodeOrderPostRA,
166+
"Number of scheduling units chosen for NodeOrder heuristic post-RA");
167+
STATISTIC(NumFirstValidPostRA,
168+
"Number of scheduling units chosen for FirstValid heuristic post-RA");
169+
79170
namespace llvm {
80171

81172
cl::opt<MISched::Direction> PreRADirection(
@@ -3420,13 +3511,137 @@ bool tryLatency(GenericSchedulerBase::SchedCandidate &TryCand,
34203511
}
34213512
} // end namespace llvm
34223513

3423-
static void tracePick(GenericSchedulerBase::CandReason Reason, bool IsTop) {
3514+
static void tracePick(GenericSchedulerBase::CandReason Reason, bool IsTop,
3515+
bool IsPostRA = false) {
34243516
LLVM_DEBUG(dbgs() << "Pick " << (IsTop ? "Top " : "Bot ")
3425-
<< GenericSchedulerBase::getReasonStr(Reason) << '\n');
3517+
<< GenericSchedulerBase::getReasonStr(Reason) << " ["
3518+
<< (IsPostRA ? "post-RA" : "pre-RA") << "]\n");
3519+
3520+
if (IsPostRA) {
3521+
if (IsTop)
3522+
NumTopPostRA++;
3523+
else
3524+
NumBotPostRA++;
3525+
3526+
switch (Reason) {
3527+
case GenericScheduler::NoCand:
3528+
NumNoCandPostRA++;
3529+
return;
3530+
case GenericScheduler::Only1:
3531+
NumOnly1PostRA++;
3532+
return;
3533+
case GenericScheduler::PhysReg:
3534+
NumPhysRegPostRA++;
3535+
return;
3536+
case GenericScheduler::RegExcess:
3537+
NumRegExcessPostRA++;
3538+
return;
3539+
case GenericScheduler::RegCritical:
3540+
NumRegCriticalPostRA++;
3541+
return;
3542+
case GenericScheduler::Stall:
3543+
NumStallPostRA++;
3544+
return;
3545+
case GenericScheduler::Cluster:
3546+
NumClusterPostRA++;
3547+
return;
3548+
case GenericScheduler::Weak:
3549+
NumWeakPostRA++;
3550+
return;
3551+
case GenericScheduler::RegMax:
3552+
NumRegMaxPostRA++;
3553+
return;
3554+
case GenericScheduler::ResourceReduce:
3555+
NumResourceReducePostRA++;
3556+
return;
3557+
case GenericScheduler::ResourceDemand:
3558+
NumResourceDemandPostRA++;
3559+
return;
3560+
case GenericScheduler::TopDepthReduce:
3561+
NumTopDepthReducePostRA++;
3562+
return;
3563+
case GenericScheduler::TopPathReduce:
3564+
NumTopPathReducePostRA++;
3565+
return;
3566+
case GenericScheduler::BotHeightReduce:
3567+
NumBotHeightReducePostRA++;
3568+
return;
3569+
case GenericScheduler::BotPathReduce:
3570+
NumBotPathReducePostRA++;
3571+
return;
3572+
case GenericScheduler::NodeOrder:
3573+
NumNodeOrderPostRA++;
3574+
return;
3575+
case GenericScheduler::FirstValid:
3576+
NumFirstValidPostRA++;
3577+
return;
3578+
};
3579+
} else {
3580+
if (IsTop)
3581+
NumTopPreRA++;
3582+
else
3583+
NumBotPreRA++;
3584+
3585+
switch (Reason) {
3586+
case GenericScheduler::NoCand:
3587+
NumNoCandPreRA++;
3588+
return;
3589+
case GenericScheduler::Only1:
3590+
NumOnly1PreRA++;
3591+
return;
3592+
case GenericScheduler::PhysReg:
3593+
NumPhysRegPreRA++;
3594+
return;
3595+
case GenericScheduler::RegExcess:
3596+
NumRegExcessPreRA++;
3597+
return;
3598+
case GenericScheduler::RegCritical:
3599+
NumRegCriticalPreRA++;
3600+
return;
3601+
case GenericScheduler::Stall:
3602+
NumStallPreRA++;
3603+
return;
3604+
case GenericScheduler::Cluster:
3605+
NumClusterPreRA++;
3606+
return;
3607+
case GenericScheduler::Weak:
3608+
NumWeakPreRA++;
3609+
return;
3610+
case GenericScheduler::RegMax:
3611+
NumRegMaxPreRA++;
3612+
return;
3613+
case GenericScheduler::ResourceReduce:
3614+
NumResourceReducePreRA++;
3615+
return;
3616+
case GenericScheduler::ResourceDemand:
3617+
NumResourceDemandPreRA++;
3618+
return;
3619+
case GenericScheduler::TopDepthReduce:
3620+
NumTopDepthReducePreRA++;
3621+
return;
3622+
case GenericScheduler::TopPathReduce:
3623+
NumTopPathReducePreRA++;
3624+
return;
3625+
case GenericScheduler::BotHeightReduce:
3626+
NumBotHeightReducePreRA++;
3627+
return;
3628+
case GenericScheduler::BotPathReduce:
3629+
NumBotPathReducePreRA++;
3630+
return;
3631+
case GenericScheduler::NodeOrder:
3632+
NumNodeOrderPreRA++;
3633+
return;
3634+
case GenericScheduler::FirstValid:
3635+
NumFirstValidPreRA++;
3636+
return;
3637+
};
3638+
}
3639+
llvm_unreachable("Unknown reason!");
34263640
}
34273641

3428-
static void tracePick(const GenericSchedulerBase::SchedCandidate &Cand) {
3429-
tracePick(Cand.Reason, Cand.AtTop);
3642+
static void tracePick(const GenericSchedulerBase::SchedCandidate &Cand,
3643+
bool IsPostRA = false) {
3644+
tracePick(Cand.Reason, Cand.AtTop, IsPostRA);
34303645
}
34313646

34323647
void GenericScheduler::initialize(ScheduleDAGMI *dag) {
@@ -3849,12 +4064,12 @@ SUnit *GenericScheduler::pickNodeBidirectional(bool &IsTopNode) {
38494064
// efficient, but also provides the best heuristics for CriticalPSets.
38504065
if (SUnit *SU = Bot.pickOnlyChoice()) {
38514066
IsTopNode = false;
3852-
tracePick(Only1, false);
4067+
tracePick(Only1, /*IsTopNode=*/false);
38534068
return SU;
38544069
}
38554070
if (SUnit *SU = Top.pickOnlyChoice()) {
38564071
IsTopNode = true;
3857-
tracePick(Only1, true);
4072+
tracePick(Only1, /*IsTopNode=*/true);
38584073
return SU;
38594074
}
38604075
// Set the bottom-up policy based on the state of the current bottom zone and
@@ -4196,12 +4411,12 @@ SUnit *PostGenericScheduler::pickNodeBidirectional(bool &IsTopNode) {
41964411
// efficient, but also provides the best heuristics for CriticalPSets.
41974412
if (SUnit *SU = Bot.pickOnlyChoice()) {
41984413
IsTopNode = false;
4199-
tracePick(Only1, false);
4414+
tracePick(Only1, /*IsTopNode=*/false, /*IsPostRA=*/true);
42004415
return SU;
42014416
}
42024417
if (SUnit *SU = Top.pickOnlyChoice()) {
42034418
IsTopNode = true;
4204-
tracePick(Only1, true);
4419+
tracePick(Only1, /*IsTopNode=*/true, /*IsPostRA=*/true);
42054420
return SU;
42064421
}
42074422
// Set the bottom-up policy based on the state of the current bottom zone and
@@ -4264,7 +4479,7 @@ SUnit *PostGenericScheduler::pickNodeBidirectional(bool &IsTopNode) {
42644479
}
42654480

42664481
IsTopNode = Cand.AtTop;
4267-
tracePick(Cand);
4482+
tracePick(Cand, /*IsPostRA=*/true);
42684483
return Cand.SU;
42694484
}
42704485

@@ -4280,7 +4495,7 @@ SUnit *PostGenericScheduler::pickNode(bool &IsTopNode) {
42804495
if (RegionPolicy.OnlyBottomUp) {
42814496
SU = Bot.pickOnlyChoice();
42824497
if (SU) {
4283-
tracePick(Only1, true);
4498+
tracePick(Only1, /*IsTopNode=*/true, /*IsPostRA=*/true);
42844499
} else {
42854500
CandPolicy NoPolicy;
42864501
BotCand.reset(NoPolicy);
@@ -4289,14 +4504,14 @@ SUnit *PostGenericScheduler::pickNode(bool &IsTopNode) {
42894504
setPolicy(BotCand.Policy, /*IsPostRA=*/true, Bot, nullptr);
42904505
pickNodeFromQueue(Bot, BotCand);
42914506
assert(BotCand.Reason != NoCand && "failed to find a candidate");
4292-
tracePick(BotCand);
4507+
tracePick(BotCand, /*IsPostRA=*/true);
42934508
SU = BotCand.SU;
42944509
}
42954510
IsTopNode = false;
42964511
} else if (RegionPolicy.OnlyTopDown) {
42974512
SU = Top.pickOnlyChoice();
42984513
if (SU) {
4299-
tracePick(Only1, true);
4514+
tracePick(Only1, /*IsTopNode=*/true, /*IsPostRA=*/true);
43004515
} else {
43014516
CandPolicy NoPolicy;
43024517
TopCand.reset(NoPolicy);
@@ -4305,7 +4520,7 @@ SUnit *PostGenericScheduler::pickNode(bool &IsTopNode) {
43054520
setPolicy(TopCand.Policy, /*IsPostRA=*/true, Top, nullptr);
43064521
pickNodeFromQueue(Top, TopCand);
43074522
assert(TopCand.Reason != NoCand && "failed to find a candidate");
4308-
tracePick(TopCand);
4523+
tracePick(TopCand, /*IsPostRA=*/true);
43094524
SU = TopCand.SU;
43104525
}
43114526
IsTopNode = true;

0 commit comments

Comments
 (0)