Home | History | Annotate | Download | only in CodeGen

Lines Matching defs:MBB

11 // directly to the target block.  This pass often results in dead MBB's, which
125 void BranchFolder::RemoveDeadBlock(MachineBasicBlock *MBB) {
126 assert(MBB->pred_empty() && "MBB must be dead!");
127 DEBUG(dbgs() << "\nRemoving MBB: " << *MBB);
129 MachineFunction *MF = MBB->getParent();
131 while (!MBB->succ_empty())
132 MBB->removeSuccessor(MBB->succ_end()-1);
135 TriedMerging.erase(MBB);
138 MF->erase(MBB);
139 FuncletMembership.erase(MBB);
141 MLI->removeBlock(MBB);
153 bool BranchFolder::OptimizeImpDefsBlock(MachineBasicBlock *MBB) {
155 MachineBasicBlock::iterator I = MBB->begin();
156 while (I != MBB->end()) {
173 while (I != MBB->end()) {
187 I = MBB->begin();
191 MBB->erase(ImpDefMI);
222 for (MachineBasicBlock &MBB : MF) {
225 if (!TII->analyzeBranch(MBB, TBB, FBB, Cond, true))
226 MadeChange |= MBB.CorrectExtraCFGEdges(TBB, FBB, !Cond.empty());
227 MadeChange |= OptimizeImpDefsBlock(&MBB);
318 /// HashEndOfMBB - Hash the last instruction in the MBB.
319 static unsigned HashEndOfMBB(const MachineBasicBlock &MBB) {
320 MachineBasicBlock::const_iterator I = MBB.getLastNonDebugInstr();
321 if (I == MBB.end())
402 void BranchFolder::computeLiveIns(MachineBasicBlock &MBB) {
407 LiveRegs.addLiveOutsNoPristines(MBB);
408 for (MachineInstr &MI : make_range(MBB.rbegin(), MBB.rend()))
422 MBB.addLiveIn(Reg);
438 /// MBB so that the part before the iterator falls into the part starting at the
439 /// iterator. This returns the new MBB.
545 BranchFolder::MBFIWrapper::getBlockFreq(const MachineBasicBlock *MBB) const {
546 auto I = MergedBBFreq.find(MBB);
551 return MBFI.getBlockFreq(MBB);
554 void BranchFolder::MBFIWrapper::setBlockFreq(const MachineBasicBlock *MBB,
556 MergedBBFreq[MBB] = F;
561 const MachineBasicBlock *MBB) const {
562 return MBFI.printBlockFreq(OS, getBlockFreq(MBB));
573 /// is one, or MBB->end() otherwise.
574 static unsigned CountTerminators(MachineBasicBlock *MBB,
576 I = MBB->end();
579 if (I == MBB->begin()) {
580 I = MBB->end();
663 /// found) and a MachineBasicBlock::iterator into that MBB indicating the
750 MachineBasicBlock *MBB = SameTails[commonTailIndex].getBlock();
754 DEBUG(dbgs() << "\nSplitting BB#" << MBB->getNumber() << ", size "
760 const BasicBlock *BB = (SuccBB && MBB->succ_size() == 1) ?
761 SuccBB->getBasicBlock() : MBB->getBasicBlock();
762 MachineBasicBlock *newMBB = SplitMBBAt(*MBB, BBI, BB);
772 if (PredBB == MBB)
782 MachineBasicBlock *MBB = MBBIStartPos->getParent();
787 for (auto E = MBB->end(); MBBIStartPos != E; ++MBBIStartPos)
790 MachineBasicBlock::reverse_iterator MBBI = MBB->rbegin();
791 MachineBasicBlock::reverse_iterator MBBIE = MBB->rend();
893 MachineBasicBlock *MBB = SameTails[i].getBlock();
894 if (MBB == EntryBB && SameTails[i].tailIsWholeBlock())
896 if (MBB == PredBB) {
917 MachineBasicBlock *MBB = SameTails[commonTailIndex].getBlock();
919 // Recompute common tail MBB's edge weights and block frequency.
920 setCommonTailEdgeWeights(*MBB);
922 // MBB is common tail. Adjust all other BB's to jump to this one.
924 DEBUG(dbgs() << "\nUsing common tail in BB#" << MBB->getNumber()
932 mergeMMOsFromMemoryOperations(SameTails[i].getTailStartPos(), *MBB);
934 ReplaceTailWithBranchTo(SameTails[i].getTailStartPos(), MBB);
955 for (MachineBasicBlock &MBB : MF) {
958 if (!TriedMerging.count(&MBB) && MBB.succ_empty())
959 MergePotentials.push_back(MergePotentialsElt(HashEndOfMBB(MBB), &MBB));
1161 MachineBasicBlock *MBB = &*I++;
1162 MadeChange |= OptimizeBlock(MBB);
1165 if (MBB->pred_empty()) {
1166 RemoveDeadBlock(MBB);
1177 static bool IsEmptyBlock(MachineBasicBlock *MBB) {
1178 return MBB->getFirstNonDebugInstr() == MBB->end();
1183 static bool IsBranchOnlyBlock(MachineBasicBlock *MBB) {
1184 MachineBasicBlock::iterator I = MBB->getFirstNonDebugInstr();
1185 assert(I != MBB->end() && "empty block!");
1214 static DebugLoc getBranchDebugLoc(MachineBasicBlock &MBB) {
1215 MachineBasicBlock::iterator I = MBB.getLastNonDebugInstr();
1216 if (I != MBB.end() && I->isBranch())
1223 bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
1225 MachineFunction &MF = *MBB->getParent();
1228 MachineFunction::iterator FallThrough = MBB->getIterator();
1231 // Make sure MBB and FallThrough belong to the same funclet.
1234 auto MBBFunclet = FuncletMembership.find(MBB);
1245 if (IsEmptyBlock(MBB) && !MBB->isEHPad() && !MBB->hasAddressTaken() &&
1248 if (MBB->pred_empty()) return MadeChange;
1257 } else if (MBB->isSuccessor(&*FallThrough)) {
1260 while (!MBB->pred_empty()) {
1261 MachineBasicBlock *Pred = *(MBB->pred_end()-1);
1262 Pred->ReplaceUsesOfBlockWith(MBB, &*FallThrough);
1264 // If MBB was the target of a jump table, update jump tables to go to the
1267 MJTI->ReplaceMBBInJumpTables(MBB, &*FallThrough);
1275 MachineBasicBlock &PrevBB = *std::prev(MachineFunction::iterator(MBB));
1293 if (PriorTBB != MBB)
1307 if (PriorCond.empty() && !PriorTBB && MBB->pred_size() == 1 &&
1309 !MBB->hasAddressTaken() && !MBB->isEHPad()) {
1311 << "From MBB: " << *MBB);
1316 MachineBasicBlock::iterator MBBIter = MBB->begin();
1318 // DBG_VALUE at the beginning of MBB.
1319 while (PrevBBIter != PrevBB.begin() && MBBIter != MBB->end()
1328 PrevBB.splice(PrevBB.end(), MBB, MBB->begin(), MBB->end());
1331 PrevBB.transferSuccessors(MBB);
1338 if (PriorTBB == MBB && !PriorFBB) {
1347 if (PriorFBB == MBB) {
1359 if (PriorTBB == MBB) {
1379 if (MBB->succ_empty() && !PriorCond.empty() && !PriorFBB &&
1381 !MBB->canFallThrough()) {
1390 !IsBetterFallthrough(PriorTBB, MBB))
1397 DEBUG(dbgs() << "\nMoving MBB: " << *MBB
1402 TII->InsertBranch(PrevBB, MBB, nullptr, NewPriorCond, dl);
1405 MBB->moveAfter(&MF.back());
1418 TII->analyzeBranch(*MBB, CurTBB, CurFBB, CurCond, true);
1421 MadeChange |= MBB->CorrectExtraCFGEdges(CurTBB, CurFBB, !CurCond.empty());
1428 if (CurTBB && CurFBB && CurFBB == MBB && CurTBB != MBB) {
1431 DebugLoc dl = getBranchDebugLoc(*MBB);
1432 TII->RemoveBranch(*MBB);
1433 TII->InsertBranch(*MBB, CurFBB, CurTBB, NewCond, dl);
1443 IsBranchOnlyBlock(MBB) && CurTBB != MBB &&
1444 !MBB->hasAddressTaken() && !MBB->isEHPad()) {
1445 DebugLoc dl = getBranchDebugLoc(*MBB);
1449 TII->RemoveBranch(*MBB);
1453 if (IsEmptyBlock(MBB)) {
1456 MBB->erase(MBB->begin(), MBB->end());
1461 // falls through into MBB and we can't understand the prior block's branch
1463 if (MBB->empty()) {
1466 !PrevBB.isSuccessor(MBB)) {
1469 if (!PredHasNoFallThrough && PrevBB.isSuccessor(MBB) &&
1470 PriorTBB != MBB && PriorFBB != MBB) {
1474 PriorTBB = MBB;
1477 PriorFBB = MBB;
1488 while(PI != MBB->pred_size()) {
1489 MachineBasicBlock *PMBB = *(MBB->pred_begin() + PI);
1490 if (PMBB == MBB) {
1496 PMBB->ReplaceUsesOfBlockWith(MBB, CurTBB);
1516 // Change any jumptables to go to the new MBB.
1518 MJTI->ReplaceMBBInJumpTables(MBB, CurTBB);
1528 TII->InsertBranch(*MBB, CurTBB, nullptr, CurCond, dl);
1539 bool CurFallsThru = MBB->canFallThrough();
1541 if (!MBB->isEHPad()) {
1544 for (MachineBasicBlock *PredBB : MBB->predecessors()) {
1548 if (PredBB != MBB && !PredBB->canFallThrough() &&
1551 (!CurFallsThru || MBB->getNumber() >= PredBB->getNumber())) {
1563 MachineBasicBlock *NextBB = &*std::next(MBB->getIterator());
1565 TII->InsertBranch(*MBB, NextBB, nullptr, CurCond, DebugLoc());
1567 MBB->moveAfter(PredBB);
1576 for (MachineBasicBlock *SuccBB : MBB->successors()) {
1584 if (SuccBB != MBB && &*SuccPrev != MBB &&
1587 MBB->moveBefore(SuccBB);
1609 MBB->moveAfter(&MF.back());
1628 MachineBasicBlock *MBB = &*I++;
1629 MadeChange |= HoistCommonCodeInSuccs(MBB);
1664 MachineBasicBlock::iterator findHoistingInsertPosAndDeps(MachineBasicBlock *MBB,
1669 MachineBasicBlock::iterator Loc = MBB->getFirstTerminator();
1671 return MBB->end();
1685 MBB->end();
1695 if (Loc == MBB->begin())
1696 return MBB->end();
1702 while (PI != MBB->begin() && PI->isDebugValue())
1733 return MBB->end();
1760 /// HoistCommonCodeInSuccs - If the successors of MBB has common instruction
1761 /// sequence at the start of the function, move the instructions before MBB
1763 bool BranchFolder::HoistCommonCodeInSuccs(MachineBasicBlock *MBB) {
1766 if (TII->analyzeBranch(*MBB, TBB, FBB, Cond, true) || !TBB || Cond.empty())
1769 if (!FBB) FBB = findFalseBlock(MBB, TBB);
1774 // Restrict the optimization to cases where MBB is the only predecessor,
1784 findHoistingInsertPosAndDeps(MBB, TII, TRI, Uses, Defs);
1785 if (Loc == MBB->end())
1905 MBB->splice(Loc, TBB, TBB->begin(), TIB);