@@ -655,22 +655,38 @@ static std::pair<VPBlockBase *, VPBlockBase *> cloneSESE(VPBlockBase *Entry);
655
655
// cloned region.
656
656
static std::pair<VPBlockBase *, VPBlockBase *> cloneSESE (VPBlockBase *Entry) {
657
657
DenseMap<VPBlockBase *, VPBlockBase *> Old2NewVPBlocks;
658
- ReversePostOrderTraversal<VPBlockShallowTraversalWrapper< VPBlockBase *>> RPOT (
659
- Entry);
660
- for (VPBlockBase *BB : RPOT ) {
658
+ VPBlockBase *Exiting = nullptr ;
659
+ // First, clone blocks reachable from Entry.
660
+ for (VPBlockBase *BB : vp_depth_first_shallow (Entry) ) {
661
661
VPBlockBase *NewBB = BB->clone ();
662
- for (VPBlockBase *Pred : BB->getPredecessors ())
663
- VPBlockUtils::connectBlocks (Old2NewVPBlocks[Pred], NewBB);
664
-
665
662
Old2NewVPBlocks[BB] = NewBB;
663
+ if (BB->getNumSuccessors () == 0 ) {
664
+ assert (!Exiting && " Multiple exiting blocks?" );
665
+ Exiting = BB;
666
+ }
667
+ }
668
+
669
+ // Second, update the predecessors & successors of the cloned blocks.
670
+ for (VPBlockBase *BB : vp_depth_first_shallow (Entry)) {
671
+ VPBlockBase *NewBB = Old2NewVPBlocks[BB];
672
+ SmallVector<VPBlockBase *> NewPreds;
673
+ for (VPBlockBase *Pred : BB->getPredecessors ()) {
674
+ NewPreds.push_back (Old2NewVPBlocks[Pred]);
675
+ }
676
+ NewBB->setPredecessors (NewPreds);
677
+ SmallVector<VPBlockBase *> NewSuccs;
678
+ for (VPBlockBase *Succ : BB->successors ()) {
679
+ NewSuccs.push_back (Old2NewVPBlocks[Succ]);
680
+ }
681
+ NewBB->setSuccessors (NewSuccs);
666
682
}
667
683
668
684
#if !defined(NDEBUG)
669
685
// Verify that the order of predecessors and successors matches in the cloned
670
686
// version.
671
- ReversePostOrderTraversal<VPBlockShallowTraversalWrapper<VPBlockBase *>>
672
- NewRPOT (Old2NewVPBlocks[ Entry]);
673
- for ( const auto &[OldBB, NewBB] : zip (RPOT, NewRPOT )) {
687
+ for ( const auto &[OldBB, NewBB] :
688
+ zip ( vp_depth_first_shallow ( Entry),
689
+ vp_depth_first_shallow (Old2NewVPBlocks[Entry]) )) {
674
690
for (const auto &[OldPred, NewPred] :
675
691
zip (OldBB->getPredecessors (), NewBB->getPredecessors ()))
676
692
assert (NewPred == Old2NewVPBlocks[OldPred] && " Different predecessors" );
@@ -681,8 +697,7 @@ static std::pair<VPBlockBase *, VPBlockBase *> cloneSESE(VPBlockBase *Entry) {
681
697
}
682
698
#endif
683
699
684
- return std::make_pair (Old2NewVPBlocks[Entry],
685
- Old2NewVPBlocks[*reverse (RPOT).begin ()]);
700
+ return std::make_pair (Old2NewVPBlocks[Entry], Old2NewVPBlocks[Exiting]);
686
701
}
687
702
688
703
VPRegionBlock *VPRegionBlock::clone () {
0 commit comments