From: Florian Hahn Date: Thu, 19 Jan 2023 20:34:22 +0000 (+0000) Subject: [VPlan] Add vp_depth_first_deep (NFC) X-Git-Tag: upstream/17.0.6~20371 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e2c43a547b311725067e7b56ae935e940e6fc1c3;p=platform%2Fupstream%2Fllvm.git [VPlan] Add vp_depth_first_deep (NFC) Similar to vp_depth_first_shallow (D140512) add vp_depth_first_deep to make existing code clearer and more compact. Reviewed By: Ayal Differential Revision: https://reviews.llvm.org/D142055 --- diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index c6b80e7..ca13e79 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1078,8 +1078,7 @@ void InnerLoopVectorizer::collectPoisonGeneratingRecipes( // Traverse all the recipes in the VPlan and collect the poison-generating // recipes in the backward slice starting at the address of a VPWidenRecipe or // VPInterleaveRecipe. - auto Iter = depth_first( - VPBlockRecursiveTraversalWrapper(State.Plan->getEntry())); + auto Iter = vp_depth_first_deep(State.Plan->getEntry()); for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly(Iter)) { for (VPRecipeBase &Recipe : *VPBB) { if (auto *WidenRec = dyn_cast(&Recipe)) { @@ -4161,8 +4160,7 @@ void InnerLoopVectorizer::sinkScalarOperands(Instruction *PredInst) { void InnerLoopVectorizer::fixNonInductionPHIs(VPlan &Plan, VPTransformState &State) { - auto Iter = depth_first( - VPBlockRecursiveTraversalWrapper(Plan.getEntry())); + auto Iter = vp_depth_first_deep(Plan.getEntry()); for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly(Iter)) { for (VPRecipeBase &P : VPBB->phis()) { VPWidenPHIRecipe *VPPhi = dyn_cast(&P); diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp index f026dbe..d554f43 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -1099,10 +1099,8 @@ void VPSlotTracker::assignSlots(const VPlan &Plan) { if (Plan.BackedgeTakenCount) assignSlot(Plan.BackedgeTakenCount); - ReversePostOrderTraversal< - VPBlockRecursiveTraversalWrapper> - RPOT(VPBlockRecursiveTraversalWrapper( - Plan.getEntry())); + ReversePostOrderTraversal> + RPOT(VPBlockDeepTraversalWrapper(Plan.getEntry())); for (const VPBasicBlock *VPBB : VPBlockUtils::blocksOnly(RPOT)) for (const VPRecipeBase &Recipe : *VPBB) diff --git a/llvm/lib/Transforms/Vectorize/VPlanCFG.h b/llvm/lib/Transforms/Vectorize/VPlanCFG.h index 8ee949d..3ca1538 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanCFG.h +++ b/llvm/lib/Transforms/Vectorize/VPlanCFG.h @@ -220,11 +220,11 @@ public: }; /// Helper for GraphTraits specialization that traverses through VPRegionBlocks. -template class VPBlockRecursiveTraversalWrapper { +template class VPBlockDeepTraversalWrapper { BlockTy Entry; public: - VPBlockRecursiveTraversalWrapper(BlockTy Entry) : Entry(Entry) {} + VPBlockDeepTraversalWrapper(BlockTy Entry) : Entry(Entry) {} BlockTy getEntry() { return Entry; } }; @@ -233,13 +233,11 @@ public: /// implicitly have their parent region's successors. This ensures all blocks in /// a region are visited before any blocks in a successor region when doing a /// reverse post-order traversal of the graph. -template <> -struct GraphTraits> { +template <> struct GraphTraits> { using NodeRef = VPBlockBase *; using ChildIteratorType = VPAllSuccessorsIterator; - static NodeRef - getEntryNode(VPBlockRecursiveTraversalWrapper N) { + static NodeRef getEntryNode(VPBlockDeepTraversalWrapper N) { return N.getEntry(); } @@ -253,12 +251,12 @@ struct GraphTraits> { }; template <> -struct GraphTraits> { +struct GraphTraits> { using NodeRef = const VPBlockBase *; using ChildIteratorType = VPAllSuccessorsIterator; static NodeRef - getEntryNode(VPBlockRecursiveTraversalWrapper N) { + getEntryNode(VPBlockDeepTraversalWrapper N) { return N.getEntry(); } @@ -330,6 +328,18 @@ vp_depth_first_shallow(const VPBlockBase *G) { return depth_first(VPBlockShallowTraversalWrapper(G)); } +/// Returns an iterator range to traverse the graph starting at \p G in +/// depth-first order while traversing through region blocks. +inline iterator_range>> +vp_depth_first_deep(VPBlockBase *G) { + return depth_first(VPBlockDeepTraversalWrapper(G)); +} +inline iterator_range< + df_iterator>> +vp_depth_first_deep(const VPBlockBase *G) { + return depth_first(VPBlockDeepTraversalWrapper(G)); +} + } // namespace llvm #endif // LLVM_TRANSFORMS_VECTORIZE_VPLANCFG_H diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index bb9fd47..429b80f 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -28,8 +28,8 @@ void VPlanTransforms::VPInstructionsToVPRecipes( SmallPtrSetImpl &DeadInstructions, ScalarEvolution &SE, const TargetLibraryInfo &TLI) { - ReversePostOrderTraversal> - RPOT(Plan->getEntry()); + ReversePostOrderTraversal> RPOT( + Plan->getEntry()); for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly(RPOT)) { VPRecipeBase *Term = VPBB->getTerminator(); auto EndIter = Term ? Term->getIterator() : VPBB->end(); @@ -107,8 +107,7 @@ void VPlanTransforms::VPInstructionsToVPRecipes( } bool VPlanTransforms::sinkScalarOperands(VPlan &Plan) { - auto Iter = depth_first( - VPBlockRecursiveTraversalWrapper(Plan.getEntry())); + auto Iter = vp_depth_first_deep(Plan.getEntry()); bool Changed = false; // First, collect the operands of all predicated replicate recipes as seeds // for sinking. @@ -229,9 +228,8 @@ bool VPlanTransforms::mergeReplicateRegionsIntoSuccessors(VPlan &Plan) { // replicate region with matching masks to process front. This is to avoid // iterator invalidation issues while merging regions. SmallVector WorkList; - for (VPRegionBlock *Region1 : - VPBlockUtils::blocksOnly(depth_first( - VPBlockRecursiveTraversalWrapper(Plan.getEntry())))) { + for (VPRegionBlock *Region1 : VPBlockUtils::blocksOnly( + vp_depth_first_deep(Plan.getEntry()))) { if (!Region1->isReplicator()) continue; auto *MiddleBasicBlock = @@ -313,8 +311,8 @@ bool VPlanTransforms::mergeReplicateRegionsIntoSuccessors(VPlan &Plan) { bool VPlanTransforms::mergeBlocksIntoPredecessors(VPlan &Plan) { SmallVector WorkList; - for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly(depth_first( - VPBlockRecursiveTraversalWrapper(Plan.getEntry())))) { + for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly( + vp_depth_first_deep(Plan.getEntry()))) { auto *PredVPBB = dyn_cast_or_null(VPBB->getSinglePredecessor()); if (PredVPBB && PredVPBB->getNumSuccessors() == 1) @@ -404,8 +402,8 @@ void VPlanTransforms::removeRedundantCanonicalIVs(VPlan &Plan) { } void VPlanTransforms::removeDeadRecipes(VPlan &Plan) { - ReversePostOrderTraversal> - RPOT(Plan.getEntry()); + ReversePostOrderTraversal> RPOT( + Plan.getEntry()); for (VPBasicBlock *VPBB : reverse(VPBlockUtils::blocksOnly(RPOT))) { // The recipes in the block are processed in reverse order, to catch chains diff --git a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp index 56a1b56..18125ce 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp @@ -252,8 +252,7 @@ verifyVPBasicBlock(const VPBasicBlock *VPBB, bool VPlanVerifier::verifyPlanIsValid(const VPlan &Plan) { DenseMap BlockNumbering; unsigned Cnt = 0; - auto Iter = depth_first( - VPBlockRecursiveTraversalWrapper(Plan.getEntry())); + auto Iter = vp_depth_first_deep(Plan.getEntry()); for (const VPBlockBase *VPB : Iter) { BlockNumbering[VPB] = Cnt++; auto *VPBB = dyn_cast(VPB); @@ -298,8 +297,7 @@ bool VPlanVerifier::verifyPlanIsValid(const VPlan &Plan) { for (const VPRegionBlock *Region : VPBlockUtils::blocksOnly( - depth_first(VPBlockRecursiveTraversalWrapper( - Plan.getEntry())))) { + vp_depth_first_deep(Plan.getEntry()))) { if (Region->getEntry()->getNumPredecessors() != 0) { errs() << "region entry block has predecessors\n"; return false; diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp index 8995399..495ce19 100644 --- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp +++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp @@ -346,7 +346,7 @@ TEST(VPBasicBlockTest, TraversingIteratorTest) { VPBlockUtils::connectBlocks(VPBB2, VPBB4); VPBlockUtils::connectBlocks(VPBB3, VPBB4); - VPBlockRecursiveTraversalWrapper Start(VPBB1); + VPBlockDeepTraversalWrapper Start(VPBB1); SmallVector FromIterator(depth_first(Start)); EXPECT_EQ(4u, FromIterator.size()); EXPECT_EQ(VPBB1, FromIterator[0]); @@ -402,7 +402,7 @@ TEST(VPBasicBlockTest, TraversingIteratorTest) { EXPECT_EQ(R1BB1, FromIterator[0]); // Depth-first. - VPBlockRecursiveTraversalWrapper Start(R1); + VPBlockDeepTraversalWrapper Start(R1); FromIterator.clear(); copy(df_begin(Start), df_end(Start), std::back_inserter(FromIterator)); EXPECT_EQ(8u, FromIterator.size()); @@ -500,7 +500,7 @@ TEST(VPBasicBlockTest, TraversingIteratorTest) { VPBlockUtils::connectBlocks(R1, VPBB2); // Depth-first. - VPBlockRecursiveTraversalWrapper Start(VPBB1); + VPBlockDeepTraversalWrapper Start(VPBB1); SmallVector FromIterator(depth_first(Start)); EXPECT_EQ(10u, FromIterator.size()); EXPECT_EQ(VPBB1, FromIterator[0]); @@ -557,7 +557,7 @@ TEST(VPBasicBlockTest, TraversingIteratorTest) { VPBlockUtils::connectBlocks(VPBB1, R1); // Depth-first. - VPBlockRecursiveTraversalWrapper Start(VPBB1); + VPBlockDeepTraversalWrapper Start(VPBB1); SmallVector FromIterator(depth_first(Start)); EXPECT_EQ(5u, FromIterator.size()); EXPECT_EQ(VPBB1, FromIterator[0]); @@ -617,7 +617,7 @@ TEST(VPBasicBlockTest, TraversingIteratorTest) { VPBlockUtils::connectBlocks(R1, VPBB2); // Depth-first. - VPBlockRecursiveTraversalWrapper Start(VPBB1); + VPBlockDeepTraversalWrapper Start(VPBB1); SmallVector FromIterator(depth_first(Start)); EXPECT_EQ(7u, FromIterator.size()); EXPECT_EQ(VPBB1, FromIterator[0]); @@ -649,7 +649,7 @@ TEST(VPBasicBlockTest, TraversingIteratorTest) { EXPECT_EQ(VPBB1, FromIterator[6]); // Post-order, const VPRegionBlocks only. - VPBlockRecursiveTraversalWrapper StartConst(VPBB1); + VPBlockDeepTraversalWrapper StartConst(VPBB1); SmallVector FromIteratorVPRegion( VPBlockUtils::blocksOnly(post_order(StartConst))); EXPECT_EQ(3u, FromIteratorVPRegion.size());