@@ -96,6 +96,14 @@ using namespace llvm;
96
96
STATISTIC (NumTrytoPipeline, " Number of loops that we attempt to pipeline" );
97
97
STATISTIC (NumPipelined, " Number of loops software pipelined" );
98
98
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" );
99
107
100
108
// / A command line option to turn software pipelining on or off.
101
109
static cl::opt<bool > EnableSWP (" enable-pipeliner" , cl::Hidden, cl::init(true ),
@@ -289,16 +297,28 @@ bool MachinePipeliner::canPipelineLoop(MachineLoop &L) {
289
297
LI.TBB = nullptr ;
290
298
LI.FBB = nullptr ;
291
299
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++;
293
304
return false ;
305
+ }
294
306
295
307
LI.LoopInductionVar = nullptr ;
296
308
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++;
298
313
return false ;
314
+ }
299
315
300
- if (!L.getLoopPreheader ())
316
+ if (!L.getLoopPreheader ()) {
317
+ LLVM_DEBUG (
318
+ dbgs () << " Preheader not found, can NOT pipeline current Loop\n " );
319
+ NumFailPreheader++;
301
320
return false ;
321
+ }
302
322
303
323
// Remove any subregisters from inputs to phi nodes.
304
324
preprocessPhiNodes (*L.getHeader ());
@@ -413,12 +433,21 @@ void SwingSchedulerDAG::schedule() {
413
433
<< " (rec=" << RecMII << " , res=" << ResMII << " )\n " );
414
434
415
435
// 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++;
417
441
return ;
442
+ }
418
443
419
444
// 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++;
421
449
return ;
450
+ }
422
451
423
452
computeNodeFunctions (NodeSets);
424
453
@@ -456,17 +485,27 @@ void SwingSchedulerDAG::schedule() {
456
485
SMSchedule Schedule (Pass.MF );
457
486
Scheduled = schedulePipeline (Schedule);
458
487
459
- if (!Scheduled)
488
+ if (!Scheduled){
489
+ LLVM_DEBUG (dbgs () << " No schedule found, return\n " );
490
+ NumFailNoSchedule++;
460
491
return ;
492
+ }
461
493
462
494
unsigned numStages = Schedule.getMaxStageCount ();
463
495
// 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++;
465
500
return ;
466
-
501
+ }
467
502
// 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++;
469
507
return ;
508
+ }
470
509
471
510
generatePipelinedLoop (Schedule);
472
511
++NumPipelined;
@@ -926,6 +965,7 @@ struct FuncUnitSorter {
926
965
// / instruction cannot be reserved in an existing DFA, we create a new one.
927
966
unsigned SwingSchedulerDAG::calculateResMII () {
928
967
968
+ LLVM_DEBUG (dbgs () << " calculateResMII:\n " );
929
969
SmallVector<ResourceManager*, 8 > Resources;
930
970
MachineBasicBlock *MBB = Loop.getHeader ();
931
971
Resources.push_back (new ResourceManager (&MF.getSubtarget ()));
@@ -956,6 +996,11 @@ unsigned SwingSchedulerDAG::calculateResMII() {
956
996
unsigned ReservedCycles = 0 ;
957
997
SmallVectorImpl<ResourceManager *>::iterator RI = Resources.begin ();
958
998
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
+ });
959
1004
for (unsigned C = 0 ; C < NumCycles; ++C)
960
1005
while (RI != RE) {
961
1006
if ((*RI++)->canReserveResources (*MI)) {
@@ -968,15 +1013,21 @@ unsigned SwingSchedulerDAG::calculateResMII() {
968
1013
--RI;
969
1014
(*RI)->reserveResources (*MI);
970
1015
}
1016
+
1017
+ LLVM_DEBUG (dbgs () << " ReservedCycles:" << ReservedCycles
1018
+ << " , NumCycles:" << NumCycles << " \n " );
971
1019
// Add new DFAs, if needed, to reserve resources.
972
1020
for (unsigned C = ReservedCycles; C < NumCycles; ++C) {
1021
+ LLVM_DEBUG (dbgs () << " NewResource created to reserve resources"
1022
+ << " \n " );
973
1023
ResourceManager *NewResource = new ResourceManager (&MF.getSubtarget ());
974
1024
assert (NewResource->canReserveResources (*MI) && " Reserve error." );
975
1025
NewResource->reserveResources (*MI);
976
1026
Resources.push_back (NewResource);
977
1027
}
978
1028
}
979
1029
int Resmii = Resources.size ();
1030
+ LLVM_DEBUG (dbgs () << " Retrun Res MII:" << Resmii << " \n " );
980
1031
// Delete the memory for each of the DFAs that were created earlier.
981
1032
for (ResourceManager *RI : Resources) {
982
1033
ResourceManager *D = RI;
@@ -1862,8 +1913,11 @@ void SwingSchedulerDAG::computeNodeOrder(NodeSetType &NodeSets) {
1862
1913
// / Process the nodes in the computed order and create the pipelined schedule
1863
1914
// / of the instructions, if possible. Return true if a schedule is found.
1864
1915
bool SwingSchedulerDAG::schedulePipeline (SMSchedule &Schedule) {
1865
- if (NodeOrder.empty ())
1916
+
1917
+ if (NodeOrder.empty ()){
1918
+ LLVM_DEBUG (dbgs () << " NodeOrder is empty! abort scheduling\n " );
1866
1919
return false ;
1920
+ }
1867
1921
1868
1922
bool scheduleFound = false ;
1869
1923
unsigned II = 0 ;
@@ -1889,13 +1943,14 @@ bool SwingSchedulerDAG::schedulePipeline(SMSchedule &Schedule) {
1889
1943
Schedule.computeStart (SU, &EarlyStart, &LateStart, &SchedEnd, &SchedStart,
1890
1944
II, this );
1891
1945
LLVM_DEBUG ({
1946
+ dbgs () << " \n " ;
1892
1947
dbgs () << " Inst (" << SU->NodeNum << " ) " ;
1893
1948
SU->getInstr ()->dump ();
1894
1949
dbgs () << " \n " ;
1895
1950
});
1896
1951
LLVM_DEBUG ({
1897
- dbgs () << " \t es: " << EarlyStart << " ls: " << LateStart
1898
- << " me: " << SchedEnd << " ms: " << SchedStart << " \n " ;
1952
+ dbgs () << format ( " \t es: %8x ls: %8x me: %8x ms: %8x \n " , EarlyStart,
1953
+ LateStart, SchedEnd, SchedStart) ;
1899
1954
});
1900
1955
1901
1956
if (EarlyStart > LateStart || SchedEnd < EarlyStart ||
@@ -3244,6 +3299,10 @@ void SwingSchedulerDAG::postprocessDAG() {
3244
3299
// / the relative values of StartCycle and EndCycle.
3245
3300
bool SMSchedule::insert (SUnit *SU, int StartCycle, int EndCycle, int II) {
3246
3301
bool forward = true ;
3302
+ LLVM_DEBUG ({
3303
+ dbgs () << " Trying to insert node between " << StartCycle << " and "
3304
+ << EndCycle << " II: " << II << " \n " ;
3305
+ });
3247
3306
if (StartCycle > EndCycle)
3248
3307
forward = false ;
3249
3308
0 commit comments