Skip to content

Commit

Permalink
[VPlan] Always create initial blocks in constructor (NFC).
Browse files Browse the repository at this point in the history
Update C++ unit tests to use VPlanTestBase to construct initial VPlan,
using a constructor that creates the VP blocks directly in the
constructor.

Split off from and in preparation for
#120918.
  • Loading branch information
fhahn committed Dec 27, 2024
1 parent 91bbebc commit 8caeb2e
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 245 deletions.
17 changes: 9 additions & 8 deletions llvm/lib/Transforms/Vectorize/VPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -3863,7 +3863,6 @@ class VPlan {
/// been modeled in VPlan directly.
DenseMap<const SCEV *, VPValue *> SCEVToExpansion;

public:
/// Construct a VPlan with \p Entry to the plan and with \p ScalarHeader
/// wrapping the original header of the scalar loop.
VPlan(VPBasicBlock *Entry, VPIRBasicBlock *ScalarHeader)
Expand All @@ -3873,18 +3872,20 @@ class VPlan {
"scalar header must be a leaf node");
}

/// Construct a VPlan with \p Entry entering the plan, trip count \p TC and
/// with \p ScalarHeader wrapping the original header of the scalar loop.
VPlan(VPBasicBlock *Entry, VPValue *TC, VPIRBasicBlock *ScalarHeader)
: VPlan(Entry, ScalarHeader) {
TripCount = TC;
}

public:
/// Construct a VPlan for \p L. This will create VPIRBasicBlocks wrapping the
/// original preheader and scalar header of \p L, to be used as entry and
/// scalar header blocks of the new VPlan.
VPlan(Loop *L);

/// Construct a VPlan with a new VPBasicBlock as entry, a VPIRBasicBlock
/// wrapping \p ScalarHeaderBB and a trip count of \p TC.
VPlan(BasicBlock *ScalarHeaderBB, VPValue *TC) {
setEntry(new VPBasicBlock("preheader"));
ScalarHeader = VPIRBasicBlock::fromBasicBlock(ScalarHeaderBB);
TripCount = TC;
}

~VPlan();

