@@ -110,6 +110,7 @@ STATISTIC(NumFailZeroMII, "Pipeliner abort due to zero MII");
110110STATISTIC (NumFailNoSchedule, " Pipeliner abort due to no schedule found" );
111111STATISTIC (NumFailZeroStage, " Pipeliner abort due to zero stage" );
112112STATISTIC (NumFailLargeMaxStage, " Pipeliner abort due to too many stages" );
113+ STATISTIC (NumFailTooManyStores, " Pipeliner abort due to too many stores" );
113114
114115// / A command line option to turn software pipelining on or off.
115116static cl::opt<bool > EnableSWP (" enable-pipeliner" , cl::Hidden, cl::init(true ),
@@ -193,6 +194,13 @@ static cl::opt<bool>
193194 MVECodeGen (" pipeliner-mve-cg" , cl::Hidden, cl::init(false ),
194195 cl::desc(" Use the MVE code generator for software pipelining" ));
195196
197+ // / A command line argument to limit the number of store instructions in the
198+ // / target basic block.
199+ static cl::opt<unsigned > SwpMaxNumStores (
200+ " pipeliner-max-num-stores" ,
201+ cl::desc (" Maximum number of stores allwed in the target loop." ), cl::Hidden,
202+ cl::init(200 ));
203+
196204namespace llvm {
197205
198206// A command line option to enable the CopyToPhi DAG mutation.
@@ -544,6 +552,23 @@ bool MachinePipeliner::canPipelineLoop(MachineLoop &L) {
544552 return false ;
545553 }
546554
555+ unsigned NumStores = 0 ;
556+ for (MachineInstr &MI : *L.getHeader ())
557+ if (MI.mayStore ())
558+ ++NumStores;
559+ if (NumStores > SwpMaxNumStores) {
560+ LLVM_DEBUG (dbgs () << " Too many stores\n " );
561+ NumFailTooManyStores++;
562+ ORE->emit ([&]() {
563+ return MachineOptimizationRemarkAnalysis (DEBUG_TYPE, " canPipelineLoop" ,
564+ L.getStartLoc (), L.getHeader ())
565+ << " Too many store instructions in the loop: "
566+ << ore::NV (" NumStores" , NumStores) << " > "
567+ << ore::NV (" SwpMaxNumStores" , SwpMaxNumStores) << " ." ;
568+ });
569+ return false ;
570+ }
571+
547572 // Remove any subregisters from inputs to phi nodes.
548573 preprocessPhiNodes (*L.getHeader ());
549574 return true ;
0 commit comments