[llvm] [NFC][VPlan] Move `introduceMasksAndLinearize` into a `VPPredicator`'s method (PR #217483)
Andrei Elovikov via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 27 16:55:46 PDT 2026
https://github.com/eas updated https://github.com/llvm/llvm-project/pull/217483
>From a9ac7f89eace971adcf25c9bf3dc4e9ec30cd85b Mon Sep 17 00:00:00 2001
From: Andrei Elovikov <andrei.elovikov at sifive.com>
Date: Tue, 18 Aug 2026 13:29:21 -0700
Subject: [PATCH] [NFC][VPlan] Move `introduceMasksAndLinearize` into a
`VPPredicator`'s method
To reduce diff in the next PR.
AI-assisted.
---
.../Transforms/Vectorize/VPlanPredicator.cpp | 34 ++++++++++++-------
1 file changed, 21 insertions(+), 13 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp b/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp
index 3f35f14e876f2..c9e1eae12eb99 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp
@@ -25,6 +25,8 @@ using namespace VPlanPatternMatch;
namespace {
class VPPredicator {
+ VPlan &Plan;
+
/// Builder to construct recipes to compute masks.
VPBuilder Builder;
@@ -92,7 +94,8 @@ class VPPredicator {
VPValue *createBlendMaskForEdges(ArrayRef<EdgeTy> Edges, VPBasicBlock *VPBB);
public:
- VPPredicator(VPlan &Plan) : VPDT(Plan), VPPDT(Plan), VPPDF(VPPDT) {}
+ VPPredicator(VPlan &Plan)
+ : Plan(Plan), VPDT(Plan), VPPDT(Plan), VPPDF(VPPDT) {}
/// Returns the *entry* mask for \p VPBB.
VPValue *getBlockInMask(const VPBasicBlock *VPBB) const {
@@ -109,6 +112,9 @@ class VPPredicator {
/// Convert phi recipes in \p VPBB to VPBlendRecipes.
void convertPhisToBlends(VPBasicBlock *VPBB);
+
+ /// Perform predication and linearization of the Plan.
+ void run();
};
} // namespace
@@ -394,17 +400,12 @@ void VPPredicator::convertPhisToBlends(VPBasicBlock *VPBB) {
}
}
-void VPlanTransforms::introduceMasksAndLinearize(VPlan &Plan) {
- // Nested loop regions (outer-loop vectorization) are not supported yet.
- if (Plan.isOuterLoop())
- return;
- VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
- // Scan the body of the loop in a topological order to visit each basic block
- // after having visited its predecessor basic blocks.
- VPBasicBlock *Header = LoopRegion->getEntryBasicBlock();
+void VPPredicator::run() {
+ VPBasicBlock *Header = Plan.getVectorLoopRegion()->getEntryBasicBlock();
+ // Scan the body of the loop in a topological order to visit each basic
+ // block after having visited its predecessor basic blocks.
ReversePostOrderTraversal<VPBlockShallowTraversalWrapper<VPBlockBase *>> RPOT(
Header);
- VPPredicator Predicator(Plan);
for (VPBlockBase *VPB : RPOT) {
// Non-outer regions with VPBBs only are supported at the moment.
auto *VPBB = cast<VPBasicBlock>(VPB);
@@ -412,9 +413,9 @@ void VPlanTransforms::introduceMasksAndLinearize(VPlan &Plan) {
// convert all phi recipes of VPBB to blend recipes unless VPBB is the
// header.
if (VPBB != Header)
- Predicator.createBlockInMask(VPBB);
+ createBlockInMask(VPBB);
- VPValue *BlockMask = Predicator.getBlockInMask(VPBB);
+ VPValue *BlockMask = getBlockInMask(VPBB);
if (!BlockMask)
continue;
@@ -427,7 +428,7 @@ void VPlanTransforms::introduceMasksAndLinearize(VPlan &Plan) {
for (VPBlockBase *VPBB : reverse(RPOT))
if (VPBB != Header)
- Predicator.convertPhisToBlends(cast<VPBasicBlock>(VPBB));
+ convertPhisToBlends(cast<VPBasicBlock>(VPBB));
// Linearize the blocks of the loop into one serial chain.
VPBlockBase *PrevVPBB = nullptr;
@@ -446,3 +447,10 @@ void VPlanTransforms::introduceMasksAndLinearize(VPlan &Plan) {
PrevVPBB = VPBB;
}
}
+
+void VPlanTransforms::introduceMasksAndLinearize(VPlan &Plan) {
+ // Nested loop regions (outer-loop vectorization) are not supported yet.
+ if (Plan.isOuterLoop())
+ return;
+ VPPredicator(Plan).run();
+}
More information about the llvm-commits
mailing list