[llvm] 1794046 - [VPlan] Move verifier to class to reduce need to pass via args. (NFC)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed May 29 21:02:02 PDT 2024
Author: Florian Hahn
Date: 2024-05-29T21:01:28-07:00
New Revision: 17940465364e0ad66fa364c5bef8abec4e34ac5b
URL: https://github.com/llvm/llvm-project/commit/17940465364e0ad66fa364c5bef8abec4e34ac5b
DIFF: https://github.com/llvm/llvm-project/commit/17940465364e0ad66fa364c5bef8abec4e34ac5b.diff
LOG: [VPlan] Move verifier to class to reduce need to pass via args. (NFC)
Move VPlan verification functions to avoid the need to pass VPDT across
multiple calls. This also allows easier extensions in the future.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
index 7ebdb914fb852..2fe487f972bb9 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
@@ -23,10 +23,41 @@
using namespace llvm;
-// Verify that phi-like recipes are at the beginning of \p VPBB, with no
-// other recipes in between. Also check that only header blocks contain
-// VPHeaderPHIRecipes.
-static bool verifyPhiRecipes(const VPBasicBlock *VPBB) {
+namespace {
+class VPlanVerifier {
+ const VPDominatorTree &VPDT;
+
+ // Verify that phi-like recipes are at the beginning of \p VPBB, with no
+ // other recipes in between. Also check that only header blocks contain
+ // VPHeaderPHIRecipes.
+ bool verifyPhiRecipes(const VPBasicBlock *VPBB);
+
+ bool verifyVPBasicBlock(const VPBasicBlock *VPBB);
+
+ bool verifyBlock(const VPBlockBase *VPB);
+
+ /// Helper function that verifies the CFG invariants of the VPBlockBases
+ /// within
+ /// \p Region. Checks in this function are generic for VPBlockBases. They are
+ /// not specific for VPBasicBlocks or VPRegionBlocks.
+ bool verifyBlocksInRegion(const VPRegionBlock *Region);
+
+ /// Verify the CFG invariants of VPRegionBlock \p Region and its nested
+ /// VPBlockBases. Do not recurse inside nested VPRegionBlocks.
+ bool verifyRegion(const VPRegionBlock *Region);
+
+ /// Verify the CFG invariants of VPRegionBlock \p Region and its nested
+ /// VPBlockBases. Recurse inside nested VPRegionBlocks.
+ bool verifyRegionRec(const VPRegionBlock *Region);
+
+public:
+ VPlanVerifier(VPDominatorTree &VPDT) : VPDT(VPDT) {}
+
+ bool verify(const VPlan &Plan);
+};
+} // namespace
+
+bool VPlanVerifier::verifyPhiRecipes(const VPBasicBlock *VPBB) {
auto RecipeI = VPBB->begin();
auto End = VPBB->end();
unsigned NumActiveLaneMaskPhiRecipes = 0;
@@ -80,8 +111,7 @@ static bool verifyPhiRecipes(const VPBasicBlock *VPBB) {
return true;
}
-static bool verifyVPBasicBlock(const VPBasicBlock *VPBB,
- const VPDominatorTree &VPDT) {
+bool VPlanVerifier::verifyVPBasicBlock(const VPBasicBlock *VPBB) {
if (!verifyPhiRecipes(VPBB))
return false;
@@ -133,7 +163,7 @@ static bool hasDuplicates(const SmallVectorImpl<VPBlockBase *> &VPBlockVec) {
return false;
}
-static bool verifyBlock(const VPBlockBase *VPB, const VPDominatorTree &VPDT) {
+bool VPlanVerifier::verifyBlock(const VPBlockBase *VPB) {
auto *VPBB = dyn_cast<VPBasicBlock>(VPB);
// Check block's condition bit.
if (VPB->getNumSuccessors() > 1 ||
@@ -193,14 +223,10 @@ static bool verifyBlock(const VPBlockBase *VPB, const VPDominatorTree &VPDT) {
return false;
}
}
- return !VPBB || verifyVPBasicBlock(VPBB, VPDT);
+ return !VPBB || verifyVPBasicBlock(VPBB);
}
-/// Helper function that verifies the CFG invariants of the VPBlockBases within
-/// \p Region. Checks in this function are generic for VPBlockBases. They are
-/// not specific for VPBasicBlocks or VPRegionBlocks.
-static bool verifyBlocksInRegion(const VPRegionBlock *Region,
- const VPDominatorTree &VPDT) {
+bool VPlanVerifier::verifyBlocksInRegion(const VPRegionBlock *Region) {
for (const VPBlockBase *VPB : vp_depth_first_shallow(Region->getEntry())) {
// Check block's parent.
if (VPB->getParent() != Region) {
@@ -208,16 +234,13 @@ static bool verifyBlocksInRegion(const VPRegionBlock *Region,
return false;
}
- if (!verifyBlock(VPB, VPDT))
+ if (!verifyBlock(VPB))
return false;
}
return true;
}
-/// Verify the CFG invariants of VPRegionBlock \p Region and its nested
-/// VPBlockBases. Do not recurse inside nested VPRegionBlocks.
-static bool verifyRegion(const VPRegionBlock *Region,
- const VPDominatorTree &VPDT) {
+bool VPlanVerifier::verifyRegion(const VPRegionBlock *Region) {
const VPBlockBase *Entry = Region->getEntry();
const VPBlockBase *Exiting = Region->getExiting();
@@ -231,33 +254,26 @@ static bool verifyRegion(const VPRegionBlock *Region,
return false;
}
- return verifyBlocksInRegion(Region, VPDT);
+ return verifyBlocksInRegion(Region);
}
-/// Verify the CFG invariants of VPRegionBlock \p Region and its nested
-/// VPBlockBases. Recurse inside nested VPRegionBlocks.
-static bool verifyRegionRec(const VPRegionBlock *Region,
- const VPDominatorTree &VPDT) {
+bool VPlanVerifier::verifyRegionRec(const VPRegionBlock *Region) {
// Recurse inside nested regions and check all blocks inside the region.
- return verifyRegion(Region, VPDT) &&
+ return verifyRegion(Region) &&
all_of(vp_depth_first_shallow(Region->getEntry()),
- [&VPDT](const VPBlockBase *VPB) {
+ [this](const VPBlockBase *VPB) {
const auto *SubRegion = dyn_cast<VPRegionBlock>(VPB);
- return !SubRegion || verifyRegionRec(SubRegion, VPDT);
+ return !SubRegion || verifyRegionRec(SubRegion);
});
}
-bool llvm::verifyVPlanIsValid(const VPlan &Plan) {
- VPDominatorTree VPDT;
- VPDT.recalculate(const_cast<VPlan &>(Plan));
-
- if (any_of(
- vp_depth_first_shallow(Plan.getEntry()),
- [&VPDT](const VPBlockBase *VPB) { return !verifyBlock(VPB, VPDT); }))
+bool VPlanVerifier::verify(const VPlan &Plan) {
+ if (any_of(vp_depth_first_shallow(Plan.getEntry()),
+ [this](const VPBlockBase *VPB) { return !verifyBlock(VPB); }))
return false;
const VPRegionBlock *TopRegion = Plan.getVectorLoopRegion();
- if (!verifyRegionRec(TopRegion, VPDT))
+ if (!verifyRegionRec(TopRegion))
return false;
if (TopRegion->getParent()) {
@@ -305,3 +321,10 @@ bool llvm::verifyVPlanIsValid(const VPlan &Plan) {
return true;
}
+
+bool llvm::verifyVPlanIsValid(const VPlan &Plan) {
+ VPDominatorTree VPDT;
+ VPDT.recalculate(const_cast<VPlan &>(Plan));
+ VPlanVerifier Verifier(VPDT);
+ return Verifier.verify(Plan);
+}
More information about the llvm-commits
mailing list