[llvm] cd60d10 - [VPlan] Move some LoopVectorizationPlanner helpers to VPlan.cpp (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 19 01:59:11 PDT 2024
Author: Florian Hahn
Date: 2024-08-19T09:58:46+01:00
New Revision: cd60d10a10732154d95892219f70f0784f5a2249
URL: https://github.com/llvm/llvm-project/commit/cd60d10a10732154d95892219f70f0784f5a2249
DIFF: https://github.com/llvm/llvm-project/commit/cd60d10a10732154d95892219f70f0784f5a2249.diff
LOG: [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
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/lib/Transforms/Vectorize/VPlan.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 55c0ba3dd8f9bc..e4307bf32804f7 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 2a9e4e12190cdc..fe5edcedff54ab 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
More information about the llvm-commits
mailing list