Skip to content

Commit 18e7bf5

Browse files
author
Jinsong Ji
committedMay 31, 2019
[MachinePipeliner][NFC] Add some debug log and statistics
This is to add some log and statistics for debugging Differential Revision: https://reviews.llvm.org/D62165 llvm-svn: 362233
1 parent 42d6c26 commit 18e7bf5

File tree

1 file changed

+71
-12
lines changed

1 file changed

+71
-12
lines changed
 

Diff for: ‎llvm/lib/CodeGen/MachinePipeliner.cpp

+71-12
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ using namespace llvm;
9696
STATISTIC(NumTrytoPipeline, "Number of loops that we attempt to pipeline");
9797
STATISTIC(NumPipelined, "Number of loops software pipelined");
9898
STATISTIC(NumNodeOrderIssues, "Number of node order issues found");
99+
STATISTIC(NumFailBranch, "Pipeliner abort due to unknown branch");
100+
STATISTIC(NumFailLoop, "Pipeliner abort due to unsupported loop");
101+
STATISTIC(NumFailPreheader, "Pipeliner abort due to missing preheader");
102+
STATISTIC(NumFailLargeMaxMII, "Pipeliner abort due to MaxMII too large");
103+
STATISTIC(NumFailZeroMII, "Pipeliner abort due to zero MII");
104+
STATISTIC(NumFailNoSchedule, "Pipeliner abort due to no schedule found");
105+
STATISTIC(NumFailZeroStage, "Pipeliner abort due to zero stage");
106+
STATISTIC(NumFailLargeMaxStage, "Pipeliner abort due to too many stages");
99107

