// 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<VPBlockBase *>(State.Plan->getEntry()));
+ auto Iter = vp_depth_first_deep(State.Plan->getEntry());
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(Iter)) {
for (VPRecipeBase &Recipe : *VPBB) {
if (auto *WidenRec = dyn_cast<VPWidenMemoryInstructionRecipe>(&Recipe)) {
void InnerLoopVectorizer::fixNonInductionPHIs(VPlan &Plan,
VPTransformState &State) {
- auto Iter = depth_first(
- VPBlockRecursiveTraversalWrapper<VPBlockBase *>(Plan.getEntry()));
+ auto Iter = vp_depth_first_deep(Plan.getEntry());
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(Iter)) {
for (VPRecipeBase &P : VPBB->phis()) {
VPWidenPHIRecipe *VPPhi = dyn_cast<VPWidenPHIRecipe>(&P);
if (Plan.BackedgeTakenCount)
assignSlot(Plan.BackedgeTakenCount);
- ReversePostOrderTraversal<
- VPBlockRecursiveTraversalWrapper<const VPBlockBase *>>
- RPOT(VPBlockRecursiveTraversalWrapper<const VPBlockBase *>(
- Plan.getEntry()));
+ ReversePostOrderTraversal<VPBlockDeepTraversalWrapper<const VPBlockBase *>>
+ RPOT(VPBlockDeepTraversalWrapper<const VPBlockBase *>(Plan.getEntry()));
for (const VPBasicBlock *VPBB :
VPBlockUtils::blocksOnly<const VPBasicBlock>(RPOT))
for (const VPRecipeBase &Recipe : *VPBB)
};
/// Helper for GraphTraits specialization that traverses through VPRegionBlocks.
-template <typename BlockTy> class VPBlockRecursiveTraversalWrapper {
+template <typename BlockTy> class VPBlockDeepTraversalWrapper {
BlockTy Entry;
public:
- VPBlockRecursiveTraversalWrapper(BlockTy Entry) : Entry(Entry) {}
+ VPBlockDeepTraversalWrapper(BlockTy Entry) : Entry(Entry) {}
BlockTy getEntry() { return Entry; }
};
/// 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<VPBlockRecursiveTraversalWrapper<VPBlockBase *>> {
+template <> struct GraphTraits<VPBlockDeepTraversalWrapper<VPBlockBase *>> {
using NodeRef = VPBlockBase *;
using ChildIteratorType = VPAllSuccessorsIterator<VPBlockBase *>;
- static NodeRef
- getEntryNode(VPBlockRecursiveTraversalWrapper<VPBlockBase *> N) {
+ static NodeRef getEntryNode(VPBlockDeepTraversalWrapper<VPBlockBase *> N) {
return N.getEntry();
}
};
template <>
-struct GraphTraits<VPBlockRecursiveTraversalWrapper<const VPBlockBase *>> {
+struct GraphTraits<VPBlockDeepTraversalWrapper<const VPBlockBase *>> {
using NodeRef = const VPBlockBase *;
using ChildIteratorType = VPAllSuccessorsIterator<const VPBlockBase *>;
static NodeRef
- getEntryNode(VPBlockRecursiveTraversalWrapper<const VPBlockBase *> N) {
+ getEntryNode(VPBlockDeepTraversalWrapper<const VPBlockBase *> N) {
return N.getEntry();
}
return depth_first(VPBlockShallowTraversalWrapper<const VPBlockBase *>(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<VPBlockDeepTraversalWrapper<VPBlockBase *>>>
+vp_depth_first_deep(VPBlockBase *G) {
+ return depth_first(VPBlockDeepTraversalWrapper<VPBlockBase *>(G));
+}
+inline iterator_range<
+ df_iterator<VPBlockDeepTraversalWrapper<const VPBlockBase *>>>
+vp_depth_first_deep(const VPBlockBase *G) {
+ return depth_first(VPBlockDeepTraversalWrapper<const VPBlockBase *>(G));
+}
+
} // namespace llvm
#endif // LLVM_TRANSFORMS_VECTORIZE_VPLANCFG_H
SmallPtrSetImpl<Instruction *> &DeadInstructions, ScalarEvolution &SE,
const TargetLibraryInfo &TLI) {
- ReversePostOrderTraversal<VPBlockRecursiveTraversalWrapper<VPBlockBase *>>
- RPOT(Plan->getEntry());
+ ReversePostOrderTraversal<VPBlockDeepTraversalWrapper<VPBlockBase *>> RPOT(
+ Plan->getEntry());
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) {
VPRecipeBase *Term = VPBB->getTerminator();
auto EndIter = Term ? Term->getIterator() : VPBB->end();
}
bool VPlanTransforms::sinkScalarOperands(VPlan &Plan) {
- auto Iter = depth_first(
- VPBlockRecursiveTraversalWrapper<VPBlockBase *>(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.
// replicate region with matching masks to process front. This is to avoid
// iterator invalidation issues while merging regions.
SmallVector<VPRegionBlock *, 8> WorkList;
- for (VPRegionBlock *Region1 :
- VPBlockUtils::blocksOnly<VPRegionBlock>(depth_first(
- VPBlockRecursiveTraversalWrapper<VPBlockBase *>(Plan.getEntry())))) {
+ for (VPRegionBlock *Region1 : VPBlockUtils::blocksOnly<VPRegionBlock>(
+ vp_depth_first_deep(Plan.getEntry()))) {
if (!Region1->isReplicator())
continue;
auto *MiddleBasicBlock =
bool VPlanTransforms::mergeBlocksIntoPredecessors(VPlan &Plan) {
SmallVector<VPBasicBlock *> WorkList;
- for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(depth_first(
- VPBlockRecursiveTraversalWrapper<VPBlockBase *>(Plan.getEntry())))) {
+ for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
+ vp_depth_first_deep(Plan.getEntry()))) {
auto *PredVPBB =
dyn_cast_or_null<VPBasicBlock>(VPBB->getSinglePredecessor());
if (PredVPBB && PredVPBB->getNumSuccessors() == 1)
}
void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
- ReversePostOrderTraversal<VPBlockRecursiveTraversalWrapper<VPBlockBase *>>
- RPOT(Plan.getEntry());
+ ReversePostOrderTraversal<VPBlockDeepTraversalWrapper<VPBlockBase *>> RPOT(
+ Plan.getEntry());
for (VPBasicBlock *VPBB : reverse(VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT))) {
// The recipes in the block are processed in reverse order, to catch chains
bool VPlanVerifier::verifyPlanIsValid(const VPlan &Plan) {
DenseMap<const VPBlockBase *, unsigned> BlockNumbering;
unsigned Cnt = 0;
- auto Iter = depth_first(
- VPBlockRecursiveTraversalWrapper<const VPBlockBase *>(Plan.getEntry()));
+ auto Iter = vp_depth_first_deep(Plan.getEntry());
for (const VPBlockBase *VPB : Iter) {
BlockNumbering[VPB] = Cnt++;
auto *VPBB = dyn_cast<VPBasicBlock>(VPB);
for (const VPRegionBlock *Region :
VPBlockUtils::blocksOnly<const VPRegionBlock>(
- depth_first(VPBlockRecursiveTraversalWrapper<const VPBlockBase *>(
- Plan.getEntry())))) {
+ vp_depth_first_deep(Plan.getEntry()))) {
if (Region->getEntry()->getNumPredecessors() != 0) {
errs() << "region entry block has predecessors\n";
return false;
VPBlockUtils::connectBlocks(VPBB2, VPBB4);
VPBlockUtils::connectBlocks(VPBB3, VPBB4);
- VPBlockRecursiveTraversalWrapper<const VPBlockBase *> Start(VPBB1);
+ VPBlockDeepTraversalWrapper<const VPBlockBase *> Start(VPBB1);
SmallVector<const VPBlockBase *> FromIterator(depth_first(Start));
EXPECT_EQ(4u, FromIterator.size());
EXPECT_EQ(VPBB1, FromIterator[0]);
EXPECT_EQ(R1BB1, FromIterator[0]);
// Depth-first.
- VPBlockRecursiveTraversalWrapper<VPBlockBase *> Start(R1);
+ VPBlockDeepTraversalWrapper<VPBlockBase *> Start(R1);
FromIterator.clear();
copy(df_begin(Start), df_end(Start), std::back_inserter(FromIterator));
EXPECT_EQ(8u, FromIterator.size());
VPBlockUtils::connectBlocks(R1, VPBB2);
// Depth-first.
- VPBlockRecursiveTraversalWrapper<VPBlockBase *> Start(VPBB1);
+ VPBlockDeepTraversalWrapper<VPBlockBase *> Start(VPBB1);
SmallVector<VPBlockBase *> FromIterator(depth_first(Start));
EXPECT_EQ(10u, FromIterator.size());
EXPECT_EQ(VPBB1, FromIterator[0]);
VPBlockUtils::connectBlocks(VPBB1, R1);
// Depth-first.
- VPBlockRecursiveTraversalWrapper<VPBlockBase *> Start(VPBB1);
+ VPBlockDeepTraversalWrapper<VPBlockBase *> Start(VPBB1);
SmallVector<VPBlockBase *> FromIterator(depth_first(Start));
EXPECT_EQ(5u, FromIterator.size());
EXPECT_EQ(VPBB1, FromIterator[0]);
VPBlockUtils::connectBlocks(R1, VPBB2);
// Depth-first.
- VPBlockRecursiveTraversalWrapper<VPBlockBase *> Start(VPBB1);
+ VPBlockDeepTraversalWrapper<VPBlockBase *> Start(VPBB1);
SmallVector<VPBlockBase *> FromIterator(depth_first(Start));
EXPECT_EQ(7u, FromIterator.size());
EXPECT_EQ(VPBB1, FromIterator[0]);
EXPECT_EQ(VPBB1, FromIterator[6]);
// Post-order, const VPRegionBlocks only.
- VPBlockRecursiveTraversalWrapper<const VPBlockBase *> StartConst(VPBB1);
+ VPBlockDeepTraversalWrapper<const VPBlockBase *> StartConst(VPBB1);
SmallVector<const VPRegionBlock *> FromIteratorVPRegion(
VPBlockUtils::blocksOnly<const VPRegionBlock>(post_order(StartConst)));
EXPECT_EQ(3u, FromIteratorVPRegion.size());