diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1078,8 +1078,7 @@ // 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::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 --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -1099,10 +1099,8 @@ 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 --- a/llvm/lib/Transforms/Vectorize/VPlanCFG.h +++ b/llvm/lib/Transforms/Vectorize/VPlanCFG.h @@ -220,11 +220,11 @@ }; /// 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 @@ /// 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 @@ }; 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 @@ 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 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -28,8 +28,8 @@ 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 @@ } 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 @@ // 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::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::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 --- a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp @@ -252,8 +252,7 @@ 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 @@ 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;