Skip to content

Commit a0c0d43

Browse files
fhahnarcbbb
authored andcommitted
[VPlan] Compute costs for plans directly after construction.
Directly compute the cost of a VPlan after construction and track it together with a plan. This allows moving selecting the best VF to the planner. This seems to be a good fit anyways, and removes code from the cost-model that is not directly related to assigning costs to a specific plan/VF. Later this can be swapped out with computing the cost for a plan directly. This may help to simplify D142015. Differential Revision: https://reviews.llvm.org/D143938
1 parent 0b24436 commit a0c0d43

File tree

3 files changed

+213
-184
lines changed

3 files changed

+213
-184
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ class LoopVectorizationPlanner {
280280

281281
SmallVector<VPlanPtr, 4> VPlans;
282282

283+
/// Candidate VectorizationFactors for VPlans.
284+
DenseMap<VPlan *, SmallVector<VectorizationFactor>> VFCandidates;
285+
283286
/// A builder used to construct the current plan.
284287
VPBuilder Builder;
285288

@@ -336,6 +339,21 @@ class LoopVectorizationPlanner {
336339
/// Check if the number of runtime checks exceeds the threshold.
337340
bool requiresTooManyRuntimeChecks() const;
338341

342+
/// \return The most profitable vectorization factor and the cost of that VF.
343+
/// This method checks every VF in every plan in VPlans.
344+
VectorizationFactor selectVectorizationFactor();
345+
346+
/// \return The most profitable vectorization factor and the cost of that VF
347+
/// for vectorizing the epilogue. Returns VectorizationFactor::Disabled if
348+
/// epilogue vectorization is not supported for the loop.
349+
VectorizationFactor
350+
selectEpilogueVectorizationFactor(const ElementCount MaxVF);
351+
352+
/// Convenience function that returns the value of vscale_range iff
353+
/// vscale_range.min == vscale_range.max or otherwise returns the value
354+
/// returned by the corresponding TLI method.
355+
std::optional<unsigned> getVScaleForTuning() const;
356+
339357
protected:
340358
/// Build VPlans for power-of-2 VF's between \p MinVF and \p MaxVF inclusive,
341359
/// according to the information gathered by Legal when it checked if it is
@@ -370,6 +388,25 @@ class LoopVectorizationPlanner {
370388
void adjustRecipesForReductions(VPBasicBlock *LatchVPBB, VPlanPtr &Plan,
371389
VPRecipeBuilder &RecipeBuilder,
372390
ElementCount MinVF);
391+
392+
/// Returns true when Factor A is more profitable than Factor B.
393+
bool isMoreProfitable(const VectorizationFactor &A,
394+
const VectorizationFactor &B) const;
395+
396+
/// Determines if we have the infrastructure to vectorize loop \p L and its
397+
/// epilogue, assuming the main loop is vectorized by \p VF.
398+
bool isCandidateForEpilogueVectorization(const ElementCount VF) const;
399+
400+
/// Returns true if epilogue vectorization is considered profitable, and
401+
/// false otherwise.
402+
/// \p VF is the vectorization factor chosen for the original loop.
403+
bool isEpilogueVectorizationProfitable(const ElementCount VF) const;
404+
405+
ArrayRef<VectorizationFactor> getVFCandidatesFor(VPlan &Plan) const {
406+
auto I = VFCandidates.find(&Plan);
407+
assert(I != VFCandidates.end());
408+
return I->second;
409+
}
373410
};
374411

375412
} // namespace llvm

0 commit comments

Comments
 (0)