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/VPlanCFG.h b/llvm/lib/Transforms/Vectorize/VPlanCFG.h --- a/llvm/lib/Transforms/Vectorize/VPlanCFG.h +++ b/llvm/lib/Transforms/Vectorize/VPlanCFG.h @@ -331,6 +331,19 @@ VPBlockNonRecursiveTraversalWrapper(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< + df_iterator>> +vp_depth_first_deep(VPBlockBase *G) { + return depth_first(VPBlockRecursiveTraversalWrapper(G)); +} +inline iterator_range< + df_iterator>> +vp_depth_first_deep(const VPBlockBase *G) { + return depth_first(VPBlockRecursiveTraversalWrapper(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 @@ -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) 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;