Lines Matching +full:- +full:bi1
1 //===-- BasicBlockUtils.cpp - BasicBlock Utilities -------------------------==//
8 //===----------------------------------------------------------------------===//
13 //===----------------------------------------------------------------------===//
37 BB->getSinglePredecessor() == BB) && "Block is not dead!"); in DeleteDeadBlock()
38 TerminatorInst *BBTerm = BB->getTerminator(); in DeleteDeadBlock()
42 for (BasicBlock *Succ : BBTerm->successors()) in DeleteDeadBlock()
43 Succ->removePredecessor(BB); in DeleteDeadBlock()
46 while (!BB->empty()) { in DeleteDeadBlock()
47 Instruction &I = BB->back(); in DeleteDeadBlock()
55 BB->getInstList().pop_back(); in DeleteDeadBlock()
59 BB->eraseFromParent(); in DeleteDeadBlock()
64 if (!isa<PHINode>(BB->begin())) return; in FoldSingleEntryPHINodes()
66 while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) { in FoldSingleEntryPHINodes()
67 if (PN->getIncomingValue(0) != PN) in FoldSingleEntryPHINodes()
68 PN->replaceAllUsesWith(PN->getIncomingValue(0)); in FoldSingleEntryPHINodes()
70 PN->replaceAllUsesWith(UndefValue::get(PN->getType())); in FoldSingleEntryPHINodes()
73 MemDep->removeInstruction(PN); // Memdep updates AA itself. in FoldSingleEntryPHINodes()
75 PN->eraseFromParent(); in FoldSingleEntryPHINodes()
83 for (BasicBlock::iterator I = BB->begin(); in DeleteDeadPHIs()
99 if (BB->hasAddressTaken()) return false; in MergeBlockIntoPredecessor()
102 BasicBlock *PredBB = BB->getUniquePredecessor(); in MergeBlockIntoPredecessor()
105 // Don't break self-loops. in MergeBlockIntoPredecessor()
108 if (PredBB->getTerminator()->isExceptional()) in MergeBlockIntoPredecessor()
123 for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE; ++BI) { in MergeBlockIntoPredecessor()
125 for (Value *IncValue : PN->incoming_values()) in MergeBlockIntoPredecessor()
133 if (isa<PHINode>(BB->front())) in MergeBlockIntoPredecessor()
137 PredBB->getInstList().pop_back(); in MergeBlockIntoPredecessor()
141 BB->replaceAllUsesWith(PredBB); in MergeBlockIntoPredecessor()
144 PredBB->getInstList().splice(PredBB->end(), BB->getInstList()); in MergeBlockIntoPredecessor()
147 if (!PredBB->hasName()) in MergeBlockIntoPredecessor()
148 PredBB->takeName(BB); in MergeBlockIntoPredecessor()
152 if (DomTreeNode *DTN = DT->getNode(BB)) { in MergeBlockIntoPredecessor()
153 DomTreeNode *PredDTN = DT->getNode(PredBB); in MergeBlockIntoPredecessor()
154 SmallVector<DomTreeNode *, 8> Children(DTN->begin(), DTN->end()); in MergeBlockIntoPredecessor()
156 DT->changeImmediateDominator(DI, PredDTN); in MergeBlockIntoPredecessor()
158 DT->eraseNode(BB); in MergeBlockIntoPredecessor()
162 LI->removeBlock(BB); in MergeBlockIntoPredecessor()
165 MemDep->invalidateCachedPredecessors(); in MergeBlockIntoPredecessor()
167 BB->eraseFromParent(); in MergeBlockIntoPredecessor()
178 if (I.hasName() && !V->hasName()) in ReplaceInstWithValue()
179 V->takeName(&I); in ReplaceInstWithValue()
187 assert(I->getParent() == nullptr && in ReplaceInstWithInst()
192 if (!I->getDebugLoc()) in ReplaceInstWithInst()
193 I->setDebugLoc(BI->getDebugLoc()); in ReplaceInstWithInst()
207 ReplaceInstWithInst(From->getParent()->getInstList(), BI, To); in ReplaceInstWithInst()
215 TerminatorInst *LatchTerm = BB->getTerminator(); in SplitEdge()
218 return LatchTerm->getSuccessor(SuccNum); in SplitEdge()
222 if (BasicBlock *SP = Succ->getSinglePredecessor()) { in SplitEdge()
227 return SplitBlock(Succ, &Succ->front(), DT, LI); in SplitEdge()
232 assert(BB->getTerminator()->getNumSuccessors() == 1 && in SplitEdge()
234 return SplitBlock(BB, BB->getTerminator(), DT, LI); in SplitEdge()
243 if (TI->getNumSuccessors() > 1 && !isa<IndirectBrInst>(TI)) in SplitAllCriticalEdges()
244 for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i) in SplitAllCriticalEdges()
253 BasicBlock::iterator SplitIt = SplitPt->getIterator(); in SplitBlock()
254 while (isa<PHINode>(SplitIt) || SplitIt->isEHPad()) in SplitBlock()
256 BasicBlock *New = Old->splitBasicBlock(SplitIt, Old->getName()+".split"); in SplitBlock()
261 if (Loop *L = LI->getLoopFor(Old)) in SplitBlock()
262 L->addBasicBlockToLoop(New, *LI); in SplitBlock()
266 if (DomTreeNode *OldNode = DT->getNode(Old)) { in SplitBlock()
267 std::vector<DomTreeNode *> Children(OldNode->begin(), OldNode->end()); in SplitBlock()
269 DomTreeNode *NewNode = DT->addNewBlock(New, Old); in SplitBlock()
271 DT->changeImmediateDominator(I, NewNode); in SplitBlock()
284 DT->splitBlock(NewBB); in UpdateAnalysisInformation()
290 Loop *L = LI->getLoopFor(OldBB); in UpdateAnalysisInformation()
300 if (Loop *PL = LI->getLoopFor(Pred)) in UpdateAnalysisInformation()
301 if (!PL->contains(OldBB)) in UpdateAnalysisInformation()
308 if (L->contains(Pred)) in UpdateAnalysisInformation()
321 // loops enclose them, and select the most-nested loop which contains the in UpdateAnalysisInformation()
325 if (Loop *PredLoop = LI->getLoopFor(Pred)) { in UpdateAnalysisInformation()
328 while (PredLoop && !PredLoop->contains(OldBB)) in UpdateAnalysisInformation()
329 PredLoop = PredLoop->getParentLoop(); in UpdateAnalysisInformation()
331 // Select the most-nested of these loops which contains the block. in UpdateAnalysisInformation()
332 if (PredLoop && PredLoop->contains(OldBB) && in UpdateAnalysisInformation()
334 InnermostPredLoop->getLoopDepth() < PredLoop->getLoopDepth())) in UpdateAnalysisInformation()
340 InnermostPredLoop->addBasicBlockToLoop(NewBB, *LI); in UpdateAnalysisInformation()
342 L->addBasicBlockToLoop(NewBB, *LI); in UpdateAnalysisInformation()
344 L->moveToHeader(NewBB); in UpdateAnalysisInformation()
355 for (BasicBlock::iterator I = OrigBB->begin(); isa<PHINode>(I); ) { in UpdatePHINodes()
362 InVal = PN->getIncomingValueForBlock(Preds[0]); in UpdatePHINodes()
363 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { in UpdatePHINodes()
364 if (!PredSet.count(PN->getIncomingBlock(i))) in UpdatePHINodes()
367 InVal = PN->getIncomingValue(i); in UpdatePHINodes()
368 else if (InVal != PN->getIncomingValue(i)) { in UpdatePHINodes()
384 for (int64_t i = PN->getNumIncomingValues() - 1; i >= 0; --i) in UpdatePHINodes()
385 if (PredSet.count(PN->getIncomingBlock(i))) in UpdatePHINodes()
386 PN->removeIncomingValue(i, false); in UpdatePHINodes()
390 PN->addIncoming(InVal, NewBB); in UpdatePHINodes()
398 PHINode::Create(PN->getType(), Preds.size(), PN->getName() + ".ph", BI); in UpdatePHINodes()
404 for (int64_t i = PN->getNumIncomingValues() - 1; i >= 0; --i) { in UpdatePHINodes()
405 BasicBlock *IncomingBB = PN->getIncomingBlock(i); in UpdatePHINodes()
407 Value *V = PN->removeIncomingValue(i, false); in UpdatePHINodes()
408 NewPHI->addIncoming(V, IncomingBB); in UpdatePHINodes()
412 PN->addIncoming(NewPHI, NewBB); in UpdatePHINodes()
421 if (!BB->canSplitPredecessors()) in SplitBlockPredecessors()
426 if (BB->isLandingPad()) { in SplitBlockPredecessors()
428 std::string NewName = std::string(Suffix) + ".split-lp"; in SplitBlockPredecessors()
437 BB->getContext(), BB->getName() + Suffix, BB->getParent(), BB); in SplitBlockPredecessors()
441 BI->setDebugLoc(BB->getFirstNonPHI()->getDebugLoc()); in SplitBlockPredecessors()
448 assert(!isa<IndirectBrInst>(Preds[i]->getTerminator()) && in SplitBlockPredecessors()
450 Preds[i]->getTerminator()->replaceUsesOfWith(BB, NewBB); in SplitBlockPredecessors()
459 for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I); ++I) in SplitBlockPredecessors()
460 cast<PHINode>(I)->addIncoming(UndefValue::get(I->getType()), NewBB); in SplitBlockPredecessors()
480 assert(OrigBB->isLandingPad() && "Trying to split a non-landing pad!"); in SplitLandingPadPredecessors()
484 BasicBlock *NewBB1 = BasicBlock::Create(OrigBB->getContext(), in SplitLandingPadPredecessors()
485 OrigBB->getName() + Suffix1, in SplitLandingPadPredecessors()
486 OrigBB->getParent(), OrigBB); in SplitLandingPadPredecessors()
490 BranchInst *BI1 = BranchInst::Create(OrigBB, NewBB1); in SplitLandingPadPredecessors() local
491 BI1->setDebugLoc(OrigBB->getFirstNonPHI()->getDebugLoc()); in SplitLandingPadPredecessors()
498 assert(!isa<IndirectBrInst>(Preds[i]->getTerminator()) && in SplitLandingPadPredecessors()
500 Preds[i]->getTerminator()->replaceUsesOfWith(OrigBB, NewBB1); in SplitLandingPadPredecessors()
508 UpdatePHINodes(OrigBB, NewBB1, Preds, BI1, HasLoopExit); in SplitLandingPadPredecessors()
516 assert(!isa<IndirectBrInst>(Pred->getTerminator()) && in SplitLandingPadPredecessors()
525 NewBB2 = BasicBlock::Create(OrigBB->getContext(), in SplitLandingPadPredecessors()
526 OrigBB->getName() + Suffix2, in SplitLandingPadPredecessors()
527 OrigBB->getParent(), OrigBB); in SplitLandingPadPredecessors()
532 BI2->setDebugLoc(OrigBB->getFirstNonPHI()->getDebugLoc()); in SplitLandingPadPredecessors()
536 NewBB2Pred->getTerminator()->replaceUsesOfWith(OrigBB, NewBB2); in SplitLandingPadPredecessors()
547 LandingPadInst *LPad = OrigBB->getLandingPadInst(); in SplitLandingPadPredecessors()
548 Instruction *Clone1 = LPad->clone(); in SplitLandingPadPredecessors()
549 Clone1->setName(Twine("lpad") + Suffix1); in SplitLandingPadPredecessors()
550 NewBB1->getInstList().insert(NewBB1->getFirstInsertionPt(), Clone1); in SplitLandingPadPredecessors()
553 Instruction *Clone2 = LPad->clone(); in SplitLandingPadPredecessors()
554 Clone2->setName(Twine("lpad") + Suffix2); in SplitLandingPadPredecessors()
555 NewBB2->getInstList().insert(NewBB2->getFirstInsertionPt(), Clone2); in SplitLandingPadPredecessors()
559 if (!LPad->use_empty()) { in SplitLandingPadPredecessors()
560 assert(!LPad->getType()->isTokenTy() && in SplitLandingPadPredecessors()
563 PHINode *PN = PHINode::Create(LPad->getType(), 2, "lpad.phi", LPad); in SplitLandingPadPredecessors()
564 PN->addIncoming(Clone1, NewBB1); in SplitLandingPadPredecessors()
565 PN->addIncoming(Clone2, NewBB2); in SplitLandingPadPredecessors()
566 LPad->replaceAllUsesWith(PN); in SplitLandingPadPredecessors()
568 LPad->eraseFromParent(); in SplitLandingPadPredecessors()
572 LPad->replaceAllUsesWith(Clone1); in SplitLandingPadPredecessors()
573 LPad->eraseFromParent(); in SplitLandingPadPredecessors()
579 Instruction *UncondBranch = Pred->getTerminator(); in FoldReturnIntoUncondBranch()
581 Instruction *NewRet = RI->clone(); in FoldReturnIntoUncondBranch()
582 Pred->getInstList().push_back(NewRet); in FoldReturnIntoUncondBranch()
586 for (User::op_iterator i = NewRet->op_begin(), e = NewRet->op_end(); in FoldReturnIntoUncondBranch()
593 V = BCI->getOperand(0); in FoldReturnIntoUncondBranch()
594 NewBC = BCI->clone(); in FoldReturnIntoUncondBranch()
595 Pred->getInstList().insert(NewRet->getIterator(), NewBC); in FoldReturnIntoUncondBranch()
599 if (PN->getParent() == BB) { in FoldReturnIntoUncondBranch()
601 NewBC->setOperand(0, PN->getIncomingValueForBlock(Pred)); in FoldReturnIntoUncondBranch()
603 *i = PN->getIncomingValueForBlock(Pred); in FoldReturnIntoUncondBranch()
610 BB->removePredecessor(Pred); in FoldReturnIntoUncondBranch()
611 UncondBranch->eraseFromParent(); in FoldReturnIntoUncondBranch()
619 BasicBlock *Head = SplitBefore->getParent(); in SplitBlockAndInsertIfThen()
620 BasicBlock *Tail = Head->splitBasicBlock(SplitBefore->getIterator()); in SplitBlockAndInsertIfThen()
621 TerminatorInst *HeadOldTerm = Head->getTerminator(); in SplitBlockAndInsertIfThen()
622 LLVMContext &C = Head->getContext(); in SplitBlockAndInsertIfThen()
623 BasicBlock *ThenBlock = BasicBlock::Create(C, "", Head->getParent(), Tail); in SplitBlockAndInsertIfThen()
629 CheckTerm->setDebugLoc(SplitBefore->getDebugLoc()); in SplitBlockAndInsertIfThen()
632 HeadNewTerm->setMetadata(LLVMContext::MD_prof, BranchWeights); in SplitBlockAndInsertIfThen()
636 if (DomTreeNode *OldNode = DT->getNode(Head)) { in SplitBlockAndInsertIfThen()
637 std::vector<DomTreeNode *> Children(OldNode->begin(), OldNode->end()); in SplitBlockAndInsertIfThen()
639 DomTreeNode *NewNode = DT->addNewBlock(Tail, Head); in SplitBlockAndInsertIfThen()
641 DT->changeImmediateDominator(Child, NewNode); in SplitBlockAndInsertIfThen()
644 DT->addNewBlock(ThenBlock, Head); in SplitBlockAndInsertIfThen()
649 Loop *L = LI->getLoopFor(Head); in SplitBlockAndInsertIfThen()
650 L->addBasicBlockToLoop(ThenBlock, *LI); in SplitBlockAndInsertIfThen()
651 L->addBasicBlockToLoop(Tail, *LI); in SplitBlockAndInsertIfThen()
661 BasicBlock *Head = SplitBefore->getParent(); in SplitBlockAndInsertIfThenElse()
662 BasicBlock *Tail = Head->splitBasicBlock(SplitBefore->getIterator()); in SplitBlockAndInsertIfThenElse()
663 TerminatorInst *HeadOldTerm = Head->getTerminator(); in SplitBlockAndInsertIfThenElse()
664 LLVMContext &C = Head->getContext(); in SplitBlockAndInsertIfThenElse()
665 BasicBlock *ThenBlock = BasicBlock::Create(C, "", Head->getParent(), Tail); in SplitBlockAndInsertIfThenElse()
666 BasicBlock *ElseBlock = BasicBlock::Create(C, "", Head->getParent(), Tail); in SplitBlockAndInsertIfThenElse()
668 (*ThenTerm)->setDebugLoc(SplitBefore->getDebugLoc()); in SplitBlockAndInsertIfThenElse()
670 (*ElseTerm)->setDebugLoc(SplitBefore->getDebugLoc()); in SplitBlockAndInsertIfThenElse()
673 HeadNewTerm->setMetadata(LLVMContext::MD_prof, BranchWeights); in SplitBlockAndInsertIfThenElse()
680 PHINode *SomePHI = dyn_cast<PHINode>(BB->begin()); in GetIfCondition()
685 if (SomePHI->getNumIncomingValues() != 2) in GetIfCondition()
687 Pred1 = SomePHI->getIncomingBlock(0); in GetIfCondition()
688 Pred2 = SomePHI->getIncomingBlock(1); in GetIfCondition()
703 BranchInst *Pred1Br = dyn_cast<BranchInst>(Pred1->getTerminator()); in GetIfCondition()
704 BranchInst *Pred2Br = dyn_cast<BranchInst>(Pred2->getTerminator()); in GetIfCondition()
710 if (Pred2Br->isConditional()) { in GetIfCondition()
715 if (Pred1Br->isConditional()) in GetIfCondition()
722 if (Pred1Br->isConditional()) { in GetIfCondition()
726 if (!Pred2->getSinglePredecessor()) in GetIfCondition()
731 if (Pred1Br->getSuccessor(0) == BB && in GetIfCondition()
732 Pred1Br->getSuccessor(1) == Pred2) { in GetIfCondition()
735 } else if (Pred1Br->getSuccessor(0) == Pred2 && in GetIfCondition()
736 Pred1Br->getSuccessor(1) == BB) { in GetIfCondition()
745 return Pred1Br->getCondition(); in GetIfCondition()
751 BasicBlock *CommonPred = Pred1->getSinglePredecessor(); in GetIfCondition()
752 if (CommonPred == nullptr || CommonPred != Pred2->getSinglePredecessor()) in GetIfCondition()
756 BranchInst *BI = dyn_cast<BranchInst>(CommonPred->getTerminator()); in GetIfCondition()
759 assert(BI->isConditional() && "Two successors but not conditional?"); in GetIfCondition()
760 if (BI->getSuccessor(0) == Pred1) { in GetIfCondition()
767 return BI->getCondition(); in GetIfCondition()