Skip to content

Commit 5ca3794

Browse files
committed
[VPlan] Move initial VPlan block creation to constructor. (NFC)
This sets up the initial blocks needed to initialize a VPlan directly in the constructor. This will allow tracking of all created blocks directly in VPlan, simplifying block deletion.
1 parent 08aa956 commit 5ca3794

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,11 @@ void VPRegionBlock::print(raw_ostream &O, const Twine &Indent,
821821
}
822822
#endif
823823

824+
VPlan::VPlan(Loop *L) {
825+
setEntry(VPIRBasicBlock::fromBasicBlock(L->getLoopPreheader()));
826+
ScalarHeader = VPIRBasicBlock::fromBasicBlock(L->getHeader());
827+
}
828+
824829
VPlan::~VPlan() {
825830
if (Entry) {
826831
VPValue DummyValue;
@@ -847,19 +852,17 @@ VPlanPtr VPlan::createInitialVPlan(Type *InductionTy,
847852
PredicatedScalarEvolution &PSE,
848853
bool RequiresScalarEpilogueCheck,
849854
bool TailFolded, Loop *TheLoop) {
850-
VPIRBasicBlock *Entry =
851-
VPIRBasicBlock::fromBasicBlock(TheLoop->getLoopPreheader());
852-
VPBasicBlock *VecPreheader = new VPBasicBlock("vector.ph");
855+
auto Plan = std::make_unique<VPlan>(TheLoop);
856+
VPBlockBase *ScalarHeader = Plan->getScalarHeader();
857+
853858
// Connect entry only to vector preheader initially. Entry will also be
854859
// connected to the scalar preheader later, during skeleton creation when
855860
// runtime guards are added as needed. Note that when executing the VPlan for
856861
// an epilogue vector loop, the original entry block here will be replaced by
857862
// a new VPIRBasicBlock wrapping the entry to the epilogue vector loop after
858863
// generating code for the main vector loop.
859-
VPBlockUtils::connectBlocks(Entry, VecPreheader);
860-
VPIRBasicBlock *ScalarHeader =
861-
VPIRBasicBlock::fromBasicBlock(TheLoop->getHeader());
862-
auto Plan = std::make_unique<VPlan>(Entry, ScalarHeader);
864+
VPBasicBlock *VecPreheader = new VPBasicBlock("vector.ph");
865+
VPBlockUtils::connectBlocks(Plan->getEntry(), VecPreheader);
863866

864867
// Create SCEV and VPValue for the trip count.
865868
// We use the symbolic max backedge-taken-count, which works also when

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,6 +3829,11 @@ class VPlan {
38293829
TripCount = TC;
38303830
}
38313831

3832+
/// Construct a VPlan for \p L. This will create VPIRBasicBlocks wrapping the
3833+
/// original preheader and scalar header of \p L, to be used as entry and
3834+
/// scalar header blocks of the new VPlan.
3835+
VPlan(Loop *L);
3836+
38323837
~VPlan();
38333838

38343839
void setEntry(VPBasicBlock *VPBB) {

0 commit comments

Comments
 (0)