@@ -1054,6 +1054,50 @@ BasicBlock *llvm::SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt,
10541054 return SplitBlockImpl (Old, SplitPt, DTU, /* DT=*/ nullptr , LI, MSSAU, BBName);
10551055}
10561056
1057+ BasicBlock *llvm::splitBlockBefore (BasicBlock *Old, BasicBlock::iterator SplitPt,
1058+ DomTreeUpdater *DTU, LoopInfo *LI,
1059+ MemorySSAUpdater *MSSAU,
1060+ const Twine &BBName) {
1061+
1062+ BasicBlock::iterator SplitIt = SplitPt;
1063+ while (isa<PHINode>(SplitIt) || SplitIt->isEHPad ())
1064+ ++SplitIt;
1065+ std::string Name = BBName.str ();
1066+ BasicBlock *New = Old->splitBasicBlockBefore (
1067+ SplitIt, Name.empty () ? Old->getName () + " .split" : Name);
1068+
1069+ // The new block lives in whichever loop the old one did. This preserves
1070+ // LCSSA as well, because we force the split point to be after any PHI nodes.
1071+ if (LI)
1072+ if (Loop *L = LI->getLoopFor (Old))
1073+ L->addBasicBlockToLoop (New, *LI);
1074+
1075+ if (DTU) {
1076+ SmallVector<DominatorTree::UpdateType, 8 > DTUpdates;
1077+ // New dominates Old. The predecessor nodes of the Old node dominate
1078+ // New node.
1079+ SmallPtrSet<BasicBlock *, 8 > UniquePredecessorsOfOld;
1080+ DTUpdates.push_back ({DominatorTree::Insert, New, Old});
1081+ DTUpdates.reserve (DTUpdates.size () + 2 * pred_size (New));
1082+ for (BasicBlock *PredecessorOfOld : predecessors (New))
1083+ if (UniquePredecessorsOfOld.insert (PredecessorOfOld).second ) {
1084+ DTUpdates.push_back ({DominatorTree::Insert, PredecessorOfOld, New});
1085+ DTUpdates.push_back ({DominatorTree::Delete, PredecessorOfOld, Old});
1086+ }
1087+
1088+ DTU->applyUpdates (DTUpdates);
1089+
1090+ // Move MemoryAccesses still tracked in Old, but part of New now.
1091+ // Update accesses in successor blocks accordingly.
1092+ if (MSSAU) {
1093+ MSSAU->applyUpdates (DTUpdates, DTU->getDomTree ());
1094+ if (VerifyMemorySSA)
1095+ MSSAU->getMemorySSA ()->verifyMemorySSA ();
1096+ }
1097+ }
1098+ return New;
1099+ }
1100+
10571101// / Update DominatorTree, LoopInfo, and LCCSA analysis information.
10581102// / Invalidates DFS Numbering when DTU or DT is provided.
10591103static void UpdateAnalysisInformation (BasicBlock *OldBB, BasicBlock *NewBB,
@@ -1168,25 +1212,6 @@ static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB,
11681212 }
11691213}
11701214
1171- BasicBlock *llvm::splitBlockBefore (BasicBlock *Old,
1172- BasicBlock::iterator SplitPt,
1173- DomTreeUpdater *DTU, LoopInfo *LI,
1174- MemorySSAUpdater *MSSAU,
1175- const Twine &BBName) {
1176- BasicBlock::iterator SplitIt = SplitPt;
1177- while (isa<PHINode>(SplitIt) || SplitIt->isEHPad ())
1178- ++SplitIt;
1179- SmallVector<BasicBlock *, 4 > Preds (predecessors (Old));
1180- BasicBlock *New = Old->splitBasicBlockBefore (
1181- SplitIt, BBName.isTriviallyEmpty () ? Old->getName () + " .split" : BBName);
1182-
1183- bool HasLoopExit = false ;
1184- UpdateAnalysisInformation (Old, New, Preds, DTU, nullptr , LI, MSSAU, false ,
1185- HasLoopExit);
1186-
1187- return New;
1188- }
1189-
11901215// / Update the PHI nodes in OrigBB to include the values coming from NewBB.
11911216// / This also updates AliasAnalysis, if available.
11921217static void UpdatePHINodes (BasicBlock *OrigBB, BasicBlock *NewBB,
0 commit comments