100108
/// A command line option to turn software pipelining on or off.
101109
static cl::opt<bool> EnableSWP("enable-pipeliner", cl::Hidden, cl::init(true),
@@ -289,16 +297,28 @@ bool MachinePipeliner::canPipelineLoop(MachineLoop &L) {
289297
LI.TBB = nullptr;
290298
LI.FBB = nullptr;
291299
LI.BrCond.clear();
292-
if (TII->analyzeBranch(*L.getHeader(), LI.TBB, LI.FBB, LI.BrCond))
300+
if (TII->analyzeBranch(*L.getHeader(), LI.TBB, LI.FBB, LI.BrCond)) {
301+
LLVM_DEBUG(
302+
dbgs() << "Unable to analyzeBranch, can NOT pipeline current Loop\n");
303+
NumFailBranch++;
293304
return false;
305+
}
294306

295307
LI.LoopInductionVar = nullptr;
296308
LI.LoopCompare = nullptr;
297-
if (TII->analyzeLoop(L, LI.LoopInductionVar, LI.LoopCompare))
309+
if (TII->analyzeLoop(L, LI.LoopInductionVar, LI.LoopCompare)) {
310+
LLVM_DEBUG(
311+
dbgs() << "Unable to analyzeLoop, can NOT pipeline current Loop\n");
312+
NumFailLoop++;
298313
return false;
314+
}
299315

300-
if (!L.getLoopPreheader())
316+
if (!L.getLoopPreheader()) {
317+
LLVM_DEBUG(
318+
dbgs() << "Preheader not found, can NOT pipeline current Loop\n");
319+
NumFailPreheader++;
301320
return false;
321+
}
302322

303323
// Remove any subregisters from inputs to phi nodes.
304324
preprocessPhiNodes(*L.getHeader());
@@ -413,12 +433,21 @@ void SwingSchedulerDAG::schedule() {
413433
<< " (rec=" << RecMII << ", res=" << ResMII << ")\n");
414434

415435
// Can't schedule a loop without a valid MII.
416-
if (MII == 0)
436+
if (MII == 0) {
437+
LLVM_DEBUG(
438+
dbgs()
439+
<< "0 is not a valid Minimal Initiation Interval, can NOT schedule\n");
440+
NumFailZeroMII++;
417441
return;
442+
}
418443

419444
// Don't pipeline large loops.
420-
if (SwpMaxMii != -1 && (int)MII > SwpMaxMii)
445+
if (SwpMaxMii != -1 && (int)MII > SwpMaxMii) {
446+
LLVM_DEBUG(dbgs() << "MII > " << SwpMaxMii
447+
<< ", we don't pipleline large loops\n");
448+
NumFailLargeMaxMII++;
421449
return;
450+
}
422451

423452
computeNodeFunctions(NodeSets);
424453

@@ -456,17 +485,27 @@ void SwingSchedulerDAG::schedule() {
456485
SMSchedule Schedule(Pass.MF);
457486
Scheduled = schedulePipeline(Schedule);
458487

459-
if (!Scheduled)
488+
if (!Scheduled){
489+
LLVM_DEBUG(dbgs() << "No schedule found, return\n");
490+
NumFailNoSchedule++;
460491
return;
492+
}
461493

462494
unsigned numStages = Schedule.getMaxStageCount();
463495
// No need to generate pipeline if there are no overlapped iterations.
464-
if (numStages == 0)
496+
if (numStages == 0) {
497+
LLVM_DEBUG(
498+
dbgs() << "No overlapped iterations, no need to generate pipeline\n");
499+
NumFailZeroStage++;
465500
return;
466-
501+
}
467502
// Check that the maximum stage count is less than user-defined limit.
468-
if (SwpMaxStages > -1 && (int)numStages > SwpMaxStages)
503+
if (SwpMaxStages > -1 && (int)numStages > SwpMaxStages) {
504+
LLVM_DEBUG(dbgs() << "numStages:" << numStages << ">" << SwpMaxStages
505+
<< " : too many stages, abort\n");
506+
NumFailLargeMaxStage++;
469507
return;
508+
}
470509

471510
generatePipelinedLoop(Schedule);
472511
++NumPipelined;
@@ -926,6 +965,7 @@ struct FuncUnitSorter {
926965
/// instruction cannot be reserved in an existing DFA, we create a new one.
927966
unsigned SwingSchedulerDAG::calculateResMII() {
928967

968+
LLVM_DEBUG(dbgs() << "calculateResMII:\n");
929969
SmallVector<ResourceManager*, 8> Resources;
930970
MachineBasicBlock *MBB = Loop.getHeader();
931971
Resources.push_back(new ResourceManager(&MF.getSubtarget()));
@@ -956,6 +996,11 @@ unsigned SwingSchedulerDAG::calculateResMII() {
956996
unsigned ReservedCycles = 0;
957997
SmallVectorImpl<ResourceManager *>::iterator RI = Resources.begin();
958998
SmallVectorImpl<ResourceManager *>::iterator RE = Resources.end();
999+
LLVM_DEBUG({
1000+
dbgs() << "Trying to reserve resource for " << NumCycles
1001+
<< " cycles for \n";
1002+
MI->dump();
1003+
});
9591004
for (unsigned C = 0; C < NumCycles; ++C)
9601005
while (RI != RE) {
9611006
if ((*RI++)->canReserveResources(*MI)) {
@@ -968,15 +1013,21 @@ unsigned SwingSchedulerDAG::calculateResMII() {
9681013
--RI;
9691014
(*RI)->reserveResources(*MI);
9701015
}
1016+
1017+
LLVM_DEBUG(dbgs() << "ReservedCycles:" << ReservedCycles
1018+
<< ", NumCycles:" << NumCycles << "\n");
9711019
// Add new DFAs, if needed, to reserve resources.
9721020
for (unsigned C = ReservedCycles; C < NumCycles; ++C) {
1021+
LLVM_DEBUG(dbgs() << "NewResource created to reserve resources"
1022+
<< "\n");
9731023
ResourceManager *NewResource = new ResourceManager(&MF.getSubtarget());
9741024
assert(NewResource->canReserveResources(*MI) && "Reserve error.");
9751025
NewResource->reserveResources(*MI);
9761026
Resources.push_back(NewResource);
9771027
}
9781028
}
9791029
int Resmii = Resources.size();
1030+
LLVM_DEBUG(dbgs() << "Retrun Res MII:" << Resmii << "\n");
9801031
// Delete the memory for each of the DFAs that were created earlier.
9811032
for (ResourceManager *RI : Resources) {
9821033
ResourceManager *D = RI;
@@ -1862,8 +1913,11 @@ void SwingSchedulerDAG::computeNodeOrder(NodeSetType &NodeSets) {
18621913
/// Process the nodes in the computed order and create the pipelined schedule
18631914
/// of the instructions, if possible. Return true if a schedule is found.
18641915
bool SwingSchedulerDAG::schedulePipeline(SMSchedule &Schedule) {
1865-
if (NodeOrder.empty())
1916+
1917+
if (NodeOrder.empty()){
1918+
LLVM_DEBUG(dbgs() << "NodeOrder is empty! abort scheduling\n" );
18661919
return false;
1920+
}
18671921

18681922
bool scheduleFound = false;
18691923
unsigned II = 0;
@@ -1889,13 +1943,14 @@ bool SwingSchedulerDAG::schedulePipeline(SMSchedule &Schedule) {
18891943
Schedule.computeStart(SU, &EarlyStart, &LateStart, &SchedEnd, &SchedStart,
18901944
II, this);
18911945
LLVM_DEBUG({
1946+
dbgs() << "\n";
18921947
dbgs() << "Inst (" << SU->NodeNum << ") ";
18931948
SU->getInstr()->dump();
18941949
dbgs() << "\n";
18951950
});
18961951
LLVM_DEBUG({
1897-
dbgs() << "\tes: " << EarlyStart << " ls: " << LateStart
1898-
<< " me: " << SchedEnd << " ms: " << SchedStart << "\n";
1952+
dbgs() << format("\tes: %8x ls: %8x me: %8x ms: %8x\n", EarlyStart,
1953+
LateStart, SchedEnd, SchedStart);
18991954
});
19001955

19011956
if (EarlyStart > LateStart || SchedEnd < EarlyStart ||
@@ -3244,6 +3299,10 @@ void SwingSchedulerDAG::postprocessDAG() {
32443299
/// the relative values of StartCycle and EndCycle.
32453300
bool SMSchedule::insert(SUnit *SU, int StartCycle, int EndCycle, int II) {
32463301
bool forward = true;
3302+
LLVM_DEBUG({
3303+
dbgs() << "Trying to insert node between " << StartCycle << " and "
3304+
<< EndCycle << " II: " << II << "\n";
3305+
});
32473306
if (StartCycle > EndCycle)
32483307
forward = false;
32493308

0 commit comments

Comments
 (0)
Please sign in to comment.