Skip to content

Commit c8fb7be

Browse files
c-rhodesGeorgeARM
authored andcommitted
[MISched] Add statistics to quantify scheduling (llvm#138090)
When diagnosing scheduler issues it can be useful to know how scheduling changes the order of instructions, particularly for large functions when it's not trivial to figure out from the debug output by looking at the scheduling unit (SU) IDs. This adds pre-RA and post-RA statistics to track 1) the number of instructions that remain in source order after scheduling and 2) the total number of instructions scheduled, to compare 1) against.
1 parent 957beea commit c8fb7be

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

llvm/include/llvm/CodeGen/MachineScheduler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,9 @@ class GenericSchedulerBase : public MachineSchedStrategy {
11961196
const MachineSchedContext *Context;
11971197
const TargetSchedModel *SchedModel = nullptr;
11981198
const TargetRegisterInfo *TRI = nullptr;
1199+
unsigned TopIdx = 0;
1200+
unsigned BotIdx = 0;
1201+
unsigned NumRegionInstrs = 0;
11991202

12001203
MachineSchedPolicy RegionPolicy;
12011204

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ using namespace llvm;
7474

7575
#define DEBUG_TYPE "machine-scheduler"
7676

77+
STATISTIC(NumInstrsInSourceOrderPreRA,
78+
"Number of instructions in source order after pre-RA scheduling");
79+
STATISTIC(NumInstrsInSourceOrderPostRA,
80+
"Number of instructions in source order after post-RA scheduling");
81+
STATISTIC(NumInstrsScheduledPreRA,
82+
"Number of instructions scheduled by pre-RA scheduler");
83+
STATISTIC(NumInstrsScheduledPostRA,
84+
"Number of instructions scheduled by post-RA scheduler");
7785
STATISTIC(NumClustered, "Number of load/store pairs clustered");
7886

7987
namespace llvm {
@@ -3505,6 +3513,9 @@ void GenericScheduler::initPolicy(MachineBasicBlock::iterator Begin,
35053513
RegionPolicy.OnlyBottomUp = false;
35063514
RegionPolicy.OnlyTopDown = false;
35073515
}
3516+
3517+
BotIdx = NumRegionInstrs - 1;
3518+
this->NumRegionInstrs = NumRegionInstrs;
35083519
}
35093520

35103521
void GenericScheduler::dumpPolicy() const {
@@ -3981,6 +3992,18 @@ SUnit *GenericScheduler::pickNode(bool &IsTopNode) {
39813992

39823993
LLVM_DEBUG(dbgs() << "Scheduling SU(" << SU->NodeNum << ") "
39833994
<< *SU->getInstr());
3995+
3996+
if (IsTopNode) {
3997+
if (SU->NodeNum == TopIdx++)
3998+
++NumInstrsInSourceOrderPreRA;
3999+
} else {
4000+
assert(BotIdx < NumRegionInstrs && "out of bounds");
4001+
if (SU->NodeNum == BotIdx--)
4002+
++NumInstrsInSourceOrderPreRA;
4003+
}
4004+
4005+
NumInstrsScheduledPreRA += 1;
4006+
39844007
return SU;
39854008
}
39864009

@@ -4104,6 +4127,9 @@ void PostGenericScheduler::initPolicy(MachineBasicBlock::iterator Begin,
41044127
RegionPolicy.OnlyBottomUp = false;
41054128
RegionPolicy.OnlyTopDown = false;
41064129
}
4130+
4131+
BotIdx = NumRegionInstrs - 1;
4132+
this->NumRegionInstrs = NumRegionInstrs;
41074133
}
41084134

41094135
void PostGenericScheduler::registerRoots() {
@@ -4323,6 +4349,18 @@ SUnit *PostGenericScheduler::pickNode(bool &IsTopNode) {
43234349

43244350
LLVM_DEBUG(dbgs() << "Scheduling SU(" << SU->NodeNum << ") "
43254351
<< *SU->getInstr());
4352+
4353+
if (IsTopNode) {
4354+
if (SU->NodeNum == TopIdx++)
4355+
++NumInstrsInSourceOrderPostRA;
4356+
} else {
4357+
assert(BotIdx < NumRegionInstrs && "out of bounds");
4358+
if (SU->NodeNum == BotIdx--)
4359+
++NumInstrsInSourceOrderPostRA;
4360+
}
4361+
4362+
NumInstrsScheduledPostRA += 1;
4363+
43264364
return SU;
43274365
}
43284366

0 commit comments

Comments
 (0)