@@ -139,11 +139,30 @@ static const unsigned RuntimeMemoryCheckThreshold = 8;
139
139
// / Maximum simd width.
140
140
static const unsigned MaxVectorWidth = 64 ;
141
141
142
+ static cl::opt<unsigned > ForceTargetNumScalarRegs (
143
+ " force-target-num-scalar-regs" , cl::init(0 ), cl::Hidden,
144
+ cl::desc(" A flag that overrides the target's number of scalar registers." ));
145
+
146
+ static cl::opt<unsigned > ForceTargetNumVectorRegs (
147
+ " force-target-num-vector-regs" , cl::init(0 ), cl::Hidden,
148
+ cl::desc(" A flag that overrides the target's number of vector registers." ));
149
+
142
150
// / Maximum vectorization unroll count.
143
151
static const unsigned MaxUnrollFactor = 16 ;
144
152
145
- // / The cost of a loop that is considered 'small' by the unroller.
146
- static const unsigned SmallLoopCost = 20 ;
153
+ static cl::opt<unsigned > ForceTargetMaxScalarUnrollFactor (
154
+ " force-target-max-scalar-unroll" , cl::init(0 ), cl::Hidden,
155
+ cl::desc(" A flag that overrides the target's max unroll factor for scalar "
156
+ " loops." ));
157
+
158
+ static cl::opt<unsigned > ForceTargetMaxVectorUnrollFactor (
159
+ " force-target-max-vector-unroll" , cl::init(0 ), cl::Hidden,
160
+ cl::desc(" A flag that overrides the target's max unroll factor for "
161
+ " vectorized loops." ));
162
+
163
+ static cl::opt<unsigned > SmallLoopCost (
164
+ " small-loop-cost" , cl::init(20 ), cl::Hidden,
165
+ cl::desc(" The cost of a loop that is considered 'small' by the unroller." ));
147
166
148
167
namespace {
149
168
@@ -4966,6 +4985,14 @@ LoopVectorizationCostModel::selectUnrollFactor(bool OptForSize,
4966
4985
DEBUG (dbgs () << " LV: The target has " << TargetNumRegisters <<
4967
4986
" registers\n " );
4968
4987
4988
+ if (VF == 1 ) {
4989
+ if (ForceTargetNumScalarRegs.getNumOccurrences () > 0 )
4990
+ TargetNumRegisters = ForceTargetNumScalarRegs;
4991
+ } else {
4992
+ if (ForceTargetNumVectorRegs.getNumOccurrences () > 0 )
4993
+ TargetNumRegisters = ForceTargetNumVectorRegs;
4994
+ }
4995
+
4969
4996
LoopVectorizationCostModel::RegisterUsage R = calculateRegisterUsage ();
4970
4997
// We divide by these constants so assume that we have at least one
4971
4998
// instruction that uses at least one register.
@@ -4983,6 +5010,15 @@ LoopVectorizationCostModel::selectUnrollFactor(bool OptForSize,
4983
5010
// Clamp the unroll factor ranges to reasonable factors.
4984
5011
unsigned MaxUnrollSize = TTI.getMaximumUnrollFactor ();
4985
5012
5013
+ // Check if the user has overridden the unroll max.
5014
+ if (VF == 1 ) {
5015
+ if (ForceTargetMaxScalarUnrollFactor.getNumOccurrences () > 0 )
5016
+ MaxUnrollSize = ForceTargetMaxScalarUnrollFactor;
5017
+ } else {
5018
+ if (ForceTargetMaxVectorUnrollFactor.getNumOccurrences () > 0 )
5019
+ MaxUnrollSize = ForceTargetMaxVectorUnrollFactor;
5020
+ }
5021
+
4986
5022
// If we did not calculate the cost for VF (because the user selected the VF)
4987
5023
// then we calculate the cost of VF here.
4988
5024
if (LoopCost == 0 )
0 commit comments