Skip to content

Commit ef1260a

Browse files
committed
[VPlan] Make VPBlock constructors private (NFC).
16d19aa moved to manage block creation via VPlan directly, with VPlan owning the created blocks. Follow up to make the VPBlock constructors private, to require creation via VPlan helpers and thus preventing issues due to manually constructing blocks.
1 parent e9255dd commit ef1260a

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,6 +3526,15 @@ class VPScalarIVStepsRecipe : public VPRecipeWithIRFlags,
35263526
/// holds a sequence of zero or more VPRecipe's each representing a sequence of
35273527
/// output IR instructions. All PHI-like recipes must come before any non-PHI recipes.
35283528
class VPBasicBlock : public VPBlockBase {
3529+
friend class VPlan;
3530+
3531+
/// Use VPlan::createVPBasicBlock to create VPBasicBlocks.
3532+
VPBasicBlock(const Twine &Name = "", VPRecipeBase *Recipe = nullptr)
3533+
: VPBlockBase(VPBasicBlockSC, Name.str()) {
3534+
if (Recipe)
3535+
appendRecipe(Recipe);
3536+
}
3537+
35293538
public:
35303539
using RecipeListTy = iplist<VPRecipeBase>;
35313540

@@ -3537,12 +3546,6 @@ class VPBasicBlock : public VPBlockBase {
35373546
: VPBlockBase(BlockSC, Name.str()) {}
35383547

35393548
public:
3540-
VPBasicBlock(const Twine &Name = "", VPRecipeBase *Recipe = nullptr)
3541-
: VPBlockBase(VPBasicBlockSC, Name.str()) {
3542-
if (Recipe)
3543-
appendRecipe(Recipe);
3544-
}
3545-
35463549
~VPBasicBlock() override {
35473550
while (!Recipes.empty())
35483551
Recipes.pop_back();
@@ -3665,14 +3668,17 @@ class VPBasicBlock : public VPBlockBase {
36653668
/// Note: At the moment, VPIRBasicBlock can only be used to wrap VPlan's
36663669
/// preheader block.
36673670
class VPIRBasicBlock : public VPBasicBlock {
3671+
friend class VPlan;
3672+
36683673
BasicBlock *IRBB;
36693674

3670-
public:
3675+
/// Use VPlan::createVPIRBasicBlock to create VPIRBasicBlocks.
36713676
VPIRBasicBlock(BasicBlock *IRBB)
36723677
: VPBasicBlock(VPIRBasicBlockSC,
36733678
(Twine("ir-bb<") + IRBB->getName() + Twine(">")).str()),
36743679
IRBB(IRBB) {}
36753680

3681+
public:
36763682
~VPIRBasicBlock() override {}
36773683

36783684
static inline bool classof(const VPBlockBase *V) {
@@ -3697,6 +3703,8 @@ class VPIRBasicBlock : public VPBasicBlock {
36973703
/// candidate VF's. The actual replication takes place only once the desired VF
36983704
/// and UF have been determined.
36993705
class VPRegionBlock : public VPBlockBase {
3706+
friend class VPlan;
3707+
37003708
/// Hold the Single Entry of the SESE region modelled by the VPRegionBlock.
37013709
VPBlockBase *Entry;
37023710

@@ -3708,7 +3716,7 @@ class VPRegionBlock : public VPBlockBase {
37083716
/// instances of output IR corresponding to its VPBlockBases.
37093717
bool IsReplicator;
37103718

3711-
public:
3719+
/// Use VPlan::createVPRegionBlock to create VPRegionBlocks.
37123720
VPRegionBlock(VPBlockBase *Entry, VPBlockBase *Exiting,
37133721
const std::string &Name = "", bool IsReplicator = false)
37143722
: VPBlockBase(VPRegionBlockSC, Name), Entry(Entry), Exiting(Exiting),
@@ -3722,6 +3730,7 @@ class VPRegionBlock : public VPBlockBase {
37223730
: VPBlockBase(VPRegionBlockSC, Name), Entry(nullptr), Exiting(nullptr),
37233731
IsReplicator(IsReplicator) {}
37243732

3733+
public:
37253734
~VPRegionBlock() override {}
37263735

37273736
/// Method to support type inquiry through isa, cast, and dyn_cast.

llvm/unittests/Transforms/Vectorize/VPlanTest.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ namespace {
3030
EXPECT_EQ(&std::get<0>(Pair), std::get<1>(Pair)); \
3131
} while (0)
3232

33-
TEST(VPInstructionTest, insertBefore) {
33+
using VPInstructionTest = VPlanTestBase;
34+
35+
TEST_F(VPInstructionTest, insertBefore) {
3436
VPInstruction *I1 = new VPInstruction(0, {});
3537
VPInstruction *I2 = new VPInstruction(1, {});
3638
VPInstruction *I3 = new VPInstruction(2, {});
3739

38-
VPBasicBlock VPBB1;
40+
VPBasicBlock &VPBB1 = *getPlan().createVPBasicBlock("");
3941
VPBB1.appendRecipe(I1);
4042

4143
I2->insertBefore(I1);
@@ -45,12 +47,12 @@ TEST(VPInstructionTest, insertBefore) {
4547
CHECK_ITERATOR(VPBB1, I3, I2, I1);
4648
}
4749

48-
TEST(VPInstructionTest, eraseFromParent) {
50+
TEST_F(VPInstructionTest, eraseFromParent) {
4951
VPInstruction *I1 = new VPInstruction(0, {});
5052
VPInstruction *I2 = new VPInstruction(1, {});
5153
VPInstruction *I3 = new VPInstruction(2, {});
5254

53-
VPBasicBlock VPBB1;
55+
VPBasicBlock &VPBB1 = *getPlan().createVPBasicBlock("");
5456
VPBB1.appendRecipe(I1);
5557
VPBB1.appendRecipe(I2);
5658
VPBB1.appendRecipe(I3);
@@ -65,12 +67,12 @@ TEST(VPInstructionTest, eraseFromParent) {
6567
EXPECT_TRUE(VPBB1.empty());
6668
}
6769

68-
TEST(VPInstructionTest, moveAfter) {
70+
TEST_F(VPInstructionTest, moveAfter) {
6971
VPInstruction *I1 = new VPInstruction(0, {});
7072
VPInstruction *I2 = new VPInstruction(1, {});
7173
VPInstruction *I3 = new VPInstruction(2, {});
7274

73-
VPBasicBlock VPBB1;
75+
VPBasicBlock &VPBB1 = *getPlan().createVPBasicBlock("");
7476
VPBB1.appendRecipe(I1);
7577
VPBB1.appendRecipe(I2);
7678
VPBB1.appendRecipe(I3);
@@ -81,7 +83,7 @@ TEST(VPInstructionTest, moveAfter) {
8183

8284
VPInstruction *I4 = new VPInstruction(4, {});
8385
VPInstruction *I5 = new VPInstruction(5, {});
84-
VPBasicBlock VPBB2;
86+
VPBasicBlock &VPBB2 = *getPlan().createVPBasicBlock("");
8587
VPBB2.appendRecipe(I4);
8688
VPBB2.appendRecipe(I5);
8789

@@ -92,12 +94,12 @@ TEST(VPInstructionTest, moveAfter) {
9294
EXPECT_EQ(I3->getParent(), I4->getParent());
9395
}
9496

95-
TEST(VPInstructionTest, moveBefore) {
97+
TEST_F(VPInstructionTest, moveBefore) {
9698
VPInstruction *I1 = new VPInstruction(0, {});
9799
VPInstruction *I2 = new VPInstruction(1, {});
98100
VPInstruction *I3 = new VPInstruction(2, {});
99101

100-
VPBasicBlock VPBB1;
102+
VPBasicBlock &VPBB1 = *getPlan().createVPBasicBlock("");
101103
VPBB1.appendRecipe(I1);
102104
VPBB1.appendRecipe(I2);
103105
VPBB1.appendRecipe(I3);
@@ -108,7 +110,7 @@ TEST(VPInstructionTest, moveBefore) {
108110

109111
VPInstruction *I4 = new VPInstruction(4, {});
110112
VPInstruction *I5 = new VPInstruction(5, {});
111-
VPBasicBlock VPBB2;
113+
VPBasicBlock &VPBB2 = *getPlan().createVPBasicBlock("");
112114
VPBB2.appendRecipe(I4);
113115
VPBB2.appendRecipe(I5);
114116

@@ -118,7 +120,7 @@ TEST(VPInstructionTest, moveBefore) {
118120
CHECK_ITERATOR(VPBB2, I3, I4, I5);
119121
EXPECT_EQ(I3->getParent(), I4->getParent());
120122

121-
VPBasicBlock VPBB3;
123+
VPBasicBlock &VPBB3 = *getPlan().createVPBasicBlock("");
122124

123125
I4->moveBefore(VPBB3, VPBB3.end());
124126

@@ -128,7 +130,7 @@ TEST(VPInstructionTest, moveBefore) {
128130
EXPECT_EQ(&VPBB3, I4->getParent());
129131
}
130132

131-
TEST(VPInstructionTest, setOperand) {
133+
TEST_F(VPInstructionTest, setOperand) {
132134
VPValue *VPV1 = new VPValue();
133135
VPValue *VPV2 = new VPValue();
134136
VPInstruction *I1 = new VPInstruction(0, {VPV1, VPV2});
@@ -174,7 +176,7 @@ TEST(VPInstructionTest, setOperand) {
174176
delete VPV4;
175177
}
176178

177-
TEST(VPInstructionTest, replaceAllUsesWith) {
179+
TEST_F(VPInstructionTest, replaceAllUsesWith) {
178180
VPValue *VPV1 = new VPValue();
179181
VPValue *VPV2 = new VPValue();
180182
VPInstruction *I1 = new VPInstruction(0, {VPV1, VPV2});
@@ -220,7 +222,7 @@ TEST(VPInstructionTest, replaceAllUsesWith) {
220222
delete VPV3;
221223
}
222224

223-
TEST(VPInstructionTest, releaseOperandsAtDeletion) {
225+
TEST_F(VPInstructionTest, releaseOperandsAtDeletion) {
224226
VPValue *VPV1 = new VPValue();
225227
VPValue *VPV2 = new VPValue();
226228
VPInstruction *I1 = new VPInstruction(0, {VPV1, VPV2});

0 commit comments

Comments
 (0)