[llvm] [LV] Add VPlan planning context and result (PR #226415)

Kiran Chandramohan via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 06:02:13 PDT 2026


================
@@ -833,6 +833,52 @@ class VFSelectionContext {
   }
 };
 
+/// The plans and profitability results produced by a completed planning run.
+class VPlanPlanningResult {
+  friend class LoopVectorizationPlanner;
+
+  SmallVector<VPlanPtr, 4> VPlans;
+  SmallVector<VectorizationFactor, 8> ProfitableVFs;
+
+public:
+  VPlanPlanningResult() = default;
+  VPlanPlanningResult(VPlanPlanningResult &&) = default;
+  VPlanPlanningResult &operator=(VPlanPlanningResult &&) = default;
+  VPlanPlanningResult(const VPlanPlanningResult &) = delete;
+  VPlanPlanningResult &operator=(const VPlanPlanningResult &) = delete;
+
+  /// Return the VPlan for \p VF. At the moment, there is always a single VPlan
+  /// for each VF.
+  VPlan &getPlanFor(ElementCount VF) const;
+
+  /// Return true if there is a plan for \p VF.
+  bool hasPlanWithVF(ElementCount VF) const;
+};
+
+/// State shared by VPlan construction and cost-modeling for one planning run.
+///
+/// Keeping the cost model and the plans whose decisions it produced in the
+/// same context makes the dependency explicit when multiple cost models are
+/// used for the same loop. Finalizing the context destroys the cost model and
+/// returns the plans and profitability results needed by code generation.
+class VPlanPlanningContext {
----------------
kiranchandramohan wrote:

A simple change would be for VPlanPlanningContext to contain a `VFSelectionContext`.

Otherwise, we probably have to break up VFSelectionContext. It contains Loop-wide inputs like TTI, Legal, TheLoop, F, PSE, DB, ORE, Hints, CostKind, OptForSize. Things that change per run like ElementTypesInLoop, MaxPermissibleVFWithoutMaxBW, MaxSafeElements. We could reduce it to only contain things that change per run and have the rest in VPlanPlanningContext or may be even in LoopVectorizationPlanner.



https://github.com/llvm/llvm-project/pull/226415


More information about the llvm-commits mailing list