Skip to content

Commit d57ee93

Browse files
committed
[VPlan] Move auxiliary declarations out of VPlan.h (NFC).
Nothing in VPlan.h directly depends on VPTransformState, VPCostContext, VPFRange, VPlanPrinter or VPSlotTracker. Move them out to a separate header to reduce the size of widely used VPlan.h. This is a first step towards more cleanly separating declarations in VPlan. Besides reducing VPlan.h's size, this also allows including additional VPlan-related headers in VPlanHelpers.h for use there. An example is using VPDominatorTree in VPTransformState (llvm#117138).
1 parent 05fbc38 commit d57ee93

File tree

13 files changed

+718
-631
lines changed

13 files changed

+718
-631
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class OptimizationRemarkEmitter;
4040
class TargetTransformInfo;
4141
class TargetLibraryInfo;
4242
class VPRecipeBuilder;
43+
struct VFRange;
4344

4445
/// VPlan-based builder utility analogous to IRBuilder.
4546
class VPBuilder {

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "VPlan.h"
6060
#include "VPlanAnalysis.h"
6161
#include "VPlanHCFGBuilder.h"
62+
#include "VPlanHelpers.h"
6263
#include "VPlanPatternMatch.h"
6364
#include "VPlanTransforms.h"
6465
#include "VPlanUtils.h"

llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class LoopVectorizationCostModel;
2323
class TargetLibraryInfo;
2424
class TargetTransformInfo;
2525
struct HistogramInfo;
26+
struct VFRange;
2627

2728
/// A chain of instructions that form a partial reduction.
2829
/// Designed to match: reduction_bin_op (bin_op (extend (A), (extend (B))),

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 13 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "VPlan.h"
2020
#include "LoopVectorizationPlanner.h"
2121
#include "VPlanCFG.h"
22+
#include "VPlanHelpers.h"
2223
#include "VPlanPatternMatch.h"
2324
#include "VPlanTransforms.h"
2425
#include "VPlanUtils.h"
@@ -400,8 +401,8 @@ void VPTransformState::packScalarIntoVectorValue(VPValue *Def,
400401
set(Def, VectorValue);
401402
}
402403

403-
BasicBlock *
404-
VPBasicBlock::createEmptyBasicBlock(VPTransformState::CFGState &CFG) {
404+
BasicBlock *VPBasicBlock::createEmptyBasicBlock(VPTransformState &State) {
405+
auto &CFG = State.CFG;
405406
// BB stands for IR BasicBlocks. VPBB stands for VPlan VPBasicBlocks.
406407
// Pred stands for Predessor. Prev stands for Previous - last visited/created.
407408
BasicBlock *PrevBB = CFG.PrevBB;
@@ -412,7 +413,8 @@ VPBasicBlock::createEmptyBasicBlock(VPTransformState::CFGState &CFG) {
412413
return NewBB;
413414
}
414415

415-
void VPBasicBlock::connectToPredecessors(VPTransformState::CFGState &CFG) {
416+
void VPBasicBlock::connectToPredecessors(VPTransformState &State) {
417+
auto &CFG = State.CFG;
416418
BasicBlock *NewBB = CFG.VPBB2IRBB[this];
417419
// Hook up the new basic block to its predecessors.
418420
for (VPBlockBase *PredVPBlock : getHierarchicalPredecessors()) {
@@ -467,7 +469,7 @@ void VPIRBasicBlock::execute(VPTransformState *State) {
467469
"other blocks must be terminated by a branch");
468470
}
469471

470-
connectToPredecessors(State->CFG);
472+
connectToPredecessors(*State);
471473
}
472474

473475
VPIRBasicBlock *VPIRBasicBlock::clone() {
@@ -494,7 +496,7 @@ void VPBasicBlock::execute(VPTransformState *State) {
494496
// * the exit of a replicate region.
495497
State->CFG.VPBB2IRBB[this] = NewBB;
496498
} else {
497-
NewBB = createEmptyBasicBlock(State->CFG);
499+
NewBB = createEmptyBasicBlock(*State);
498500

499501
State->Builder.SetInsertPoint(NewBB);
500502
// Temporarily terminate with unreachable until CFG is rewired.
@@ -507,7 +509,7 @@ void VPBasicBlock::execute(VPTransformState *State) {
507509

508510
State->CFG.PrevBB = NewBB;
509511
State->CFG.VPBB2IRBB[this] = NewBB;
510-
connectToPredecessors(State->CFG);
512+
connectToPredecessors(*State);
511513
}
512514

513515
// 2. Fill the IR basic block with IR instructions.
@@ -616,6 +618,11 @@ bool VPBasicBlock::isExiting() const {
616618
}
617619

618620
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
621+
void VPBlockBase::print(raw_ostream &O) const {
622+
VPSlotTracker SlotTracker(getPlan());
623+
print(O, "", SlotTracker);
624+
}
625+
619626
void VPBlockBase::printSuccessors(raw_ostream &O, const Twine &Indent) const {
620627
if (getSuccessors().empty()) {
621628
O << Indent << "No successors\n";
@@ -1460,58 +1467,6 @@ void VPUser::printOperands(raw_ostream &O, VPSlotTracker &SlotTracker) const {
14601467
}
14611468
#endif
14621469

1463-
void VPInterleavedAccessInfo::visitRegion(VPRegionBlock *Region,
1464-
Old2NewTy &Old2New,
1465-
InterleavedAccessInfo &IAI) {
1466-
ReversePostOrderTraversal<VPBlockShallowTraversalWrapper<VPBlockBase *>>
1467-
RPOT(Region->getEntry());
1468-
for (VPBlockBase *Base : RPOT) {
1469-
visitBlock(Base, Old2New, IAI);
1470-
}
1471-
}
1472-
1473-
void VPInterleavedAccessInfo::visitBlock(VPBlockBase *Block, Old2NewTy &Old2New,
1474-
InterleavedAccessInfo &IAI) {
1475-
if (VPBasicBlock *VPBB = dyn_cast<VPBasicBlock>(Block)) {
1476-
for (VPRecipeBase &VPI : *VPBB) {
1477-
if (isa<VPWidenPHIRecipe>(&VPI))
1478-
continue;
1479-
assert(isa<VPInstruction>(&VPI) && "Can only handle VPInstructions");
1480-
auto *VPInst = cast<VPInstruction>(&VPI);
1481-
1482-
auto *Inst = dyn_cast_or_null<Instruction>(VPInst->getUnderlyingValue());
1483-
if (!Inst)
1484-
continue;
1485-
auto *IG = IAI.getInterleaveGroup(Inst);
1486-
if (!IG)
1487-
continue;
1488-
1489-
auto NewIGIter = Old2New.find(IG);
1490-
if (NewIGIter == Old2New.end())
1491-
Old2New[IG] = new InterleaveGroup<VPInstruction>(
1492-
IG->getFactor(), IG->isReverse(), IG->getAlign());
1493-
1494-
if (Inst == IG->getInsertPos())
1495-
Old2New[IG]->setInsertPos(VPInst);
1496-
1497-
InterleaveGroupMap[VPInst] = Old2New[IG];
1498-
InterleaveGroupMap[VPInst]->insertMember(
1499-
VPInst, IG->getIndex(Inst),
1500-
Align(IG->isReverse() ? (-1) * int(IG->getFactor())
1501-
: IG->getFactor()));
1502-
}
1503-
} else if (VPRegionBlock *Region = dyn_cast<VPRegionBlock>(Block))
1504-
visitRegion(Region, Old2New, IAI);
1505-
else
1506-
llvm_unreachable("Unsupported kind of VPBlock.");
1507-
}
1508-
1509-
VPInterleavedAccessInfo::VPInterleavedAccessInfo(VPlan &Plan,
1510-
InterleavedAccessInfo &IAI) {
1511-
Old2NewTy Old2New;
1512-
visitRegion(Plan.getVectorLoopRegion(), Old2New, IAI);
1513-
}
1514-
15151470
void VPSlotTracker::assignName(const VPValue *V) {
15161471
assert(!VPValue2Name.contains(V) && "VPValue already has a name!");
15171472
auto *UV = V->getUnderlyingValue();

0 commit comments

Comments
 (0)