aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2024-08-19 09:58:46 +0100
committerFlorian Hahn <flo@fhahn.com>2024-08-19 09:58:46 +0100
commitcd60d10a10732154d95892219f70f0784f5a2249 (patch)
treeade2b0bab068273eb7088b18482859a9395ef66c
parent5795f9e27390fe5c322853476b3c9ba8376e8541 (diff)
downloadllvm-cd60d10a10732154d95892219f70f0784f5a2249.zip
llvm-cd60d10a10732154d95892219f70f0784f5a2249.tar.gz
llvm-cd60d10a10732154d95892219f70f0784f5a2249.tar.bz2
[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
-rw-r--r--llvm/lib/Transforms/Vectorize/LoopVectorize.cpp58
-rw-r--r--llvm/lib/Transforms/Vectorize/VPlan.cpp59
2 files changed, 59 insertions, 58 deletions
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 55c0ba3..e4307bf 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -380,10 +380,6 @@ cl::opt<bool> llvm::EnableLoopVectorization(
"vectorize-loops", cl::init(true), cl::Hidden,
cl::desc("Run the Loop vectorization passes"));
-static cl::opt<bool> PrintVPlansInDotFormat(
- "vplan-print-in-dot-format", cl::Hidden,
- cl::desc("Use dot format instead of plain text when dumping VPlans"));
-
static cl::opt<cl::boolOrDefault> ForceSafeDivisor(
"force-widen-divrem-via-safe-divisor", cl::Hidden,
cl::desc(
@@ -7302,19 +7298,6 @@ ElementCount LoopVectorizationPlanner::getBestVF() {
return BestFactor.Width;
}
-VPlan &LoopVectorizationPlanner::getBestPlanFor(ElementCount VF) const {
- assert(count_if(VPlans,
- [VF](const VPlanPtr &Plan) { return Plan->hasVF(VF); }) ==
- 1 &&
- "Best VF has not a single VPlan.");
-
- for (const VPlanPtr &Plan : VPlans) {
- if (Plan->hasVF(VF))
- return *Plan.get();
- }
- llvm_unreachable("No plan found!");
-}
-
static void AddRuntimeUnrollDisableMetaData(Loop *L) {
SmallVector<Metadata *, 4> MDs;
// Reserve first location for self reference to the LoopID metadata node.
@@ -7559,16 +7542,6 @@ LoopVectorizationPlanner::executePlan(
return {State.ExpandedSCEVs, ReductionResumeValues};
}
-#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
-void LoopVectorizationPlanner::printPlans(raw_ostream &O) {
- for (const auto &Plan : VPlans)
- if (PrintVPlansInDotFormat)
- Plan->printDOT(O);
- else
- Plan->print(O);
-}
-#endif
-
//===--------------------------------------------------------------------===//
// EpilogueVectorizerMainLoop
//===--------------------------------------------------------------------===//
@@ -7858,37 +7831,6 @@ void EpilogueVectorizerEpilogueLoop::printDebugTracesAtEnd() {
});
}
-bool LoopVectorizationPlanner::getDecisionAndClampRange(
- const std::function<bool(ElementCount)> &Predicate, VFRange &Range) {
- assert(!Range.isEmpty() && "Trying to test an empty VF range.");
- bool PredicateAtRangeStart = Predicate(Range.Start);
-
- for (ElementCount TmpVF : VFRange(Range.Start * 2, Range.End))
- if (Predicate(TmpVF) != PredicateAtRangeStart) {
- Range.End = TmpVF;
- break;
- }
-
- return PredicateAtRangeStart;
-}
-
-/// Build VPlans for the full range of feasible VF's = {\p MinVF, 2 * \p MinVF,
-/// 4 * \p MinVF, ..., \p MaxVF} by repeatedly building a VPlan for a sub-range
-/// of VF's starting at a given VF and extending it as much as possible. Each
-/// vectorization decision can potentially shorten this sub-range during
-/// buildVPlan().
-void LoopVectorizationPlanner::buildVPlans(ElementCount MinVF,
- ElementCount MaxVF) {
- auto MaxVFTimes2 = MaxVF * 2;
- for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) {
- VFRange SubRange = {VF, MaxVFTimes2};
- auto Plan = buildVPlan(SubRange);
- VPlanTransforms::optimize(*Plan, *PSE.getSE());
- VPlans.push_back(std::move(Plan));
- VF = SubRange.End;
- }
-}
-
iterator_range<mapped_iterator<Use *, std::function<VPValue *(Value *)>>>
VPRecipeBuilder::mapToVPValues(User::op_range Operands) {
std::function<VPValue *(Value *)> Fn = [this](Value *Op) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index 2a9e4e1..fe5edce 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -21,6 +21,7 @@
#include "VPlanCFG.h"
#include "VPlanDominatorTree.h"
#include "VPlanPatternMatch.h"
+#include "VPlanTransforms.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
@@ -55,6 +56,10 @@ namespace llvm {
extern cl::opt<bool> EnableVPlanNativePath;
}
+static cl::opt<bool> PrintVPlansInDotFormat(
+ "vplan-print-in-dot-format", cl::Hidden,
+ cl::desc("Use dot format instead of plain text when dumping VPlans"));
+
#define DEBUG_TYPE "vplan"
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
@@ -1643,3 +1648,57 @@ bool vputils::isHeaderMask(const VPValue *V, VPlan &Plan) {
return match(V, m_Binary<Instruction::ICmp>(m_VPValue(A), m_VPValue(B))) &&
IsWideCanonicalIV(A) && B == Plan.getOrCreateBackedgeTakenCount();
}
+
+bool LoopVectorizationPlanner::getDecisionAndClampRange(
+ const std::function<bool(ElementCount)> &Predicate, VFRange &Range) {
+ assert(!Range.isEmpty() && "Trying to test an empty VF range.");
+ bool PredicateAtRangeStart = Predicate(Range.Start);
+
+ for (ElementCount TmpVF : VFRange(Range.Start * 2, Range.End))
+ if (Predicate(TmpVF) != PredicateAtRangeStart) {
+ Range.End = TmpVF;
+ break;
+ }
+
+ return PredicateAtRangeStart;
+}
+
+/// Build VPlans for the full range of feasible VF's = {\p MinVF, 2 * \p MinVF,
+/// 4 * \p MinVF, ..., \p MaxVF} by repeatedly building a VPlan for a sub-range
+/// of VF's starting at a given VF and extending it as much as possible. Each
+/// vectorization decision can potentially shorten this sub-range during
+/// buildVPlan().
+void LoopVectorizationPlanner::buildVPlans(ElementCount MinVF,
+ ElementCount MaxVF) {
+ auto MaxVFTimes2 = MaxVF * 2;
+ for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) {
+ VFRange SubRange = {VF, MaxVFTimes2};
+ auto Plan = buildVPlan(SubRange);
+ VPlanTransforms::optimize(*Plan, *PSE.getSE());
+ VPlans.push_back(std::move(Plan));
+ VF = SubRange.End;
+ }
+}
+
+VPlan &LoopVectorizationPlanner::getBestPlanFor(ElementCount VF) const {
+ assert(count_if(VPlans,
+ [VF](const VPlanPtr &Plan) { return Plan->hasVF(VF); }) ==
+ 1 &&
+ "Best VF has not a single VPlan.");
+
+ for (const VPlanPtr &Plan : VPlans) {
+ if (Plan->hasVF(VF))
+ return *Plan.get();
+ }
+ llvm_unreachable("No plan found!");
+}
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+void LoopVectorizationPlanner::printPlans(raw_ostream &O) {
+ for (const auto &Plan : VPlans)
+ if (PrintVPlansInDotFormat)
+ Plan->printDOT(O);
+ else
+ Plan->print(O);
+}
+#endif