Skip to content

Commit cd60d10

Browse files
committed
[VPlan] Move some LoopVectorizationPlanner helpers to VPlan.cpp (NFC).
Members not requiring access to LoopVectorizationLegality or LoopVectorizationCostModel can safely be moved out of the very large LoopVectorization.cpp and are more accurately placed in VPlan.cpp
1 parent 5795f9e commit cd60d10

File tree

2 files changed

+59
-58
lines changed

2 files changed

+59
-58
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,6 @@ cl::opt<bool> llvm::EnableLoopVectorization(
380380
"vectorize-loops", cl::init(true), cl::Hidden,
381381
cl::desc("Run the Loop vectorization passes"));
382382

383-
static cl::opt<bool> PrintVPlansInDotFormat(
384-
"vplan-print-in-dot-format", cl::Hidden,
385-
cl::desc("Use dot format instead of plain text when dumping VPlans"));
386-
387383
static cl::opt<cl::boolOrDefault> ForceSafeDivisor(
388384
"force-widen-divrem-via-safe-divisor", cl::Hidden,
389385
cl::desc(
@@ -7302,19 +7298,6 @@ ElementCount LoopVectorizationPlanner::getBestVF() {
73027298
return BestFactor.Width;
73037299
}
73047300

7305-
VPlan &LoopVectorizationPlanner::getBestPlanFor(ElementCount VF) const {
7306-
assert(count_if(VPlans,
7307-
[VF](const VPlanPtr &Plan) { return Plan->hasVF(VF); }) ==
7308-
1 &&
7309-
"Best VF has not a single VPlan.");
7310-
7311-
for (const VPlanPtr &Plan : VPlans) {
7312-
if (Plan->hasVF(VF))
7313-
return *Plan.get();
7314-
}
7315-
llvm_unreachable("No plan found!");
7316-
}
7317-
73187301
static void AddRuntimeUnrollDisableMetaData(Loop *L) {
73197302
SmallVector<Metadata *, 4> MDs;
73207303
// Reserve first location for self reference to the LoopID metadata node.
@@ -7559,16 +7542,6 @@ LoopVectorizationPlanner::executePlan(
75597542
return {State.ExpandedSCEVs, ReductionResumeValues};
75607543
}
75617544

7562-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
7563-
void LoopVectorizationPlanner::printPlans(raw_ostream &O) {
7564-
for (const auto &Plan : VPlans)
7565-
if (PrintVPlansInDotFormat)
7566-
Plan->printDOT(O);
7567-
else
7568-
Plan->print(O);
7569-
}
7570-
#endif
7571-
75727545
//===--------------------------------------------------------------------===//
75737546
// EpilogueVectorizerMainLoop
75747547
//===--------------------------------------------------------------------===//
@@ -7858,37 +7831,6 @@ void EpilogueVectorizerEpilogueLoop::printDebugTracesAtEnd() {
78587831
});
78597832
}
78607833

7861-
bool LoopVectorizationPlanner::getDecisionAndClampRange(
7862-
const std::function<bool(ElementCount)> &Predicate, VFRange &Range) {
7863-
assert(!Range.isEmpty() && "Trying to test an empty VF range.");
7864-
bool PredicateAtRangeStart = Predicate(Range.Start);
7865-
7866-
for (ElementCount TmpVF : VFRange(Range.Start * 2, Range.End))
7867-
if (Predicate(TmpVF) != PredicateAtRangeStart) {
7868-
Range.End = TmpVF;
7869-
break;
7870-
}
7871-
7872-
return PredicateAtRangeStart;
7873-
}
7874-
7875-
/// Build VPlans for the full range of feasible VF's = {\p MinVF, 2 * \p MinVF,
7876-
/// 4 * \p MinVF, ..., \p MaxVF} by repeatedly building a VPlan for a sub-range
7877-
/// of VF's starting at a given VF and extending it as much as possible. Each
7878-
/// vectorization decision can potentially shorten this sub-range during
7879-
/// buildVPlan().
7880-
void LoopVectorizationPlanner::buildVPlans(ElementCount MinVF,
7881-
ElementCount MaxVF) {
7882-
auto MaxVFTimes2 = MaxVF * 2;
7883-
for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) {
7884-
VFRange SubRange = {VF, MaxVFTimes2};
7885-
auto Plan = buildVPlan(SubRange);
7886-
VPlanTransforms::optimize(*Plan, *PSE.getSE());
7887-
VPlans.push_back(std::move(Plan));
7888-
VF = SubRange.End;
7889-
}
7890-
}
7891-
78927834
iterator_range<mapped_iterator<Use *, std::function<VPValue *(Value *)>>>
78937835
VPRecipeBuilder::mapToVPValues(User::op_range Operands) {
78947836
std::function<VPValue *(Value *)> Fn = [this](Value *Op) {

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "VPlanCFG.h"
2222
#include "VPlanDominatorTree.h"
2323
#include "VPlanPatternMatch.h"
24+
#include "VPlanTransforms.h"
2425
#include "llvm/ADT/PostOrderIterator.h"
2526
#include "llvm/ADT/STLExtras.h"
2627
#include "llvm/ADT/SmallVector.h"
@@ -55,6 +56,10 @@ namespace llvm {
5556
extern cl::opt<bool> EnableVPlanNativePath;
5657
}
5758

59+
static cl::opt<bool> PrintVPlansInDotFormat(
60+
"vplan-print-in-dot-format", cl::Hidden,
61+
cl::desc("Use dot format instead of plain text when dumping VPlans"));
62+
5863
#define DEBUG_TYPE "vplan"
5964

6065
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
@@ -1643,3 +1648,57 @@ bool vputils::isHeaderMask(const VPValue *V, VPlan &Plan) {
16431648
return match(V, m_Binary<Instruction::ICmp>(m_VPValue(A), m_VPValue(B))) &&
16441649
IsWideCanonicalIV(A) && B == Plan.getOrCreateBackedgeTakenCount();
16451650
}
1651+
1652+
bool LoopVectorizationPlanner::getDecisionAndClampRange(
1653+
const std::function<bool(ElementCount)> &Predicate, VFRange &Range) {
1654+
assert(!Range.isEmpty() && "Trying to test an empty VF range.");
1655+
bool PredicateAtRangeStart = Predicate(Range.Start);
1656+
1657+
for (ElementCount TmpVF : VFRange(Range.Start * 2, Range.End))
1658+
if (Predicate(TmpVF) != PredicateAtRangeStart) {
1659+
Range.End = TmpVF;
1660+
break;
1661+
}
1662+
1663+
return PredicateAtRangeStart;
1664+
}
1665+
1666+
/// Build VPlans for the full range of feasible VF's = {\p MinVF, 2 * \p MinVF,
1667+
/// 4 * \p MinVF, ..., \p MaxVF} by repeatedly building a VPlan for a sub-range
1668+
/// of VF's starting at a given VF and extending it as much as possible. Each
1669+
/// vectorization decision can potentially shorten this sub-range during
1670+
/// buildVPlan().
1671+
void LoopVectorizationPlanner::buildVPlans(ElementCount MinVF,
1672+
ElementCount MaxVF) {
1673+
auto MaxVFTimes2 = MaxVF * 2;
1674+
for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) {
1675+
VFRange SubRange = {VF, MaxVFTimes2};
1676+
auto Plan = buildVPlan(SubRange);
1677+
VPlanTransforms::optimize(*Plan, *PSE.getSE());
1678+
VPlans.push_back(std::move(Plan));
1679+
VF = SubRange.End;
1680+
}
1681+
}
1682+
1683+
VPlan &LoopVectorizationPlanner::getBestPlanFor(ElementCount VF) const {
1684+
assert(count_if(VPlans,
1685+
[VF](const VPlanPtr &Plan) { return Plan->hasVF(VF); }) ==
1686+
1 &&
1687+
"Best VF has not a single VPlan.");
1688+
1689+
for (const VPlanPtr &Plan : VPlans) {
1690+
if (Plan->hasVF(VF))
1691+
return *Plan.get();
1692+
}
1693+
llvm_unreachable("No plan found!");
1694+
}
1695+
1696+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1697+
void LoopVectorizationPlanner::printPlans(raw_ostream &O) {
1698+
for (const auto &Plan : VPlans)
1699+
if (PrintVPlansInDotFormat)
1700+
Plan->printDOT(O);
1701+
else
1702+
Plan->print(O);
1703+
}
1704+
#endif

0 commit comments

Comments
 (0)