[llvm] 4b9be5a - [VPlan] Add VPBlockUtils::blocksOnly helper.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 25 09:39:51 PDT 2021
Author: Florian Hahn
Date: 2021-04-25T17:38:09+01:00
New Revision: 4b9be5ac08506bdaea2f8f6cb8e4ead71452f38d
URL: https://github.com/llvm/llvm-project/commit/4b9be5ac08506bdaea2f8f6cb8e4ead71452f38d
DIFF: https://github.com/llvm/llvm-project/commit/4b9be5ac08506bdaea2f8f6cb8e4ead71452f38d.diff
LOG: [VPlan] Add VPBlockUtils::blocksOnly helper.
This patch adds a blocksOnly helpers which take an iterator range
over VPBlockBase * or const VPBlockBase * and returns an interator
range that only include BlockTy blocks. The accesses are casted to
BlockTy.
Reviewed By: a.elovikov
Differential Revision: https://reviews.llvm.org/D101093
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.h
llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 0aa111b552a4..91a3d9153c68 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -2201,6 +2201,20 @@ class VPBlockUtils {
}
return Count;
}
+
+ /// Return an iterator range over \p Iter which only includes \p BlockTy
+ /// blocks. The accesses are casted to \p BlockTy.
+ template <typename BlockTy, typename T> static auto blocksOnly(T Iter) {
+ // We need to first create an iterator range over VPBlockBase & instead of
+ // VPBlockBase * for filter_range to work properly.
+ auto Mapped = map_range(
+ Iter, [](VPBlockBase *Block) -> VPBlockBase & { return *Block; });
+ auto Filter = make_filter_range(
+ Mapped, [](VPBlockBase &Block) { return isa<BlockTy>(&Block); });
+ return map_range(Filter, [](VPBlockBase &Block) -> BlockTy * {
+ return cast<BlockTy>(&Block);
+ });
+ }
};
class VPInterleavedAccessInfo {
diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
index 7255825a1646..7c1843b6abb9 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
@@ -405,6 +405,25 @@ TEST(VPBasicBlockTest, TraversingIteratorTest) {
EXPECT_EQ(R2BB2, FromIterator[6]);
EXPECT_EQ(R1BB3, FromIterator[7]);
+ // const VPBasicBlocks only.
+ FromIterator.clear();
+ copy(VPBlockUtils::blocksOnly<const VPBasicBlock>(depth_first(Start)),
+ std::back_inserter(FromIterator));
+ EXPECT_EQ(6u, FromIterator.size());
+ EXPECT_EQ(R1BB1, FromIterator[0]);
+ EXPECT_EQ(R1BB2, FromIterator[1]);
+ EXPECT_EQ(R1BB4, FromIterator[2]);
+ EXPECT_EQ(R2BB1, FromIterator[3]);
+ EXPECT_EQ(R2BB2, FromIterator[4]);
+ EXPECT_EQ(R1BB3, FromIterator[5]);
+
+ // VPRegionBlocks only.
+ SmallVector<VPRegionBlock *> FromIteratorVPRegion(
+ VPBlockUtils::blocksOnly<VPRegionBlock>(depth_first(Start)));
+ EXPECT_EQ(2u, FromIteratorVPRegion.size());
+ EXPECT_EQ(R1, FromIteratorVPRegion[0]);
+ EXPECT_EQ(R2, FromIteratorVPRegion[1]);
+
// Post-order.
FromIterator.clear();
copy(post_order(Start), std::back_inserter(FromIterator));
@@ -599,6 +618,14 @@ TEST(VPBasicBlockTest, TraversingIteratorTest) {
EXPECT_EQ(R3BB1, FromIterator[5]);
EXPECT_EQ(VPBB2, FromIterator[6]);
+ SmallVector<VPBlockBase *> FromIteratorVPBB;
+ copy(VPBlockUtils::blocksOnly<VPBasicBlock>(depth_first(Start)),
+ std::back_inserter(FromIteratorVPBB));
+ EXPECT_EQ(VPBB1, FromIteratorVPBB[0]);
+ EXPECT_EQ(R2BB1, FromIteratorVPBB[1]);
+ EXPECT_EQ(R3BB1, FromIteratorVPBB[2]);
+ EXPECT_EQ(VPBB2, FromIteratorVPBB[3]);
+
// Post-order.
FromIterator.clear();
copy(post_order(Start), std::back_inserter(FromIterator));
@@ -611,6 +638,24 @@ TEST(VPBasicBlockTest, TraversingIteratorTest) {
EXPECT_EQ(R1, FromIterator[5]);
EXPECT_EQ(VPBB1, FromIterator[6]);
+ // Post-order, const VPRegionBlocks only.
+ SmallVector<const VPRegionBlock *> FromIteratorVPRegion(
+ VPBlockUtils::blocksOnly<const VPRegionBlock>(post_order(Start)));
+ EXPECT_EQ(3u, FromIteratorVPRegion.size());
+ EXPECT_EQ(R3, FromIteratorVPRegion[0]);
+ EXPECT_EQ(R2, FromIteratorVPRegion[1]);
+ EXPECT_EQ(R1, FromIteratorVPRegion[2]);
+
+ // Post-order, VPBasicBlocks only.
+ FromIterator.clear();
+ copy(VPBlockUtils::blocksOnly<VPBasicBlock>(post_order(Start)),
+ std::back_inserter(FromIterator));
+ EXPECT_EQ(FromIterator.size(), 4u);
+ EXPECT_EQ(VPBB2, FromIterator[0]);
+ EXPECT_EQ(R3BB1, FromIterator[1]);
+ EXPECT_EQ(R2BB1, FromIterator[2]);
+ EXPECT_EQ(VPBB1, FromIterator[3]);
+
// Use Plan to properly clean up created blocks.
VPlan Plan;
Plan.setEntry(VPBB1);
More information about the llvm-commits
mailing list