Skip to content

Commit 0fe0e7c

Browse files
author
git apple-llvm automerger
committed
Merge commit 'ffa6b0c365ec' from llvm.org/release/21.x into stable/21.x
2 parents 16e29e4 + ffa6b0c commit 0fe0e7c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

llvm/lib/CodeGen/MachinePipeliner.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ STATISTIC(NumFailZeroMII, "Pipeliner abort due to zero MII");
110110
STATISTIC(NumFailNoSchedule, "Pipeliner abort due to no schedule found");
111111
STATISTIC(NumFailZeroStage, "Pipeliner abort due to zero stage");
112112
STATISTIC(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.
115116
static 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+
196204
namespace 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

Comments
 (0)