diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -2209,13 +2209,14 @@ /// 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 @@ MapVector LiveOuts; public: - VPlan(VPBlockBase *Entry = nullptr) : Entry(Entry) { + VPlan(VPBasicBlock *Entry = nullptr) : Entry(Entry) { if (Entry) Entry->setPlan(this); } @@ -2269,10 +2270,10 @@ /// 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/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -1133,7 +1133,7 @@ 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/unittests/Transforms/Vectorize/VPDomTreeTest.cpp b/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp --- a/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp +++ b/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp @@ -15,6 +15,8 @@ namespace { TEST(VPDominatorTreeTest, DominanceNoRegionsTest) { + // VPBB0 + // | // R1 { // VPBB1 // / \ @@ -22,6 +24,7 @@ // \ / // 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 @@ 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 @@ TEST(VPDominatorTreeTest, DominanceRegionsTest) { { // 2 consecutive regions. + // VPBB0 + // | // R1 { // \ // R1BB1 _ @@ -84,6 +90,7 @@ // R2BB2 // } // + VPBasicBlock *VPBB0 = new VPBasicBlock("VPBB0"); VPBasicBlock *R1BB1 = new VPBasicBlock(); VPBasicBlock *R1BB2 = new VPBasicBlock(); VPBasicBlock *R1BB3 = new VPBasicBlock(); @@ -91,6 +98,7 @@ 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 @@ 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 --- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp +++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp @@ -263,20 +263,6 @@ EXPECT_EQ(&Plan, VPBB4->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(); @@ -359,6 +345,8 @@ { // 2 consecutive regions. + // VPBB0 + // | // R1 { // \ // R1BB1 @@ -374,6 +362,7 @@ // | // R2BB2 // + VPBasicBlock *VPBB0 = new VPBasicBlock("VPBB0"); VPBasicBlock *R1BB1 = new VPBasicBlock(); VPBasicBlock *R1BB2 = new VPBasicBlock(); VPBasicBlock *R1BB3 = new VPBasicBlock(); @@ -381,6 +370,7 @@ 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 @@ // Use Plan to properly clean up created blocks. VPlan Plan; - Plan.setEntry(R1); + Plan.setEntry(VPBB0); } {