void setEntry(VPBasicBlock *VPBB) {
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Vectorize/VPlanHCFGBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class Loop;
class LoopInfo;
class VPRegionBlock;
class VPlan;
class VPlanTestBase;
class VPlanTestIRBase;

/// Main class to build the VPlan H-CFG for an incoming IR.
class VPlanHCFGBuilder {
friend VPlanTestBase;
friend VPlanTestIRBase;

private:
// The outermost loop of the input loop nest considered for vectorization.
Expand Down
42 changes: 15 additions & 27 deletions llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@

#include "../lib/Transforms/Vectorize/VPlan.h"
#include "../lib/Transforms/Vectorize/VPlanDominatorTree.h"
#include "VPlanTestBase.h"
#include "gtest/gtest.h"

namespace llvm {
namespace {

TEST(VPDominatorTreeTest, DominanceNoRegionsTest) {
using VPDominatorTreeTest = VPlanTestBase;

TEST_F(VPDominatorTreeTest, DominanceNoRegionsTest) {
// VPBB0
// |
// R1 {
Expand All @@ -24,8 +27,8 @@ TEST(VPDominatorTreeTest, DominanceNoRegionsTest) {
// \ /
// VPBB4
// }
VPBasicBlock *VPPH = new VPBasicBlock("ph");
VPBasicBlock *VPBB0 = new VPBasicBlock("VPBB0");
VPlan &Plan = getPlan();
VPBasicBlock *VPBB0 = Plan.getEntry();
VPBasicBlock *VPBB1 = new VPBasicBlock("VPBB1");
VPBasicBlock *VPBB2 = new VPBasicBlock("VPBB2");
VPBasicBlock *VPBB3 = new VPBasicBlock("VPBB3");
Expand All @@ -40,12 +43,7 @@ TEST(VPDominatorTreeTest, DominanceNoRegionsTest) {
VPBlockUtils::connectBlocks(VPBB2, VPBB4);
VPBlockUtils::connectBlocks(VPBB3, VPBB4);

LLVMContext C;
auto *ScalarHeader = BasicBlock::Create(C, "");
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
VPBlockUtils::connectBlocks(R1, ScalarHeaderVPBB);
VPBlockUtils::connectBlocks(VPPH, VPBB0);
VPlan Plan(VPPH, ScalarHeaderVPBB);
VPBlockUtils::connectBlocks(R1, Plan.getScalarHeader());

VPDominatorTree VPDT;
VPDT.recalculate(Plan);
Expand All @@ -62,7 +60,6 @@ TEST(VPDominatorTreeTest, DominanceNoRegionsTest) {
EXPECT_EQ(VPDT.findNearestCommonDominator(VPBB2, VPBB3), VPBB1);
EXPECT_EQ(VPDT.findNearestCommonDominator(VPBB2, VPBB4), VPBB1);
EXPECT_EQ(VPDT.findNearestCommonDominator(VPBB4, VPBB4), VPBB4);
delete ScalarHeader;
}

static void
Expand All @@ -76,9 +73,7 @@ checkDomChildren(VPDominatorTree &VPDT, VPBlockBase *Src,
EXPECT_EQ(Children, ExpectedNodes);
}

TEST(VPDominatorTreeTest, DominanceRegionsTest) {
LLVMContext C;
auto *ScalarHeader = BasicBlock::Create(C, "");
TEST_F(VPDominatorTreeTest, DominanceRegionsTest) {
{
// 2 consecutive regions.
// VPBB0
Expand All @@ -99,8 +94,8 @@ TEST(VPDominatorTreeTest, DominanceRegionsTest) {
// R2BB2
// }
//
VPBasicBlock *VPPH = new VPBasicBlock("ph");
VPBasicBlock *VPBB0 = new VPBasicBlock("VPBB0");
VPlan &Plan = getPlan();
VPBasicBlock *VPBB0 = Plan.getEntry();
VPBasicBlock *R1BB1 = new VPBasicBlock();
VPBasicBlock *R1BB2 = new VPBasicBlock();
VPBasicBlock *R1BB3 = new VPBasicBlock();
Expand All @@ -122,10 +117,7 @@ TEST(VPDominatorTreeTest, DominanceRegionsTest) {
VPBlockUtils::connectBlocks(R2BB1, R2BB2);
VPBlockUtils::connectBlocks(R1, R2);

VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
VPBlockUtils::connectBlocks(R2, ScalarHeaderVPBB);
VPBlockUtils::connectBlocks(VPPH, VPBB0);
VPlan Plan(VPPH, ScalarHeaderVPBB);
VPBlockUtils::connectBlocks(R2, Plan.getScalarHeader());
VPDominatorTree VPDT;
VPDT.recalculate(Plan);

Expand Down Expand Up @@ -177,7 +169,7 @@ TEST(VPDominatorTreeTest, DominanceRegionsTest) {
// |
// VPBB2
//
VPBasicBlock *VPPH = new VPBasicBlock("ph");
VPlan &Plan = getPlan();
VPBasicBlock *R1BB1 = new VPBasicBlock("R1BB1");
VPBasicBlock *R1BB2 = new VPBasicBlock("R1BB2");
VPBasicBlock *R1BB3 = new VPBasicBlock("R1BB3");
Expand All @@ -199,15 +191,12 @@ TEST(VPDominatorTreeTest, DominanceRegionsTest) {
VPBlockUtils::connectBlocks(R1BB2, R1BB3);
VPBlockUtils::connectBlocks(R2, R1BB3);

VPBasicBlock *VPBB1 = new VPBasicBlock("VPBB1");
VPBasicBlock *VPBB1 = Plan.getEntry();
VPBlockUtils::connectBlocks(VPBB1, R1);
VPBasicBlock *VPBB2 = new VPBasicBlock("VPBB2");
VPBlockUtils::connectBlocks(R1, VPBB2);

VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
VPBlockUtils::connectBlocks(VPBB2, ScalarHeaderVPBB);
VPBlockUtils::connectBlocks(VPPH, VPBB1);
VPlan Plan(VPPH, ScalarHeaderVPBB);
VPBlockUtils::connectBlocks(VPBB2, Plan.getScalarHeader());
VPDominatorTree VPDT;
VPDT.recalculate(Plan);

Expand All @@ -220,9 +209,8 @@ TEST(VPDominatorTreeTest, DominanceRegionsTest) {
checkDomChildren(VPDT, R2BB2, {R2BB3});
checkDomChildren(VPDT, R2BB3, {});
checkDomChildren(VPDT, R1BB3, {VPBB2});
checkDomChildren(VPDT, VPBB2, {ScalarHeaderVPBB});
checkDomChildren(VPDT, VPBB2, {Plan.getScalarHeader()});
}
delete ScalarHeader;
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/Transforms/Vectorize/VPlanHCFGTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace llvm {
namespace {

class VPlanHCFGTest : public VPlanTestBase {};
class VPlanHCFGTest : public VPlanTestIRBase {};

TEST_F(VPlanHCFGTest, testBuildHCFGInnerLoop) {
const char *ModuleString =
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/Transforms/Vectorize/VPlanSlpTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace llvm {
namespace {

class VPlanSlpTest : public VPlanTestBase {
class VPlanSlpTest : public VPlanTestIRBase {
protected:
TargetLibraryInfoImpl TLII;
TargetLibraryInfo TLI;
Expand Down
Loading

0 comments on commit 8caeb2e

Please sign in to comment.