53#define DEBUG_TYPE "basicblock-utils"
57 cl::desc(
"Set the maximum path length when checking whether a basic block "
58 "is followed by a block that either has a terminating "
59 "deoptimizing call or is terminated with an unreachable"));
64 bool KeepOneInputPHIs) {
65 for (
auto *BB : BBs) {
70 Succ->removePredecessor(BB, KeepOneInputPHIs);
71 if (Updates && UniqueSuccessors.
insert(Succ).second)
72 Updates->
push_back({DominatorTree::Delete, BB, Succ});
76 while (!BB->empty()) {
85 BB->back().eraseFromParent();
89 isa<UnreachableInst>(BB->getTerminator()) &&
90 "The successor list of BB isn't empty before "
91 "applying corresponding DTU updates.");
96 bool KeepOneInputPHIs) {
101 bool KeepOneInputPHIs) {
105 assert(Dead.size() == BBs.
size() &&
"Duplicating blocks?");
106 for (
auto *BB : Dead)
108 assert(Dead.count(Pred) &&
"All predecessors must be dead!");
121 BB->eraseFromParent();
125 bool KeepOneInputPHIs) {
133 std::vector<BasicBlock*> DeadBlocks;
135 if (!Reachable.
count(&BB))
136 DeadBlocks.push_back(&BB);
141 return !DeadBlocks.empty();
146 if (!isa<PHINode>(BB->
begin()))
150 if (PN->getIncomingValue(0) != PN)
151 PN->replaceAllUsesWith(PN->getIncomingValue(0));
158 PN->eraseFromParent();
171 bool Changed =
false;
172 for (
unsigned i = 0, e = PHIs.
size(); i != e; ++i)
173 if (
PHINode *PN = dyn_cast_or_null<PHINode>(PHIs[i].
operator Value*()))
182 bool PredecessorWithTwoSuccessors,
189 if (!PredBB)
return false;
192 if (PredBB == BB)
return false;
207 unsigned FallThruPath;
208 if (PredecessorWithTwoSuccessors) {
209 if (!(PredBB_BI = dyn_cast<BranchInst>(PTI)))
215 FallThruPath = PredBB_BI->
getSuccessor(0) == BB ? 0 : 1;
228 if (isa<PHINode>(BB->
front())) {
230 if (!isa<PHINode>(PN.getIncomingValue(0)) ||
231 cast<PHINode>(PN.getIncomingValue(0))->getParent() != BB)
232 IncomingValues.
push_back(PN.getIncomingValue(0));
237 assert(!DTU &&
"cannot use both DT and DTU for updates");
241 assert(BBNode &&
"PredNode unreachable but BBNode reachable?");
243 C->setIDom(PredNode);
248 std::vector<DominatorTree::UpdateType> Updates;
250 assert(!DT &&
"cannot use both DT and DTU for updates");
255 Updates.reserve(Updates.size() + 2 *
succ_size(BB) + 1);
264 if (!SuccsOfPredBB.
contains(SuccOfBB))
265 if (SeenSuccs.
insert(SuccOfBB).second)
266 Updates.push_back({DominatorTree::Insert, PredBB, SuccOfBB});
269 if (SeenSuccs.
insert(SuccOfBB).second)
270 Updates.push_back({DominatorTree::Delete, BB, SuccOfBB});
271 Updates.push_back({DominatorTree::Delete, PredBB, BB});
291 if (PredecessorWithTwoSuccessors) {
328 "successors should have been transferred to PredBB");
341 assert(!MergeBlocks.
empty() &&
"MergeBlocks should not be empty");
343 bool BlocksHaveBeenMerged =
false;
344 while (!MergeBlocks.
empty()) {
347 if (Dest && (!L || L->
contains(Dest))) {
352 "Expecting BB to be unique predecessor of the Dest block");
353 MergeBlocks.
erase(Dest);
354 BlocksHaveBeenMerged =
true;
356 MergeBlocks.
erase(BB);
358 MergeBlocks.
erase(BB);
360 return BlocksHaveBeenMerged;
390 DVI->getExpression(),
391 DVI->getDebugLoc()->getInlinedAt());
392 auto R = VariableSet.
insert(Key);
398 if (
auto *DAI = dyn_cast<DbgAssignIntrinsic>(DVI)) {
417 for (
auto &Instr : ToBeRemoved)
418 Instr->eraseFromParent();
420 return !ToBeRemoved.
empty();
446 for (
auto &
I : *BB) {
449 DVI->getDebugLoc()->getInlinedAt());
450 auto VMI = VariableMap.
find(Key);
451 auto *DAI = dyn_cast<DbgAssignIntrinsic>(DVI);
459 if (VMI == VariableMap.
end() || VMI->second.first != Values ||
460 VMI->second.second != DVI->getExpression()) {
465 VariableMap[Key] = {Values, DVI->getExpression()};
467 VariableMap[Key] = {Values,
nullptr};
478 for (
auto &Instr : ToBeRemoved)
479 Instr->eraseFromParent();
481 return !ToBeRemoved.
empty();
510 DVI->getDebugLoc()->getInlinedAt());
515 for (
auto &
I : *BB) {
519 auto *DAI = dyn_cast<DbgAssignIntrinsic>(DVI);
522 if (!SeenDefForAggregate.
contains(Aggregate)) {
525 SeenDefForAggregate.
insert(Aggregate);
533 DAI->eraseFromParent();
535 return !ToBeRemoved.
empty();
539 bool MadeChanges =
false;
566 I.replaceAllUsesWith(V);
573 BI = BI->eraseFromParent();
578 assert(
I->getParent() ==
nullptr &&
579 "ReplaceInstWithInst: Instruction already inserted into basic block!");
583 if (!
I->getDebugLoc())
584 I->setDebugLoc(BI->getDebugLoc());
601 VisitedBlocks.
insert(BB).second) {
617 const Twine &BBName) {
640 assert(SP == BB &&
"CFG broken");
649 "Should have a single succ!");
654 if (
auto *II = dyn_cast<InvokeInst>(TI))
655 II->setUnwindDest(Succ);
656 else if (
auto *CS = dyn_cast<CatchSwitchInst>(TI))
657 CS->setUnwindDest(Succ);
658 else if (
auto *CR = dyn_cast<CleanupReturnInst>(TI))
659 CR->setUnwindDest(Succ);
678 if (PN.getIncomingBlock(BBIdx) != OldPred)
679 BBIdx = PN.getBasicBlockIndex(OldPred);
681 assert(BBIdx != -1 &&
"Invalid PHI Index!");
682 PN.setIncomingBlock(BBIdx, NewPred);
688 PHINode *LandingPadReplacement,
690 const Twine &BBName) {
693 if (!LandingPadReplacement && !PadInst->
isEHPad())
701 if (
Options.PreserveLoopSimplify && LI) {
702 if (
Loop *BBLoop = LI->getLoopFor(BB)) {
716 if (LI->getLoopFor(
P) != BBLoop) {
739 if (LandingPadReplacement) {
740 auto *NewLP = OriginalPad->
clone();
742 NewLP->insertBefore(Terminator);
745 Value *ParentPad =
nullptr;
746 if (
auto *FuncletPad = dyn_cast<FuncletPadInst>(PadInst))
747 ParentPad = FuncletPad->getParentPad();
748 else if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(PadInst))
749 ParentPad = CatchSwitch->getParentPad();
750 else if (
auto *CleanupPad = dyn_cast<CleanupPadInst>(PadInst))
751 ParentPad = CleanupPad->getParentPad();
752 else if (
auto *LandingPad = dyn_cast<LandingPadInst>(PadInst))
753 ParentPad = LandingPad->getParent();
770 Updates.
push_back({DominatorTree::Insert, BB, NewBB});
771 Updates.
push_back({DominatorTree::Insert, NewBB, Succ});
772 Updates.
push_back({DominatorTree::Delete, BB, Succ});
778 MSSAU->applyUpdates(Updates, *DT);
780 MSSAU->getMemorySSA()->verifyMemorySSA();
785 if (
Loop *BBLoop = LI->getLoopFor(BB)) {
788 if (
Loop *SuccLoop = LI->getLoopFor(Succ)) {
789 if (BBLoop == SuccLoop) {
791 SuccLoop->addBasicBlockToLoop(NewBB, *LI);
792 }
else if (BBLoop->contains(SuccLoop)) {
794 BBLoop->addBasicBlockToLoop(NewBB, *LI);
795 }
else if (SuccLoop->contains(BBLoop)) {
797 SuccLoop->addBasicBlockToLoop(NewBB, *LI);
803 assert(SuccLoop->getHeader() == Succ &&
804 "Should not create irreducible loops!");
805 if (
Loop *
P = SuccLoop->getParentLoop())
806 P->addBasicBlockToLoop(NewBB, *LI);
812 if (!BBLoop->contains(Succ)) {
813 assert(!BBLoop->contains(NewBB) &&
814 "Split point for loop exit is contained in loop!");
821 if (!LoopPreds.
empty()) {
823 Succ, LoopPreds,
"split", DT, LI, MSSAU,
Options.PreserveLCSSA);
839 "SplitBB has non-PHI nodes!");
843 int Idx = PN.getBasicBlockIndex(SplitBB);
844 assert(
Idx >= 0 &&
"Invalid Block Index");
845 Value *V = PN.getIncomingValue(
Idx);
849 if (
const PHINode *VP = dyn_cast<PHINode>(V))
850 if (VP->getParent() == SplitBB)
855 PN.getType(), Preds.
size(),
"split",
861 PN.setIncomingValue(
Idx, NewPN);
868 unsigned NumBroken = 0;
882 const Twine &BBName,
bool Before) {
884 DomTreeUpdater LocalDTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
886 DTU ? DTU : (DT ? &LocalDTU :
nullptr), LI, MSSAU,
890 while (isa<PHINode>(SplitIt) || SplitIt->isEHPad()) {
894 std::string
Name = BBName.
str();
902 L->addBasicBlockToLoop(New, *LI);
908 Updates.
push_back({DominatorTree::Insert, Old, New});
911 if (UniqueSuccessorsOfOld.
insert(SuccessorOfOld).second) {
912 Updates.
push_back({DominatorTree::Insert, New, SuccessorOfOld});
913 Updates.
push_back({DominatorTree::Delete, Old, SuccessorOfOld});
920 std::vector<DomTreeNode *> Children(OldNode->begin(), OldNode->end());
939 return SplitBlockImpl(Old, SplitPt,
nullptr, DT, LI, MSSAU, BBName,
946 return SplitBlockImpl(Old, SplitPt, DTU,
nullptr, LI, MSSAU, BBName,
953 const Twine &BBName) {
956 while (isa<PHINode>(SplitIt) || SplitIt->isEHPad())
958 std::string
Name = BBName.
str();
967 L->addBasicBlockToLoop(New, *LI);
974 DTUpdates.
push_back({DominatorTree::Insert, New, Old});
977 if (UniquePredecessorsOfOld.
insert(PredecessorOfOld).second) {
978 DTUpdates.
push_back({DominatorTree::Insert, PredecessorOfOld, New});
979 DTUpdates.
push_back({DominatorTree::Delete, PredecessorOfOld, Old});
1000 bool PreserveLCSSA,
bool &HasLoopExit) {
1014 Updates.
push_back({DominatorTree::Insert, NewBB, OldBB});
1016 for (
auto *Pred : Preds)
1017 if (UniquePreds.
insert(Pred).second) {
1018 Updates.
push_back({DominatorTree::Insert, Pred, NewBB});
1019 Updates.
push_back({DominatorTree::Delete, Pred, OldBB});
1043 assert(DT &&
"DT should be available to update LoopInfo!");
1048 bool IsLoopEntry = !!L;
1049 bool SplitMakesNewLoopHeader =
false;
1061 if (!PL->contains(OldBB))
1069 IsLoopEntry =
false;
1071 SplitMakesNewLoopHeader =
true;
1083 Loop *InnermostPredLoop =
nullptr;
1088 while (PredLoop && !PredLoop->contains(OldBB))
1092 if (PredLoop && PredLoop->contains(OldBB) &&
1093 (!InnermostPredLoop ||
1094 InnermostPredLoop->
getLoopDepth() < PredLoop->getLoopDepth()))
1095 InnermostPredLoop = PredLoop;
1099 if (InnermostPredLoop)
1103 if (SplitMakesNewLoopHeader)
1120 Value *InVal =
nullptr;
1166 if (PredSet.
count(IncomingBB)) {
1195 std::string NewName = std::string(Suffix) +
".split-lp";
1198 DTU, DT, LI, MSSAU, PreserveLCSSA);
1231 assert(!isa<IndirectBrInst>(Pred->getTerminator()) &&
1232 "Cannot split an edge from an IndirectBrInst");
1233 Pred->getTerminator()->replaceSuccessorWith(BB, NewBB);
1240 if (Preds.
empty()) {
1247 bool HasLoopExit =
false;
1251 if (!Preds.
empty()) {
1258 if (NewLatch != OldLatch) {
1276 bool PreserveLCSSA) {
1278 MSSAU, PreserveLCSSA);
1285 bool PreserveLCSSA) {
1287 nullptr, LI, MSSAU, PreserveLCSSA);
1313 assert(!isa<IndirectBrInst>(Pred->getTerminator()) &&
1314 "Cannot split an edge from an IndirectBrInst");
1315 Pred->getTerminator()->replaceUsesOfWith(OrigBB, NewBB1);
1318 bool HasLoopExit =
false;
1320 PreserveLCSSA, HasLoopExit);
1330 if (Pred == NewBB1)
continue;
1332 "Cannot split an edge from an IndirectBrInst");
1338 if (!NewBB2Preds.
empty()) {
1351 NewBB2Pred->getTerminator()->replaceUsesOfWith(OrigBB, NewBB2);
1354 HasLoopExit =
false;
1356 PreserveLCSSA, HasLoopExit);
1376 "Split cannot be applied if LPad is token type. Otherwise an "
1377 "invalid PHINode of token type would be created.");
1394 const char *Suffix1,
const char *Suffix2,
1398 bool PreserveLCSSA) {
1400 OrigBB, Preds, Suffix1, Suffix2, NewBBs,
1401 nullptr, DT, LI, MSSAU, PreserveLCSSA);
1405 const char *Suffix1,
const char *Suffix2,
1409 bool PreserveLCSSA) {
1411 NewBBs, DTU,
nullptr, LI, MSSAU,
1428 if (
BitCastInst *BCI = dyn_cast<BitCastInst>(V)) {
1431 V = BCI->getOperand(0);
1432 NewBC = BCI->
clone();
1439 V = EVI->getOperand(0);
1440 NewEV = EVI->
clone();
1450 if (
PHINode *PN = dyn_cast<PHINode>(V)) {
1451 if (PN->getParent() == BB) {
1453 NewEV->
setOperand(0, PN->getIncomingValueForBlock(Pred));
1455 NewBC->
setOperand(0, PN->getIncomingValueForBlock(Pred));
1457 Op = PN->getIncomingValueForBlock(Pred);
1468 DTU->
applyUpdates({{DominatorTree::Delete, Pred, BB}});
1470 return cast<ReturnInst>(NewRet);
1475 bool Unreachable,
MDNode *BranchWeights,
1486 if (UniqueSuccessorsOfHead.
insert(SuccessorOfHead).second) {
1487 Updates.
push_back({DominatorTree::Insert,
Tail, SuccessorOfHead});
1488 Updates.
push_back({DominatorTree::Delete, Head, SuccessorOfHead});
1494 bool CreateThenBlock = (ThenBlock ==
nullptr);
1495 if (CreateThenBlock) {
1502 Updates.
push_back({DominatorTree::Insert, ThenBlock,
Tail});
1510 Updates.
push_back({DominatorTree::Insert, Head, ThenBlock});
1511 HeadNewTerm->
setMetadata(LLVMContext::MD_prof, BranchWeights);
1518 std::vector<DomTreeNode *> Children(OldNode->begin(), OldNode->end());
1525 if (CreateThenBlock)
1534 L->addBasicBlockToLoop(ThenBlock, *LI);
1535 L->addBasicBlockToLoop(
Tail, *LI);
1550 nullptr, DT, LI, ThenBlock);
1559 BranchWeights, DTU,
nullptr, LI,
1580 (*ThenTerm)->setDebugLoc(SplitBefore->
getDebugLoc());
1582 (*ElseTerm)->setDebugLoc(SplitBefore->
getDebugLoc());
1585 HeadNewTerm->
setMetadata(LLVMContext::MD_prof, BranchWeights);
1589 Updates.
reserve(4 + 2 * UniqueOrigSuccessors.
size());
1591 Updates.
push_back({DominatorTree::Insert, Head, Succ});
1594 for (
BasicBlock *UniqueOrigSuccessor : UniqueOrigSuccessors)
1595 Updates.
push_back({DominatorTree::Insert,
Tail, UniqueOrigSuccessor});
1596 for (
BasicBlock *UniqueOrigSuccessor : UniqueOrigSuccessors)
1597 Updates.
push_back({DominatorTree::Delete, Head, UniqueOrigSuccessor});
1629 if (!Pred1Br || !Pred2Br)
1681 if (!BI)
return nullptr;
1707 while (
I != Out->
end() && isa<PHINode>(
I)) {
1708 auto Phi = cast<PHINode>(
I);
1711 Phi->getName() +
".moved", &FirstGuardBlock->
front());
1712 for (
auto *In : Incoming) {
1716 }
else if (Phi->getBasicBlockIndex(In) != -1) {
1717 V = Phi->removeIncomingValue(In,
false);
1719 NewPhi->addIncoming(V, In);
1721 assert(NewPhi->getNumIncomingValues() == Incoming.size());
1722 if (Phi->getNumOperands() == 0) {
1723 Phi->replaceAllUsesWith(NewPhi);
1724 I = Phi->eraseFromParent();
1727 Phi->addIncoming(NewPhi, GuardBlock);
1745static std::tuple<Value *, BasicBlock *, BasicBlock *>
1749 "Only support branch terminator.");
1751 auto Condition = Branch->isConditional() ? Branch->getCondition() :
nullptr;
1755 Succ0 = Outgoing.
count(Succ0) ? Succ0 :
nullptr;
1757 if (Branch->isUnconditional()) {
1758 Branch->setSuccessor(0, FirstGuardBlock);
1761 Succ1 = Branch->getSuccessor(1);
1762 Succ1 = Outgoing.
count(Succ1) ? Succ1 :
nullptr;
1764 if (Succ0 && !Succ1) {
1765 Branch->setSuccessor(0, FirstGuardBlock);
1766 }
else if (Succ1 && !Succ0) {
1767 Branch->setSuccessor(1, FirstGuardBlock);
1769 Branch->eraseFromParent();
1775 return std::make_tuple(Condition, Succ0, Succ1);
1792 for (
int i = 0, e = GuardBlocks.
size() - 1; i != e; ++i) {
1793 auto Out = Outgoing[i];
1809 auto FirstGuardBlock = GuardBlocks.
front();
1812 "merged.bb.idx", FirstGuardBlock);
1814 for (
auto In : Incoming) {
1818 std::tie(Condition, Succ0, Succ1) =
1820 Value *IncomingId =
nullptr;
1821 if (Succ0 && Succ1) {
1823 auto Succ0Iter =
find(Outgoing, Succ0);
1824 auto Succ1Iter =
find(Outgoing, Succ1);
1826 std::distance(Outgoing.
begin(), Succ0Iter));
1828 std::distance(Outgoing.
begin(), Succ1Iter));
1830 In->getTerminator());
1833 auto SuccIter = Succ0 ?
find(Outgoing, Succ0) :
find(Outgoing, Succ1);
1835 std::distance(Outgoing.
begin(), SuccIter));
1837 Phi->addIncoming(IncomingId, In);
1840 for (
int i = 0, e = Outgoing.
size() - 1; i != e; ++i) {
1841 auto Out = Outgoing[i];
1842 auto Cmp = ICmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, Phi,
1844 Out->
getName() +
".predicate", GuardBlocks[i]);
1845 GuardPredicates[Out] = Cmp;
1857 auto FirstGuardBlock = GuardBlocks.
front();
1861 for (
int i = 0, e = Outgoing.
size() - 1; i != e; ++i) {
1862 auto Out = Outgoing[i];
1863 LLVM_DEBUG(
dbgs() <<
"Creating guard for " << Out->getName() <<
"\n");
1867 StringRef(
"Guard.") + Out->getName(), FirstGuardBlock);
1868 GuardPredicates[Out] = Phi;
1871 for (
auto *In : Incoming) {
1875 std::tie(Condition, Succ0, Succ1) =
1885 bool OneSuccessorDone =
false;
1886 for (
int i = 0, e = Outgoing.
size() - 1; i != e; ++i) {
1887 auto Out = Outgoing[i];
1888 PHINode *Phi = cast<PHINode>(GuardPredicates[Out]);
1889 if (Out != Succ0 && Out != Succ1) {
1891 }
else if (!Succ0 || !Succ1 || OneSuccessorDone) {
1901 DeletionCandidates.
push_back(Condition);
1904 OneSuccessorDone =
true;
1924 std::optional<unsigned> MaxControlFlowBooleans) {
1926 auto F = Incoming.
front()->getParent();
1928 for (
int i = 0, e = Outgoing.
size() - 1; i != e; ++i)
1937 if (!MaxControlFlowBooleans || Outgoing.
size() <= *MaxControlFlowBooleans)
1939 DeletionCandidates);
1949 const StringRef Prefix, std::optional<unsigned> MaxControlFlowBooleans) {
1950 if (Outgoing.
size() < 2)
1951 return Outgoing.
front();
1955 for (
auto *In : Incoming) {
1957 if (Outgoing.
count(Succ))
1958 Updates.
push_back({DominatorTree::Delete,
In, Succ});
1964 Prefix, MaxControlFlowBooleans);
1965 auto FirstGuardBlock = GuardBlocks.
front();
1968 for (
int i = 0, e = GuardBlocks.
size(); i != e; ++i)
1969 reconnectPhis(Outgoing[i], GuardBlocks[i], Incoming, FirstGuardBlock);
1974 int NumGuards = GuardBlocks.
size();
1975 assert((
int)Outgoing.
size() == NumGuards + 1);
1977 for (
auto In : Incoming)
1978 Updates.
push_back({DominatorTree::Insert,
In, FirstGuardBlock});
1980 for (
int i = 0; i != NumGuards - 1; ++i) {
1981 Updates.
push_back({DominatorTree::Insert, GuardBlocks[i], Outgoing[i]});
1983 {DominatorTree::Insert, GuardBlocks[i], GuardBlocks[i + 1]});
1985 Updates.
push_back({DominatorTree::Insert, GuardBlocks[NumGuards - 1],
1986 Outgoing[NumGuards - 1]});
1987 Updates.
push_back({DominatorTree::Insert, GuardBlocks[NumGuards - 1],
1988 Outgoing[NumGuards]});
1992 for (
auto I : DeletionCandidates) {
1994 if (
auto Inst = dyn_cast_or_null<Instruction>(
I))
1995 Inst->eraseFromParent();
1998 return FirstGuardBlock;
SmallVector< MachineOperand, 4 > Cond
static BasicBlock * SplitBlockPredecessorsImpl(BasicBlock *BB, ArrayRef< BasicBlock * > Preds, const char *Suffix, DomTreeUpdater *DTU, DominatorTree *DT, LoopInfo *LI, MemorySSAUpdater *MSSAU, bool PreserveLCSSA)
static void convertToGuardPredicates(SmallVectorImpl< BasicBlock * > &GuardBlocks, SmallVectorImpl< WeakVH > &DeletionCandidates, const BBSetVector &Incoming, const BBSetVector &Outgoing, const StringRef Prefix, std::optional< unsigned > MaxControlFlowBooleans)
static bool removeRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB)
Remove redundant instructions within sequences of consecutive dbg.value instructions.
static void calcPredicateUsingBooleans(const BBSetVector &Incoming, const BBSetVector &Outgoing, SmallVectorImpl< BasicBlock * > &GuardBlocks, BBPredicates &GuardPredicates, SmallVectorImpl< WeakVH > &DeletionCandidates)
We record the predicate of each outgoing block using a phi of boolean.
static void UpdatePHINodes(BasicBlock *OrigBB, BasicBlock *NewBB, ArrayRef< BasicBlock * > Preds, BranchInst *BI, bool HasLoopExit)
Update the PHI nodes in OrigBB to include the values coming from NewBB.
static BasicBlock * SplitBlockImpl(BasicBlock *Old, Instruction *SplitPt, DomTreeUpdater *DTU, DominatorTree *DT, LoopInfo *LI, MemorySSAUpdater *MSSAU, const Twine &BBName, bool Before)
static Instruction * SplitBlockAndInsertIfThenImpl(Value *Cond, Instruction *SplitBefore, bool Unreachable, MDNode *BranchWeights, DomTreeUpdater *DTU, DominatorTree *DT, LoopInfo *LI, BasicBlock *ThenBlock)
static std::tuple< Value *, BasicBlock *, BasicBlock * > redirectToHub(BasicBlock *BB, BasicBlock *FirstGuardBlock, const BBSetVector &Outgoing)
static bool remomveUndefDbgAssignsFromEntryBlock(BasicBlock *BB)
Remove redundant undef dbg.assign intrinsic from an entry block using a forward scan.
static void setupBranchForGuard(SmallVectorImpl< BasicBlock * > &GuardBlocks, const BBSetVector &Outgoing, BBPredicates &GuardPredicates)
static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB, ArrayRef< BasicBlock * > Preds, DomTreeUpdater *DTU, DominatorTree *DT, LoopInfo *LI, MemorySSAUpdater *MSSAU, bool PreserveLCSSA, bool &HasLoopExit)
Update DominatorTree, LoopInfo, and LCCSA analysis information.
static void reconnectPhis(BasicBlock *Out, BasicBlock *GuardBlock, const SetVector< BasicBlock * > &Incoming, BasicBlock *FirstGuardBlock)
static void calcPredicateUsingInteger(const BBSetVector &Incoming, const BBSetVector &Outgoing, SmallVectorImpl< BasicBlock * > &GuardBlocks, BBPredicates &GuardPredicates)
We are using one integer to represent the block we are branching to.
static bool removeRedundantDbgInstrsUsingForwardScan(BasicBlock *BB)
Remove redundant dbg.value instructions using a forward scan.
static void SplitLandingPadPredecessorsImpl(BasicBlock *OrigBB, ArrayRef< BasicBlock * > Preds, const char *Suffix1, const char *Suffix2, SmallVectorImpl< BasicBlock * > &NewBBs, DomTreeUpdater *DTU, DominatorTree *DT, LoopInfo *LI, MemorySSAUpdater *MSSAU, bool PreserveLCSSA)
static cl::opt< unsigned > MaxDeoptOrUnreachableSuccessorCheckDepth("max-deopt-or-unreachable-succ-check-depth", cl::init(8), cl::Hidden, cl::desc("Set the maximum path length when checking whether a basic block " "is followed by a block that either has a terminating " "deoptimizing call or is terminated with an unreachable"))
BlockVerifier::State From
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
const Instruction & front() const
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
bool isEntryBlock() const
Return true if this is the entry block of the containing function.
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="", bool Before=false)
Split the basic block into two basic blocks at the specified instruction.
const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction * getFirstNonPHIOrDbg(bool SkipPseudoOp=true) const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic,...
InstListType::iterator iterator
Instruction iterators...
LLVMContext & getContext() const
Get the context in which this basic block lives.
bool isLandingPad() const
Return true if this basic block is a landing pad.
bool isEHPad() const
Return true if this basic block is an exception handling block.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
bool canSplitPredecessors() const
void splice(BasicBlock::iterator ToIt, BasicBlock *FromBB)
Transfer all instructions from FromBB to this basic block at ToIt.
const Instruction & back() const
void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
This class represents a no-op cast from one type to another.
Conditional or Unconditional Branch instruction.
bool isConditional() const
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
BasicBlock * getSuccessor(unsigned i) const
bool isUnconditional() const
void setSuccessor(unsigned idx, BasicBlock *NewSucc)
static CleanupPadInst * Create(Value *ParentPad, ArrayRef< Value * > Args=std::nullopt, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, Instruction *InsertBefore=nullptr)
static ConstantInt * getTrue(LLVMContext &Context)
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static ConstantInt * getFalse(LLVMContext &Context)
This represents the llvm.dbg.assign instruction.
This represents the llvm.dbg.value instruction.
bool isKillLocation() const
Identifies a unique instance of a variable.
iterator find(const_arg_type_t< KeyT > Val)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Implements a dense probed hash-table based set.
iterator_range< iterator > children()
void flush()
Apply all pending updates to available trees and flush all BasicBlocks awaiting deletion.
void recalculate(Function &F)
Notify DTU that the entry block was replaced.
bool hasDomTree() const
Returns true if it holds a DominatorTree.
void applyUpdates(ArrayRef< DominatorTree::UpdateType > Updates)
Submit updates to all available trees.
void deleteBB(BasicBlock *DelBB)
Delete DelBB.
DominatorTree & getDomTree()
Flush DomTree updates and return DomTree.
DomTreeNodeBase< NodeT > * getRootNode()
getRootNode - This returns the entry node for the CFG of the function.
void changeImmediateDominator(DomTreeNodeBase< NodeT > *N, DomTreeNodeBase< NodeT > *NewIDom)
changeImmediateDominator - This method is used to update the dominator tree information when a node's...
DomTreeNodeBase< NodeT > * addNewBlock(NodeT *BB, NodeT *DomBB)
Add a new node to the dominator tree information.
void splitBlock(NodeT *NewBB)
splitBlock - BB is split and now it has one successor.
DomTreeNodeBase< NodeT > * setNewRoot(NodeT *BB)
Add a new node to the forward dominator tree and make it a new root.
void eraseNode(NodeT *BB)
eraseNode - Removes a node from the dominator tree.
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
Module * getParent()
Get the module that this global value is contained inside of...
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following:
unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
const BasicBlock * getParent() const
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
bool mayHaveSideEffects() const LLVM_READONLY
Return true if the instruction may have side effects.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
bool isExceptionalTerminator() const
SymbolTableList< Instruction >::iterator insertInto(BasicBlock *ParentBB, SymbolTableList< Instruction >::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
This is an important class for using LLVM in a threaded context.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
BlockT * getLoopLatch() const
If there is a single latch block for this loop, return it.
unsigned getLoopDepth() const
Return the nesting level of this loop.
void addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase< BlockT, LoopT > &LI)
This method is used by other analyses to update loop information.
LoopT * getParentLoop() const
Return the parent loop if it exists or nullptr for top level loops.
void moveToHeader(BlockT *BB)
This method is used to move BB (which must be part of this loop) to be the loop header of the loop (t...
void removeBlock(BlockT *BB)
This method completely removes BB from all data structures, including all of the Loop objects it is n...
bool isLoopHeader(const BlockT *BB) const
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
Represents a single loop in the control flow graph.
DebugLoc getStartLoc() const
Return the debug location of the start of this loop.
Provides a lazy, caching interface for making common memory aliasing information queries,...
void invalidateCachedPredecessors()
Clears the PredIteratorCache info.
void removeInstruction(Instruction *InstToRemove)
Removes an instruction from the dependence analysis, updating the dependence of instructions that pre...
MemorySSA * getMemorySSA() const
Get handle on MemorySSA.
void moveAllAfterSpliceBlocks(BasicBlock *From, BasicBlock *To, Instruction *Start)
From block was spliced into From and To.
void applyUpdates(ArrayRef< CFGUpdate > Updates, DominatorTree &DT, bool UpdateDTFirst=false)
Apply CFG updates, analogous with the DT edge updates.
void moveAllAfterMergeBlocks(BasicBlock *From, BasicBlock *To, Instruction *Start)
From block was merged into To.
void moveToPlace(MemoryUseOrDef *What, BasicBlock *BB, MemorySSA::InsertionPlace Where)
void wireOldPredecessorsToNewImmediatePredecessor(BasicBlock *Old, BasicBlock *New, ArrayRef< BasicBlock * > Preds, bool IdenticalEdgesWereMerged=true)
A new empty BasicBlock (New) now branches directly to Old.
void verifyMemorySSA(VerificationLevel=VerificationLevel::Fast) const
Verify that MemorySSA is self consistent (IE definitions dominate all uses, uses appear in the right ...
MemoryUseOrDef * getMemoryAccess(const Instruction *I) const
Given a memory Mod/Ref'ing instruction, get the MemorySSA access associated with it.
Class that has the common methods + fields of memory uses/defs.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
Value * getIncomingValueForBlock(const BasicBlock *BB) const
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Return a value (possibly void), from a function.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
A vector that has set insertion semantics.
size_type size() const
Determine the number of elements in the SetVector.
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
const T & front() const
Return the first element of the SetVector.
const T & back() const
Return the last element of the SetVector.
iterator begin()
Get an iterator to the beginning of the SetVector.
Implements a dense probed hash-table based set with some number of buckets stored inline.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
bool erase(PtrType Ptr)
erase - If the set contains the specified pointer, remove it and return true, otherwise return false.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Provides information about what library functions are available for the current target.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
std::string str() const
Return the twine contents as a std::string.
static IntegerType * getInt1Ty(LLVMContext &C)
static IntegerType * getInt32Ty(LLVMContext &C)
bool isTokenTy() const
Return true if this is 'token'.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
This function has undefined behavior.
A Use represents the edge between a Value definition and its users.
void setOperand(unsigned i, Value *Val)
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void setName(const Twine &Name)
Change the name of the value.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
StringRef getName() const
Return a constant reference to the value's name.
void takeName(Value *V)
Transfer the name from V to this value.
std::pair< iterator, bool > insert(const ValueT &V)
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
@ C
The default llvm calling convention, compatible with C.
AssignmentInstRange getAssignmentInsts(DIAssignID *ID)
Return a range of instructions (typically just one) that have ID as an attachment.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
void ReplaceInstWithInst(BasicBlock *BB, BasicBlock::iterator &BI, Instruction *I)
Replace the instruction specified by BI with the instruction specified by I.
iterator_range< df_ext_iterator< T, SetTy > > depth_first_ext(const T &G, SetTy &S)
Interval::succ_iterator succ_end(Interval *I)
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
bool RemoveRedundantDbgInstrs(BasicBlock *BB)
Try to remove redundant dbg.value instructions from given basic block.
bool succ_empty(const Instruction *I)
bool IsBlockFollowedByDeoptOrUnreachable(const BasicBlock *BB)
Check if we can prove that all paths starting from this block converge to a block that either has a @...
BranchInst * GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue, BasicBlock *&IfFalse)
Check whether BB is the merge point of a if-region.
unsigned GetSuccessorNumber(const BasicBlock *BB, const BasicBlock *Succ)
Search for the specified successor of basic block BB and return its position in the terminator instru...
void detachDeadBlocks(ArrayRef< BasicBlock * > BBs, SmallVectorImpl< DominatorTree::UpdateType > *Updates, bool KeepOneInputPHIs=false)
Replace contents of every block in BBs with single unreachable instruction.
auto successors(const MachineBasicBlock *BB)
ReturnInst * FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB, BasicBlock *Pred, DomTreeUpdater *DTU=nullptr)
This method duplicates the specified return instruction into a predecessor which ends in an unconditi...
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
void SplitLandingPadPredecessors(BasicBlock *OrigBB, ArrayRef< BasicBlock * > Preds, const char *Suffix, const char *Suffix2, SmallVectorImpl< BasicBlock * > &NewBBs, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, bool PreserveLCSSA=false)
This method transforms the landing pad, OrigBB, by introducing two new basic blocks into the function...
BasicBlock * splitBlockBefore(BasicBlock *Old, Instruction *SplitPt, DomTreeUpdater *DTU, LoopInfo *LI, MemorySSAUpdater *MSSAU, const Twine &BBName="")
Split the specified block at the specified instruction SplitPt.
void DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete the specified block, which must have no predecessors.
void ReplaceInstWithValue(BasicBlock::iterator &BI, Value *V)
Replace all uses of an instruction (specified by BI) with a value, then remove and delete the origina...
void SplitBlockAndInsertIfThenElse(Value *Cond, Instruction *SplitBefore, Instruction **ThenTerm, Instruction **ElseTerm, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr)
SplitBlockAndInsertIfThenElse is similar to SplitBlockAndInsertIfThen, but also creates the ElseBlock...
BasicBlock * SplitKnownCriticalEdge(Instruction *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions(), const Twine &BBName="")
If it is known that an edge is critical, SplitKnownCriticalEdge can be called directly,...
Interval::pred_iterator pred_end(Interval *I)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
bool DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Examine each PHI in the given block and delete it if it is dead.
auto reverse(ContainerTy &&C)
bool EliminateUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete all basic blocks from F that are not reachable from its entry node.
bool MergeBlockSuccessorsIntoGivenBlocks(SmallPtrSetImpl< BasicBlock * > &MergeBlocks, Loop *L=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr)
Merge block(s) sucessors, if possible.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
BasicBlock * ehAwareSplitEdge(BasicBlock *BB, BasicBlock *Succ, LandingPadInst *OriginalPad=nullptr, PHINode *LandingPadReplacement=nullptr, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions(), const Twine &BBName="")
Split the edge connect the specficed blocks in the case that Succ is an Exception Handling Block.
SmallVector< ValueTypeFromRangeType< R >, Size > to_vector(R &&Range)
Given a range of type R, iterate the entire range and return a SmallVector with elements of the vecto...
BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock * > Preds, const char *Suffix, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, bool PreserveLCSSA=false)
This method introduces at least one new basic block into the function and moves some of the predecess...
bool VerifyMemorySSA
Enables verification of MemorySSA.
void createPHIsForSplitLoopExit(ArrayRef< BasicBlock * > Preds, BasicBlock *SplitBB, BasicBlock *DestBB)
When a loop exit edge is split, LCSSA form may require new PHIs in the new exit block.
bool MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, MemoryDependenceResults *MemDep=nullptr, bool PredecessorWithTwoSuccessors=false, DominatorTree *DT=nullptr)
Attempts to merge a block into its predecessor, if possible.
bool isAssignmentTrackingEnabled(const Module &M)
Return true if assignment tracking is enabled for module M.
BasicBlock * CreateControlFlowHub(DomTreeUpdater *DTU, SmallVectorImpl< BasicBlock * > &GuardBlocks, const SetVector< BasicBlock * > &Predecessors, const SetVector< BasicBlock * > &Successors, const StringRef Prefix, std::optional< unsigned > MaxControlFlowBooleans=std::nullopt)
Given a set of incoming and outgoing blocks, create a "hub" such that every edge from an incoming blo...
BasicBlock * SplitCriticalEdge(Instruction *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions(), const Twine &BBName="")
If this edge is a critical edge, insert a new node to split the critical edge.
bool FoldSingleEntryPHINodes(BasicBlock *BB, MemoryDependenceResults *MemDep=nullptr)
We know that BB has one predecessor.
bool isCriticalEdge(const Instruction *TI, unsigned SuccNum, bool AllowIdenticalEdges=false)
Return true if the specified edge is a critical edge.
unsigned SplitAllCriticalEdges(Function &F, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions())
Loop over all of the edges in the CFG, breaking critical edges as they are found.
void updatePhiNodes(BasicBlock *DestBB, BasicBlock *OldPred, BasicBlock *NewPred, PHINode *Until=nullptr)
Replaces all uses of OldPred with the NewPred block in all PHINodes in a block.
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
BasicBlock * SplitBlock(BasicBlock *Old, Instruction *SplitPt, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="", bool Before=false)
Split the specified block at the specified instruction.
bool RecursivelyDeleteDeadPHINode(PHINode *PN, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr)
If the specified value is an effectively dead PHI node, due to being a def-use chain of single-use no...
unsigned succ_size(const MachineBasicBlock *BB)
Value * invertCondition(Value *Condition)
Invert the given true/false value, possibly reusing an existing copy.
void DeleteDeadBlocks(ArrayRef< BasicBlock * > BBs, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete the specified blocks from BB.
BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="")
Split the edge connecting the specified blocks, and return the newly created basic block between From...
Instruction * SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore, bool Unreachable, MDNode *BranchWeights, DominatorTree *DT, LoopInfo *LI=nullptr, BasicBlock *ThenBlock=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...
void setUnwindEdgeTo(Instruction *TI, BasicBlock *Succ)
Sets the unwind edge of an instruction to a particular successor.
unsigned pred_size(const MachineBasicBlock *BB)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Option class for critical edge splitting.
CriticalEdgeSplittingOptions & setPreserveLCSSA()