@@ -205,11 +205,6 @@ VPBlockBase *VPBlockBase::getEnclosingBlockWithPredecessors() {
205
205
return Parent->getEnclosingBlockWithPredecessors ();
206
206
}
207
207
208
- void VPBlockBase::deleteCFG (VPBlockBase *Entry) {
209
- for (VPBlockBase *Block : to_vector (vp_depth_first_shallow (Entry)))
210
- delete Block;
211
- }
212
-
213
208
VPBasicBlock::iterator VPBasicBlock::getFirstNonPhi () {
214
209
iterator It = begin ();
215
210
while (It != end () && It->isPhi ())
@@ -474,6 +469,16 @@ void VPIRBasicBlock::execute(VPTransformState *State) {
474
469
connectToPredecessors (State->CFG );
475
470
}
476
471
472
+ VPIRBasicBlock *VPIRBasicBlock::clone () {
473
+ auto *NewBlock = getPlan ()->createVPIRBasicBlock (IRBB);
474
+ for (VPRecipeBase &R : make_early_inc_range (*NewBlock))
475
+ R.eraseFromParent ();
476
+
477
+ for (VPRecipeBase &R : Recipes)
478
+ NewBlock->appendRecipe (R.clone ());
479
+ return NewBlock;
480
+ }
481
+
477
482
void VPBasicBlock::execute (VPTransformState *State) {
478
483
bool Replica = bool (State->Lane );
479
484
BasicBlock *NewBB = State->CFG .PrevBB ; // Reuse it if possible.
@@ -523,6 +528,13 @@ void VPBasicBlock::dropAllReferences(VPValue *NewValue) {
523
528
}
524
529
}
525
530
531
+ VPBasicBlock *VPBasicBlock::clone () {
532
+ auto *NewBlock = getPlan ()->createVPBasicBlock (getName ());
533
+ for (VPRecipeBase &R : *this )
534
+ NewBlock->appendRecipe (R.clone ());
535
+ return NewBlock;
536
+ }
537
+
526
538
void VPBasicBlock::executeRecipes (VPTransformState *State, BasicBlock *BB) {
527
539
LLVM_DEBUG (dbgs () << " LV: vectorizing VPBB:" << getName ()
528
540
<< " in BB:" << BB->getName () << ' \n ' );
@@ -541,7 +553,7 @@ VPBasicBlock *VPBasicBlock::splitAt(iterator SplitAt) {
541
553
542
554
SmallVector<VPBlockBase *, 2 > Succs (successors ());
543
555
// Create new empty block after the block to split.
544
- auto *SplitBlock = new VPBasicBlock (getName () + " .split" );
556
+ auto *SplitBlock = getPlan ()-> createVPBasicBlock (getName () + " .split" );
545
557
VPBlockUtils::insertBlockAfter (SplitBlock, this );
546
558
547
559
// Finally, move the recipes starting at SplitAt to new block.
@@ -701,8 +713,8 @@ static std::pair<VPBlockBase *, VPBlockBase *> cloneFrom(VPBlockBase *Entry) {
701
713
702
714
VPRegionBlock *VPRegionBlock::clone () {
703
715
const auto &[NewEntry, NewExiting] = cloneFrom (getEntry ());
704
- auto *NewRegion =
705
- new VPRegionBlock (NewEntry, NewExiting, getName (), isReplicator ());
716
+ auto *NewRegion = getPlan ()-> createVPRegionBlock (NewEntry, NewExiting,
717
+ getName (), isReplicator ());
706
718
for (VPBlockBase *Block : vp_depth_first_shallow (NewEntry))
707
719
Block->setParent (NewRegion);
708
720
return NewRegion;
@@ -822,32 +834,27 @@ void VPRegionBlock::print(raw_ostream &O, const Twine &Indent,
822
834
#endif
823
835
824
836
VPlan::VPlan (Loop *L) {
825
- setEntry (VPIRBasicBlock::fromBasicBlock (L->getLoopPreheader ()));
826
- ScalarHeader = VPIRBasicBlock::fromBasicBlock (L->getHeader ());
837
+ setEntry (createVPIRBasicBlock (L->getLoopPreheader ()));
838
+ ScalarHeader = createVPIRBasicBlock (L->getHeader ());
827
839
}
828
840
829
841
VPlan::~VPlan () {
830
842
if (Entry) {
831
843
VPValue DummyValue;
832
- for (VPBlockBase *Block : vp_depth_first_shallow (Entry))
833
- Block->dropAllReferences (&DummyValue);
834
844
835
- VPBlockBase::deleteCFG (Entry);
845
+ for (auto *VPB : reverse (CreatedBlocks))
846
+ VPB->dropAllReferences (&DummyValue);
847
+
848
+ for (auto *VPB : reverse (CreatedBlocks)) {
849
+ delete VPB;
850
+ }
836
851
}
837
852
for (VPValue *VPV : VPLiveInsToFree)
838
853
delete VPV;
839
854
if (BackedgeTakenCount)
840
855
delete BackedgeTakenCount;
841
856
}
842
857
843
- VPIRBasicBlock *VPIRBasicBlock::fromBasicBlock (BasicBlock *IRBB) {
844
- auto *VPIRBB = new VPIRBasicBlock (IRBB);
845
- for (Instruction &I :
846
- make_range (IRBB->begin (), IRBB->getTerminator ()->getIterator ()))
847
- VPIRBB->appendRecipe (new VPIRInstruction (I));
848
- return VPIRBB;
849
- }
850
-
851
858
VPlanPtr VPlan::createInitialVPlan (Type *InductionTy,
852
859
PredicatedScalarEvolution &PSE,
853
860
bool RequiresScalarEpilogueCheck,
@@ -861,7 +868,7 @@ VPlanPtr VPlan::createInitialVPlan(Type *InductionTy,
861
868
// an epilogue vector loop, the original entry block here will be replaced by
862
869
// a new VPIRBasicBlock wrapping the entry to the epilogue vector loop after
863
870
// generating code for the main vector loop.
864
- VPBasicBlock *VecPreheader = new VPBasicBlock (" vector.ph" );
871
+ VPBasicBlock *VecPreheader = Plan-> createVPBasicBlock (" vector.ph" );
865
872
VPBlockUtils::connectBlocks (Plan->getEntry (), VecPreheader);
866
873
867
874
// Create SCEV and VPValue for the trip count.
@@ -878,17 +885,17 @@ VPlanPtr VPlan::createInitialVPlan(Type *InductionTy,
878
885
879
886
// Create VPRegionBlock, with empty header and latch blocks, to be filled
880
887
// during processing later.
881
- VPBasicBlock *HeaderVPBB = new VPBasicBlock (" vector.body" );
882
- VPBasicBlock *LatchVPBB = new VPBasicBlock (" vector.latch" );
888
+ VPBasicBlock *HeaderVPBB = Plan-> createVPBasicBlock (" vector.body" );
889
+ VPBasicBlock *LatchVPBB = Plan-> createVPBasicBlock (" vector.latch" );
883
890
VPBlockUtils::insertBlockAfter (LatchVPBB, HeaderVPBB);
884
- auto *TopRegion = new VPRegionBlock (HeaderVPBB, LatchVPBB, " vector loop " ,
885
- false /* isReplicator*/ );
891
+ auto *TopRegion = Plan-> createVPRegionBlock (
892
+ HeaderVPBB, LatchVPBB, " vector loop " , false /* isReplicator*/ );
886
893
887
894
VPBlockUtils::insertBlockAfter (TopRegion, VecPreheader);
888
- VPBasicBlock *MiddleVPBB = new VPBasicBlock (" middle.block" );
895
+ VPBasicBlock *MiddleVPBB = Plan-> createVPBasicBlock (" middle.block" );
889
896
VPBlockUtils::insertBlockAfter (MiddleVPBB, TopRegion);
890
897
891
- VPBasicBlock *ScalarPH = new VPBasicBlock (" scalar.ph" );
898
+ VPBasicBlock *ScalarPH = Plan-> createVPBasicBlock (" scalar.ph" );
892
899
VPBlockUtils::connectBlocks (ScalarPH, ScalarHeader);
893
900
if (!RequiresScalarEpilogueCheck) {
894
901
VPBlockUtils::connectBlocks (MiddleVPBB, ScalarPH);
@@ -904,7 +911,7 @@ VPlanPtr VPlan::createInitialVPlan(Type *InductionTy,
904
911
// we unconditionally branch to the scalar preheader. Do nothing.
905
912
// 3) Otherwise, construct a runtime check.
906
913
BasicBlock *IRExitBlock = TheLoop->getUniqueLatchExitBlock ();
907
- auto *VPExitBlock = VPIRBasicBlock::fromBasicBlock (IRExitBlock);
914
+ auto *VPExitBlock = Plan-> createVPIRBasicBlock (IRExitBlock);
908
915
// The connection order corresponds to the operands of the conditional branch.
909
916
VPBlockUtils::insertBlockAfter (VPExitBlock, MiddleVPBB);
910
917
VPBlockUtils::connectBlocks (MiddleVPBB, ScalarPH);
@@ -960,15 +967,13 @@ void VPlan::prepareToExecute(Value *TripCountV, Value *VectorTripCountV,
960
967
// / have a single predecessor, which is rewired to the new VPIRBasicBlock. All
961
968
// / successors of VPBB, if any, are rewired to the new VPIRBasicBlock.
962
969
static void replaceVPBBWithIRVPBB (VPBasicBlock *VPBB, BasicBlock *IRBB) {
963
- VPIRBasicBlock *IRVPBB = VPIRBasicBlock::fromBasicBlock (IRBB);
970
+ VPIRBasicBlock *IRVPBB = VPBB-> getPlan ()-> createVPIRBasicBlock (IRBB);
964
971
for (auto &R : make_early_inc_range (*VPBB)) {
965
972
assert (!R.isPhi () && " Tried to move phi recipe to end of block" );
966
973
R.moveBefore (*IRVPBB, IRVPBB->end ());
967
974
}
968
975
969
976
VPBlockUtils::reassociateBlocks (VPBB, IRVPBB);
970
-
971
- delete VPBB;
972
977
}
973
978
974
979
// / Generate the code inside the preheader and body of the vectorized loop.
@@ -1217,6 +1222,7 @@ static void remapOperands(VPBlockBase *Entry, VPBlockBase *NewEntry,
1217
1222
}
1218
1223
1219
1224
VPlan *VPlan::duplicate () {
1225
+ unsigned CreatedBlockSize = CreatedBlocks.size ();
1220
1226
// Clone blocks.
1221
1227
const auto &[NewEntry, __] = cloneFrom (Entry);
1222
1228
@@ -1257,9 +1263,23 @@ VPlan *VPlan::duplicate() {
1257
1263
assert (Old2NewVPValues.contains (TripCount) &&
1258
1264
" TripCount must have been added to Old2NewVPValues" );
1259
1265
NewPlan->TripCount = Old2NewVPValues[TripCount];
1266
+
1267
+ for (unsigned I = CreatedBlockSize; I != CreatedBlocks.size (); ++I)
1268
+ NewPlan->CreatedBlocks .push_back (CreatedBlocks[I]);
1269
+ CreatedBlocks.truncate (CreatedBlockSize);
1270
+
1260
1271
return NewPlan;
1261
1272
}
1262
1273
1274
+ VPIRBasicBlock *VPlan::createVPIRBasicBlock (BasicBlock *IRBB) {
1275
+ auto *VPIRBB = new VPIRBasicBlock (IRBB);
1276
+ for (Instruction &I :
1277
+ make_range (IRBB->begin (), IRBB->getTerminator ()->getIterator ()))
1278
+ VPIRBB->appendRecipe (new VPIRInstruction (I));
1279
+ CreatedBlocks.push_back (VPIRBB);
1280
+ return VPIRBB;
1281
+ }
1282
+
1263
1283
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1264
1284
1265
1285
Twine VPlanPrinter::getUID (const VPBlockBase *Block) {
0 commit comments