From 2c9d21a2a3593029213df9492b163195e631e491 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Fri, 28 Apr 2023 12:29:05 +0100 Subject: [PATCH] [VPlan] Turn Plan entry node into VPBasicBlock (NFCI). The entry to the plan is the preheader of the vector loop and guaranteed to be a VPBasicBlock. Make sure this is the case by adjusting the type. Reviewed By: Ayal Differential Revision: https://reviews.llvm.org/D149005 --- llvm/lib/Transforms/Vectorize/VPlan.cpp | 2 +- llvm/lib/Transforms/Vectorize/VPlan.h | 15 ++++++++------- .../unittests/Transforms/Vectorize/VPDomTreeTest.cpp | 12 ++++++++++-- llvm/unittests/Transforms/Vectorize/VPlanTest.cpp | 20 +++++--------------- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp index d0ffc2d..9e8ce60 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -1133,7 +1133,7 @@ VPValue *vputils::getOrCreateVPValueForSCEVExpr(VPlan &Plan, const SCEV *Expr, if (auto *E = dyn_cast(Expr)) return Plan.getVPValueOrAddLiveIn(E->getValue()); - VPBasicBlock *Preheader = Plan.getEntry()->getEntryBasicBlock(); + VPBasicBlock *Preheader = Plan.getEntry(); VPExpandSCEVRecipe *Step = new VPExpandSCEVRecipe(Expr, SE); Preheader->appendRecipe(Step); return Step; diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index f4cd4d8..45fc504 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -2209,13 +2209,14 @@ public: /// to produce efficient output IR, including which branches, basic-blocks and /// output IR instructions to generate, and their cost. VPlan holds a /// Hierarchical-CFG of VPBasicBlocks and VPRegionBlocks rooted at an Entry -/// VPBlock. +/// VPBasicBlock. class VPlan { friend class VPlanPrinter; friend class VPSlotTracker; - /// Hold the single entry to the Hierarchical CFG of the VPlan. - VPBlockBase *Entry; + /// Hold the single entry to the Hierarchical CFG of the VPlan, i.e. the + /// preheader of the vector loop. + VPBasicBlock *Entry; /// Holds the VFs applicable to this VPlan. SmallSetVector VFs; @@ -2254,7 +2255,7 @@ class VPlan { MapVector LiveOuts; public: - VPlan(VPBlockBase *Entry = nullptr) : Entry(Entry) { + VPlan(VPBasicBlock *Entry = nullptr) : Entry(Entry) { if (Entry) Entry->setPlan(this); } @@ -2269,10 +2270,10 @@ public: /// Generate the IR code for this VPlan. void execute(VPTransformState *State); - VPBlockBase *getEntry() { return Entry; } - const VPBlockBase *getEntry() const { return Entry; } + VPBasicBlock *getEntry() { return Entry; } + const VPBasicBlock *getEntry() const { return Entry; } - VPBlockBase *setEntry(VPBlockBase *Block) { + VPBasicBlock *setEntry(VPBasicBlock *Block) { Entry = Block; Block->setPlan(this); return Entry; diff --git a/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp b/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp index d336e17..1e5d60b 100644 --- a/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp +++ b/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp @@ -15,6 +15,8 @@ namespace llvm { namespace { TEST(VPDominatorTreeTest, DominanceNoRegionsTest) { + // VPBB0 + // | // R1 { // VPBB1 // / \ @@ -22,6 +24,7 @@ TEST(VPDominatorTreeTest, DominanceNoRegionsTest) { // \ / // VPBB4 // } + VPBasicBlock *VPBB0 = new VPBasicBlock("VPBB0"); VPBasicBlock *VPBB1 = new VPBasicBlock("VPBB1"); VPBasicBlock *VPBB2 = new VPBasicBlock("VPBB2"); VPBasicBlock *VPBB3 = new VPBasicBlock("VPBB3"); @@ -30,13 +33,14 @@ TEST(VPDominatorTreeTest, DominanceNoRegionsTest) { VPBB2->setParent(R1); VPBB3->setParent(R1); + VPBlockUtils::connectBlocks(VPBB0, R1); VPBlockUtils::connectBlocks(VPBB1, VPBB2); VPBlockUtils::connectBlocks(VPBB1, VPBB3); VPBlockUtils::connectBlocks(VPBB2, VPBB4); VPBlockUtils::connectBlocks(VPBB3, VPBB4); VPlan Plan; - Plan.setEntry(R1); + Plan.setEntry(VPBB0); VPDominatorTree VPDT; VPDT.recalculate(Plan); @@ -68,6 +72,8 @@ checkDomChildren(VPDominatorTree &VPDT, VPBlockBase *Src, TEST(VPDominatorTreeTest, DominanceRegionsTest) { { // 2 consecutive regions. + // VPBB0 + // | // R1 { // \ // R1BB1 _ @@ -84,6 +90,7 @@ TEST(VPDominatorTreeTest, DominanceRegionsTest) { // R2BB2 // } // + VPBasicBlock *VPBB0 = new VPBasicBlock("VPBB0"); VPBasicBlock *R1BB1 = new VPBasicBlock(); VPBasicBlock *R1BB2 = new VPBasicBlock(); VPBasicBlock *R1BB3 = new VPBasicBlock(); @@ -91,6 +98,7 @@ TEST(VPDominatorTreeTest, DominanceRegionsTest) { VPRegionBlock *R1 = new VPRegionBlock(R1BB1, R1BB4, "R1"); R1BB2->setParent(R1); R1BB3->setParent(R1); + VPBlockUtils::connectBlocks(VPBB0, R1); VPBlockUtils::connectBlocks(R1BB1, R1BB2); VPBlockUtils::connectBlocks(R1BB1, R1BB3); VPBlockUtils::connectBlocks(R1BB2, R1BB4); @@ -105,7 +113,7 @@ TEST(VPDominatorTreeTest, DominanceRegionsTest) { VPBlockUtils::connectBlocks(R1, R2); VPlan Plan; - Plan.setEntry(R1); + Plan.setEntry(VPBB0); VPDominatorTree VPDT; VPDT.recalculate(Plan); diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp index 606d8d0..dbf0369 100644 --- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp +++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp @@ -264,20 +264,6 @@ TEST(VPBasicBlockTest, getPlan) { } { - // Region block is entry into VPlan. - VPBasicBlock *R1BB1 = new VPBasicBlock(); - VPBasicBlock *R1BB2 = new VPBasicBlock(); - VPRegionBlock *R1 = new VPRegionBlock(R1BB1, R1BB2, "R1"); - VPBlockUtils::connectBlocks(R1BB1, R1BB2); - - VPlan Plan; - Plan.setEntry(R1); - EXPECT_EQ(&Plan, R1->getPlan()); - EXPECT_EQ(&Plan, R1BB1->getPlan()); - EXPECT_EQ(&Plan, R1BB2->getPlan()); - } - - { // VPBasicBlock is the entry into the VPlan, followed by a region. VPBasicBlock *R1BB1 = new VPBasicBlock(); VPBasicBlock *R1BB2 = new VPBasicBlock(); @@ -359,6 +345,8 @@ TEST(VPBasicBlockTest, TraversingIteratorTest) { { // 2 consecutive regions. + // VPBB0 + // | // R1 { // \ // R1BB1 @@ -374,6 +362,7 @@ TEST(VPBasicBlockTest, TraversingIteratorTest) { // | // R2BB2 // + VPBasicBlock *VPBB0 = new VPBasicBlock("VPBB0"); VPBasicBlock *R1BB1 = new VPBasicBlock(); VPBasicBlock *R1BB2 = new VPBasicBlock(); VPBasicBlock *R1BB3 = new VPBasicBlock(); @@ -381,6 +370,7 @@ TEST(VPBasicBlockTest, TraversingIteratorTest) { VPRegionBlock *R1 = new VPRegionBlock(R1BB1, R1BB4, "R1"); R1BB2->setParent(R1); R1BB3->setParent(R1); + VPBlockUtils::connectBlocks(VPBB0, R1); VPBlockUtils::connectBlocks(R1BB1, R1BB2); VPBlockUtils::connectBlocks(R1BB1, R1BB3); VPBlockUtils::connectBlocks(R1BB2, R1BB4); @@ -449,7 +439,7 @@ TEST(VPBasicBlockTest, TraversingIteratorTest) { // Use Plan to properly clean up created blocks. VPlan Plan; - Plan.setEntry(R1); + Plan.setEntry(VPBB0); } { -- 2.7.4