Skip to content

Commit 32928a0

Browse files
committed
[VPlan] Construct regions from innermost to outermost (NFC).
Flip the region construction order to innermost first from outermost first. This ensures we only set the final parent region for VPBBs once. Split off from #137709.
1 parent d05ab11 commit 32928a0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

llvm/lib/Transforms/Vectorize/VPlanCFG.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "VPlanUtils.h"
1717
#include "llvm/ADT/DepthFirstIterator.h"
1818
#include "llvm/ADT/GraphTraits.h"
19+
#include "llvm/ADT/PostOrderIterator.h"
1920
#include "llvm/ADT/SmallVector.h"
2021

2122
namespace llvm {
@@ -221,6 +222,14 @@ vp_depth_first_shallow(const VPBlockBase *G) {
221222
return depth_first(VPBlockShallowTraversalWrapper<const VPBlockBase *>(G));
222223
}
223224

225+
/// Returns an iterator range to traverse the graph starting at \p G in
226+
/// post order. The iterator won't traverse through region blocks.
227+
inline iterator_range<
228+
po_iterator<VPBlockShallowTraversalWrapper<VPBlockBase *>>>
229+
vp_post_order_shallow(VPBlockBase *G) {
230+
return post_order(VPBlockShallowTraversalWrapper<VPBlockBase *>(G));
231+
}
232+
224233
/// Returns an iterator range to traverse the graph starting at \p G in
225234
/// depth-first order while traversing through region blocks.
226235
inline iterator_range<df_iterator<VPBlockDeepTraversalWrapper<VPBlockBase *>>>

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ void VPlanTransforms::prepareForVectorization(VPlan &Plan, Type *InductionTy,
559559
void VPlanTransforms::createLoopRegions(VPlan &Plan) {
560560
VPDominatorTree VPDT;
561561
VPDT.recalculate(Plan);
562-
for (VPBlockBase *HeaderVPB : vp_depth_first_shallow(Plan.getEntry()))
562+
for (VPBlockBase *HeaderVPB : vp_post_order_shallow(Plan.getEntry()))
563563
if (canonicalHeaderAndLatch(HeaderVPB, VPDT))
564564
createLoopRegion(Plan, HeaderVPB);
565565

0 commit comments

Comments
 (0)