[VPlan] Make VPBlock constructors private (NFC).

16d19aaed 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.
This commit is contained in:
Florian Hahn
2025-01-15 21:34:23 +00:00
parent e9255dda23
commit ef1260acc0
2 changed files with 33 additions and 22 deletions

View File

@@ -3526,6 +3526,15 @@ public:
/// holds a sequence of zero or more VPRecipe's each representing a sequence of
/// output IR instructions. All PHI-like recipes must come before any non-PHI recipes.
class VPBasicBlock : public VPBlockBase {
friend class VPlan;
/// Use VPlan::createVPBasicBlock to create VPBasicBlocks.
VPBasicBlock(const Twine &Name = "", VPRecipeBase *Recipe = nullptr)
: VPBlockBase(VPBasicBlockSC, Name.str()) {
if (Recipe)
appendRecipe(Recipe);
}
public:
using RecipeListTy = iplist<VPRecipeBase>;
@@ -3537,12 +3546,6 @@ protected:
: VPBlockBase(BlockSC, Name.str()) {}
public:
VPBasicBlock(const Twine &Name = "", VPRecipeBase *Recipe = nullptr)
: VPBlockBase(VPBasicBlockSC, Name.str()) {
if (Recipe)
appendRecipe(Recipe);
}
~VPBasicBlock() override {
while (!Recipes.empty())
Recipes.pop_back();
@@ -3665,14 +3668,17 @@ private:
/// Note: At the moment, VPIRBasicBlock can only be used to wrap VPlan's
/// preheader block.
class VPIRBasicBlock : public VPBasicBlock {
friend class VPlan;
BasicBlock *IRBB;
public:
/// Use VPlan::createVPIRBasicBlock to create VPIRBasicBlocks.
VPIRBasicBlock(BasicBlock *IRBB)
: VPBasicBlock(VPIRBasicBlockSC,
(Twine("ir-bb<") + IRBB->getName() + Twine(">")).str()),
IRBB(IRBB) {}
public:
~VPIRBasicBlock() override {}
static inline bool classof(const VPBlockBase *V) {
@@ -3697,6 +3703,8 @@ public:
/// candidate VF's. The actual replication takes place only once the desired VF
/// and UF have been determined.
class VPRegionBlock : public VPBlockBase {
friend class VPlan;
/// Hold the Single Entry of the SESE region modelled by the VPRegionBlock.
VPBlockBase *Entry;
@@ -3708,7 +3716,7 @@ class VPRegionBlock : public VPBlockBase {
/// instances of output IR corresponding to its VPBlockBases.
bool IsReplicator;
public:
/// Use VPlan::createVPRegionBlock to create VPRegionBlocks.
VPRegionBlock(VPBlockBase *Entry, VPBlockBase *Exiting,
const std::string &Name = "", bool IsReplicator = false)
: VPBlockBase(VPRegionBlockSC, Name), Entry(Entry), Exiting(Exiting),
@@ -3722,6 +3730,7 @@ public:
: VPBlockBase(VPRegionBlockSC, Name), Entry(nullptr), Exiting(nullptr),
IsReplicator(IsReplicator) {}
public:
~VPRegionBlock() override {}
/// Method to support type inquiry through isa, cast, and dyn_cast.

View File

@@ -30,12 +30,14 @@ namespace {
EXPECT_EQ(&std::get<0>(Pair), std::get<1>(Pair)); \
} while (0)
TEST(VPInstructionTest, insertBefore) {
using VPInstructionTest = VPlanTestBase;
TEST_F(VPInstructionTest, insertBefore) {
VPInstruction *I1 = new VPInstruction(0, {});
VPInstruction *I2 = new VPInstruction(1, {});
VPInstruction *I3 = new VPInstruction(2, {});
VPBasicBlock VPBB1;
VPBasicBlock &VPBB1 = *getPlan().createVPBasicBlock("");
VPBB1.appendRecipe(I1);
I2->insertBefore(I1);
@@ -45,12 +47,12 @@ TEST(VPInstructionTest, insertBefore) {
CHECK_ITERATOR(VPBB1, I3, I2, I1);
}
TEST(VPInstructionTest, eraseFromParent) {
TEST_F(VPInstructionTest, eraseFromParent) {
VPInstruction *I1 = new VPInstruction(0, {});
VPInstruction *I2 = new VPInstruction(1, {});
VPInstruction *I3 = new VPInstruction(2, {});
VPBasicBlock VPBB1;
VPBasicBlock &VPBB1 = *getPlan().createVPBasicBlock("");
VPBB1.appendRecipe(I1);
VPBB1.appendRecipe(I2);
VPBB1.appendRecipe(I3);
@@ -65,12 +67,12 @@ TEST(VPInstructionTest, eraseFromParent) {
EXPECT_TRUE(VPBB1.empty());
}
TEST(VPInstructionTest, moveAfter) {
TEST_F(VPInstructionTest, moveAfter) {
VPInstruction *I1 = new VPInstruction(0, {});
VPInstruction *I2 = new VPInstruction(1, {});
VPInstruction *I3 = new VPInstruction(2, {});
VPBasicBlock VPBB1;
VPBasicBlock &VPBB1 = *getPlan().createVPBasicBlock("");
VPBB1.appendRecipe(I1);
VPBB1.appendRecipe(I2);
VPBB1.appendRecipe(I3);
@@ -81,7 +83,7 @@ TEST(VPInstructionTest, moveAfter) {
VPInstruction *I4 = new VPInstruction(4, {});
VPInstruction *I5 = new VPInstruction(5, {});
VPBasicBlock VPBB2;
VPBasicBlock &VPBB2 = *getPlan().createVPBasicBlock("");
VPBB2.appendRecipe(I4);
VPBB2.appendRecipe(I5);
@@ -92,12 +94,12 @@ TEST(VPInstructionTest, moveAfter) {
EXPECT_EQ(I3->getParent(), I4->getParent());
}
TEST(VPInstructionTest, moveBefore) {
TEST_F(VPInstructionTest, moveBefore) {
VPInstruction *I1 = new VPInstruction(0, {});
VPInstruction *I2 = new VPInstruction(1, {});
VPInstruction *I3 = new VPInstruction(2, {});
VPBasicBlock VPBB1;
VPBasicBlock &VPBB1 = *getPlan().createVPBasicBlock("");
VPBB1.appendRecipe(I1);
VPBB1.appendRecipe(I2);
VPBB1.appendRecipe(I3);
@@ -108,7 +110,7 @@ TEST(VPInstructionTest, moveBefore) {
VPInstruction *I4 = new VPInstruction(4, {});
VPInstruction *I5 = new VPInstruction(5, {});
VPBasicBlock VPBB2;
VPBasicBlock &VPBB2 = *getPlan().createVPBasicBlock("");
VPBB2.appendRecipe(I4);
VPBB2.appendRecipe(I5);
@@ -118,7 +120,7 @@ TEST(VPInstructionTest, moveBefore) {
CHECK_ITERATOR(VPBB2, I3, I4, I5);
EXPECT_EQ(I3->getParent(), I4->getParent());
VPBasicBlock VPBB3;
VPBasicBlock &VPBB3 = *getPlan().createVPBasicBlock("");
I4->moveBefore(VPBB3, VPBB3.end());
@@ -128,7 +130,7 @@ TEST(VPInstructionTest, moveBefore) {
EXPECT_EQ(&VPBB3, I4->getParent());
}
TEST(VPInstructionTest, setOperand) {
TEST_F(VPInstructionTest, setOperand) {
VPValue *VPV1 = new VPValue();
VPValue *VPV2 = new VPValue();
VPInstruction *I1 = new VPInstruction(0, {VPV1, VPV2});
@@ -174,7 +176,7 @@ TEST(VPInstructionTest, setOperand) {
delete VPV4;
}
TEST(VPInstructionTest, replaceAllUsesWith) {
TEST_F(VPInstructionTest, replaceAllUsesWith) {
VPValue *VPV1 = new VPValue();
VPValue *VPV2 = new VPValue();
VPInstruction *I1 = new VPInstruction(0, {VPV1, VPV2});
@@ -220,7 +222,7 @@ TEST(VPInstructionTest, replaceAllUsesWith) {
delete VPV3;
}
TEST(VPInstructionTest, releaseOperandsAtDeletion) {
TEST_F(VPInstructionTest, releaseOperandsAtDeletion) {
VPValue *VPV1 = new VPValue();
VPValue *VPV2 = new VPValue();
VPInstruction *I1 = new VPInstruction(0, {VPV1, VPV2});