Skip to content

Commit f40a790

Browse files
committed
[LV] Move selecting vectorization factor logic to LVP (NFC).
Split off from D143938. This moves the planning logic to select the vectorization factor to LoopVectorizationPlanner as a step towards only computing costs for individual VFs in LoopVectorizationCostModel and do planning in LVP. Reviewed By: Ayal Differential Revision: https://reviews.llvm.org/D150197
1 parent 7472f1d commit f40a790

File tree

2 files changed

+92
-89
lines changed

2 files changed

+92
-89
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZATIONPLANNER_H
2626

2727
#include "VPlan.h"
28+
#include "llvm/ADT/SmallSet.h"
2829
#include "llvm/Support/InstructionCost.h"
2930

3031
namespace llvm {
@@ -217,6 +218,16 @@ struct VectorizationFactor {
217218
}
218219
};
219220

221+
/// ElementCountComparator creates a total ordering for ElementCount
222+
/// for the purposes of using it in a set structure.
223+
struct ElementCountComparator {
224+
bool operator()(const ElementCount &LHS, const ElementCount &RHS) const {
225+
return std::make_tuple(LHS.isScalable(), LHS.getKnownMinValue()) <
226+
std::make_tuple(RHS.isScalable(), RHS.getKnownMinValue());
227+
}
228+
};
229+
using ElementCountSet = SmallSet<ElementCount, 16, ElementCountComparator>;
230+
220231
/// A class that represents two vectorization factors (initialized with 0 by
221232
/// default). One for fixed-width vectorization and one for scalable
222233
/// vectorization. This can be used by the vectorizer to choose from a range of
@@ -280,6 +291,9 @@ class LoopVectorizationPlanner {
280291

281292
SmallVector<VPlanPtr, 4> VPlans;
282293

294+
/// Profitable vector factors.
295+
SmallVector<VectorizationFactor, 8> ProfitableVFs;
296+
283297
/// A builder used to construct the current plan.
284298
VPBuilder Builder;
285299

@@ -342,6 +356,12 @@ class LoopVectorizationPlanner {
342356
/// Check if the number of runtime checks exceeds the threshold.
343357
bool requiresTooManyRuntimeChecks() const;
344358

359+
/// \return The most profitable vectorization factor and the cost of that VF
360+
/// for vectorizing the epilogue. Returns VectorizationFactor::Disabled if
361+
/// epilogue vectorization is not supported for the loop.
362+
VectorizationFactor
363+
selectEpilogueVectorizationFactor(const ElementCount MaxVF);
364+
345365
protected:
346366
/// Build VPlans for power-of-2 VF's between \p MinVF and \p MaxVF inclusive,
347367
/// according to the information gathered by Legal when it checked if it is
@@ -376,6 +396,20 @@ class LoopVectorizationPlanner {
376396
void adjustRecipesForReductions(VPBasicBlock *LatchVPBB, VPlanPtr &Plan,
377397
VPRecipeBuilder &RecipeBuilder,
378398
ElementCount MinVF);
399+
400+
/// \return The most profitable vectorization factor and the cost of that VF.
401+
/// This method checks every VF in \p CandidateVFs.
402+
VectorizationFactor
403+
selectVectorizationFactor(const ElementCountSet &CandidateVFs);
404+
405+
/// Returns true if the per-lane cost of VectorizationFactor A is lower than
406+
/// that of B.
407+
bool isMoreProfitable(const VectorizationFactor &A,
408+
const VectorizationFactor &B) const;
409+
410+
/// Determines if we have the infrastructure to vectorize the loop and its
411+
/// epilogue, assuming the main loop is vectorized by \p VF.
412+
bool isCandidateForEpilogueVectorization(const ElementCount VF) const;
379413
};
380414

381415
} // namespace llvm

0 commit comments

Comments
 (0)