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 @@ -1250,26 +1250,6 @@ Slots[V] = NextSlot++; } -void VPSlotTracker::assignSlots(const VPBlockBase *VPBB) { - if (auto *Region = dyn_cast(VPBB)) - assignSlots(Region); - else - assignSlots(cast(VPBB)); -} - -void VPSlotTracker::assignSlots(const VPRegionBlock *Region) { - ReversePostOrderTraversal RPOT(Region->getEntry()); - for (const VPBlockBase *Block : RPOT) - assignSlots(Block); -} - -void VPSlotTracker::assignSlots(const VPBasicBlock *VPBB) { - for (const VPRecipeBase &Recipe : *VPBB) { - for (VPValue *Def : Recipe.definedValues()) - assignSlot(Def); - } -} - void VPSlotTracker::assignSlots(const VPlan &Plan) { for (const VPValue *V : Plan.VPExternalDefs) @@ -1278,7 +1258,17 @@ if (Plan.BackedgeTakenCount) assignSlot(Plan.BackedgeTakenCount); - ReversePostOrderTraversal RPOT(Plan.getEntry()); - for (const VPBlockBase *Block : RPOT) - assignSlots(Block); + ReversePostOrderTraversal< + VPBlockRecursiveTraversalWrapper> + RPOT(VPBlockRecursiveTraversalWrapper( + Plan.getEntry())); + for (const VPBlockBase *Block : RPOT) { + auto *VPBB = dyn_cast(Block); + if (!VPBB) + continue; + for (const VPRecipeBase &Recipe : *VPBB) { + for (VPValue *Def : Recipe.definedValues()) + assignSlot(Def); + } + } } diff --git a/llvm/lib/Transforms/Vectorize/VPlanValue.h b/llvm/lib/Transforms/Vectorize/VPlanValue.h --- a/llvm/lib/Transforms/Vectorize/VPlanValue.h +++ b/llvm/lib/Transforms/Vectorize/VPlanValue.h @@ -372,11 +372,7 @@ DenseMap Slots; unsigned NextSlot = 0; - void assignSlots(const VPBlockBase *VPBB); - void assignSlots(const VPRegionBlock *Region); - void assignSlots(const VPBasicBlock *VPBB); void assignSlot(const VPValue *V); - void assignSlots(const VPlan &Plan); public: 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 @@ -418,6 +418,21 @@ EXPECT_EQ(R1BB1, FromIterator[6]); EXPECT_EQ(R1, FromIterator[7]); + // Reverse post-order. + FromIterator.clear(); + ReversePostOrderTraversal> + RPOT(Start); + copy(RPOT, std::back_inserter(FromIterator)); + EXPECT_EQ(8u, FromIterator.size()); + EXPECT_EQ(R1, FromIterator[0]); + EXPECT_EQ(R1BB1, FromIterator[1]); + EXPECT_EQ(R1BB3, FromIterator[2]); + EXPECT_EQ(R1BB2, FromIterator[3]); + EXPECT_EQ(R1BB4, FromIterator[4]); + EXPECT_EQ(R2, FromIterator[5]); + EXPECT_EQ(R2BB1, FromIterator[6]); + EXPECT_EQ(R2BB2, FromIterator[7]); + // Use Plan to properly clean up created blocks. VPlan Plan; Plan.setEntry(R1); @@ -500,6 +515,22 @@ EXPECT_EQ(R1, FromIterator[8]); EXPECT_EQ(VPBB1, FromIterator[9]); + FromIterator.clear(); + ReversePostOrderTraversal> + RPOT(Start); + copy(RPOT, std::back_inserter(FromIterator)); + EXPECT_EQ(10u, FromIterator.size()); + EXPECT_EQ(VPBB1, FromIterator[0]); + EXPECT_EQ(R1, FromIterator[1]); + EXPECT_EQ(R1BB1, FromIterator[2]); + EXPECT_EQ(R1BB2, FromIterator[3]); + EXPECT_EQ(R2, FromIterator[4]); + EXPECT_EQ(R2BB1, FromIterator[5]); + EXPECT_EQ(R2BB2, FromIterator[6]); + EXPECT_EQ(R2BB3, FromIterator[7]); + EXPECT_EQ(R1BB3, FromIterator[8]); + EXPECT_EQ(VPBB2, FromIterator[9]); + // Use Plan to properly clean up created blocks. VPlan Plan; Plan.setEntry(VPBB1);