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
123 void BranchFolder::RemoveDeadBlock(MachineBasicBlock *MBB) {
124 assert(MBB->pred_empty() && "MBB must be dead!");
125 DEBUG(dbgs() << "\nRemoving MBB: " << *MBB);
127 MachineFunction *MF = MBB->getParent();
129 while (!MBB->succ_empty())
130 MBB->removeSuccessor(MBB->succ_end()-1);
133 TriedMerging.erase(MBB);
136 MF->erase(MBB);
137 FuncletMembership.erase(MBB);
149 bool BranchFolder::OptimizeImpDefsBlock(MachineBasicBlock *MBB) {
151 MachineBasicBlock::iterator I = MBB->begin();
152 while (I != MBB->end()) {
169 while (I != MBB->end()) {
183 I = MBB->begin();
187 MBB->erase(ImpDefMI);
217 for (MachineBasicBlock &MBB : MF) {
220 if (!TII->AnalyzeBranch(MBB, TBB, FBB, Cond, true))
221 MadeChange |= MBB.CorrectExtraCFGEdges(TBB, FBB, !Cond.empty());
222 MadeChange |= OptimizeImpDefsBlock(&MBB);
313 /// HashEndOfMBB - Hash the last instruction in the MBB.
314 static unsigned HashEndOfMBB(const MachineBasicBlock *MBB) {
315 MachineBasicBlock::const_iterator I = MBB->getLastNonDebugInstr();
316 if (I == MBB->end())
424 /// MBB so that the part before the iterator falls into the part starting at the
425 /// iterator. This returns the new MBB.
526 BranchFolder::MBFIWrapper::getBlockFreq(const MachineBasicBlock *MBB) const {
527 auto I = MergedBBFreq.find(MBB);
532 return MBFI.getBlockFreq(MBB);
535 void BranchFolder::MBFIWrapper::setBlockFreq(const MachineBasicBlock *MBB,
537 MergedBBFreq[MBB] = F;
542 /// is one, or MBB->end() otherwise.
543 static unsigned CountTerminators(MachineBasicBlock *MBB,
545 I = MBB->end();
548 if (I == MBB->begin()) {
549 I = MBB->end();
632 /// found) and a MachineBasicBlock::iterator into that MBB indicating the
719 MachineBasicBlock *MBB = SameTails[commonTailIndex].getBlock();
723 DEBUG(dbgs() << "\nSplitting BB#" << MBB->getNumber() << ", size "
729 const BasicBlock *BB = (SuccBB && MBB->succ_size() == 1) ?
730 SuccBB->getBasicBlock() : MBB->getBasicBlock();
731 MachineBasicBlock *newMBB = SplitMBBAt(*MBB, BBI, BB);
741 if (PredBB == MBB)
765 MachineBasicBlock *MBB = MBBIStartPos->getParent();
770 for (auto E = MBB->end(); MBBIStartPos != E; ++MBBIStartPos)
773 MachineBasicBlock::reverse_iterator MBBI = MBB->rbegin();
774 MachineBasicBlock::reverse_iterator MBBIE = MBB->rend();
878 MachineBasicBlock *MBB = SameTails[i].getBlock();
879 if (MBB
881 if (MBB == PredBB) {
902 MachineBasicBlock *MBB = SameTails[commonTailIndex].getBlock();
904 // Recompute commont tail MBB's edge weights and block frequency.
905 setCommonTailEdgeWeights(*MBB);
907 // MBB is common tail. Adjust all other BB's to jump to this one.
909 DEBUG(dbgs() << "\nUsing common tail in BB#" << MBB->getNumber()
917 removeMMOsFromMemoryOperations(SameTails[i].getTailStartPos(), *MBB);
919 ReplaceTailWithBranchTo(SameTails[i].getTailStartPos(), MBB);
937 for (MachineBasicBlock &MBB : MF) {
940 if (!TriedMerging.count(&MBB) && MBB.succ_empty())
941 MergePotentials.push_back(MergePotentialsElt(HashEndOfMBB(&MBB), &MBB));
1131 MachineBasicBlock *MBB = &*I++;
1132 MadeChange |= OptimizeBlock(MBB);
1135 if (MBB->pred_empty()) {
1136 RemoveDeadBlock(MBB);
1147 static bool IsEmptyBlock(MachineBasicBlock *MBB) {
1148 return MBB->getFirstNonDebugInstr() == MBB->end();
1153 static bool IsBranchOnlyBlock(MachineBasicBlock *MBB) {
1154 MachineBasicBlock::iterator I = MBB->getFirstNonDebugInstr();
1155 assert(I != MBB->end() && "empty block!");
1184 static DebugLoc getBranchDebugLoc(MachineBasicBlock &MBB) {
1185 MachineBasicBlock::iterator I = MBB.getLastNonDebugInstr();
1186 if (I != MBB.end() && I->isBranch())
1193 bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
1195 MachineFunction &MF = *MBB->getParent();
1198 MachineFunction::iterator FallThrough = MBB->getIterator();
1201 // Make sure MBB and FallThrough belong to the same funclet.
1204 auto MBBFunclet = FuncletMembership.find(MBB);
1215 if (IsEmptyBlock(MBB) && !MBB->isEHPad() && !MBB->hasAddressTaken() &&
1218 if (MBB->pred_empty()) return MadeChange;
1230 while (!MBB->pred_empty()) {
1231 MachineBasicBlock *Pred = *(MBB->pred_end()-1);
1232 Pred->ReplaceUsesOfBlockWith(MBB, &*FallThrough);
1234 // If MBB was the target of a jump table, update jump tables to go to the
1237 MJTI->ReplaceMBBInJumpTables(MBB, &*FallThrough);
1245 MachineBasicBlock &PrevBB = *std::prev(MachineFunction::iterator(MBB));
1263 if (PriorTBB != MBB)
1277 if (PriorCond.empty() && !PriorTBB && MBB->pred_size() == 1 &&
1279 !MBB->hasAddressTaken() && !MBB->isEHPad()) {
1281 << "From MBB: " << *MBB);
1286 MachineBasicBlock::iterator MBBIter = MBB->begin();
1288 // DBG_VALUE at the beginning of MBB.
1289 while (PrevBBIter != PrevBB.begin() && MBBIter != MBB->end()
1298 PrevBB.splice(PrevBB.end(), MBB, MBBMBB->end());
1301 PrevBB.transferSuccessors(MBB);
1308 if (PriorTBB == MBB && !PriorFBB) {
1317 if (PriorFBB == MBB) {
1329 if (PriorTBB == MBB) {
1349 if (MBB->succ_empty() && !PriorCond.empty() && !PriorFBB &&
1351 !MBB->canFallThrough()) {
1360 !IsBetterFallthrough(PriorTBB, MBB))
1367 DEBUG(dbgs() << "\nMoving MBB: " << *MBB
1372 TII->InsertBranch(PrevBB, MBB, nullptr, NewPriorCond, dl);
1375 MBB->moveAfter(&MF.back());
1387 bool CurUnAnalyzable= TII->AnalyzeBranch(*MBB, CurTBB, CurFBB, CurCond, true);
1390 MadeChange |= MBB->CorrectExtraCFGEdges(CurTBB, CurFBB, !CurCond.empty());
1397 if (CurTBB && CurFBB && CurFBB == MBB && CurTBB != MBB) {
1400 DebugLoc dl = getBranchDebugLoc(*MBB);
1401 TII->RemoveBranch(*MBB);
1402 TII->InsertBranch(*MBB, CurFBB, CurTBB, NewCond, dl);
1412 IsBranchOnlyBlock(MBB) && CurTBB != MBB &&
1413 !MBB->hasAddressTaken() && !MBB->isEHPad()) {
1414 DebugLoc dl = getBranchDebugLoc(*MBB);
1418 TII->RemoveBranch(*MBB);
1422 if (IsEmptyBlock(MBB)) {
1425 MBB->erase(MBB->begin(), MBB->end());
1430 // falls through into MBB and we can't understand the prior block's branch
1432 if (MBB->empty()) {
1435 !PrevBB.isSuccessor(MBB)) {
1438 if (!PredHasNoFallThrough && PrevBB.isSuccessor(MBB) &&
1439 PriorTBB != MBB && PriorFBB != MBB) {
1443 PriorTBB = MBB;
1446 PriorFBB = MBB;
1457 while(PI != MBB->pred_size()) {
1458 MachineBasicBlock *PMBB = *(MBB->pred_begin() + PI);
1459 if (PMBB == MBB) {
1465 PMBB->ReplaceUsesOfBlockWith(MBB, CurTBB);
1485 // Change any jumptables to go to the new MBB.
1487 MJTI->ReplaceMBBInJumpTables(MBB, CurTBB);
1497 TII->InsertBranch(*MBB, CurTBB, nullptr, CurCond, dl);
1508 bool CurFallsThru = MBB->canFallThrough();
1510 if (!MBB->isEHPad()) {
1513 for (MachineBasicBlock *PredBB : MBB->predecessors()) {
1517 if (PredBB != MBB && !PredBB->canFallThrough() &&
1520 && (!CurFallsThru || MBB->getNumber() >= PredBB->getNumber())) {
1532 MachineBasicBlock *NextBB = &*std::next(MBB->getIterator());
1534 TII->InsertBranch(*MBB, NextBB, nullptr, CurCond, DebugLoc());
1536 MBB->moveAfter(PredBB);
1545 for (MachineBasicBlock *SuccBB : MBB->successors()) {
1553 if (SuccBB != MBB && &*SuccPrev != MBB &&
1556 MBB->moveBefore(SuccBB);
1578 MBB->moveAfter(&MF.back());
1597 MachineBasicBlock *MBB = &*I++;
1598 MadeChange |= HoistCommonCodeInSuccs(MBB);
1633 MachineBasicBlock::iterator findHoistingInsertPosAndDeps(MachineBasicBlock *MBB,
1638 MachineBasicBlock::iterator Loc = MBB->getFirstTerminator();
1640 return MBB->end();
1654 return MBB->end();
1664 if (Loc == MBB->begin())
1665 return MBB->end();
1671 while (PI != MBB->begin() && PI->isDebugValue())
1702 return MBB->end();
1729 /// HoistCommonCodeInSuccs - If the successors of MBB has common instruction
1730 /// sequence at the start of the function, move the instructions before MBB
1732 bool BranchFolder::HoistCommonCodeInSuccs(MachineBasicBlock *MBB) {
1735 if (TII->AnalyzeBranch(*MBB, TBB, FBB, Cond, true) || !TBB || Cond.empty())
1738 if (!FBB) FBB = findFalseBlock(MBB, TBB);
1743 // Restrict the optimization to cases where MBB is the only predecessor,
1753 findHoistingInsertPosAndDeps(MBB, TII, TRI, Uses, Defs);
1754 if (Loc == MBB->end())
1874 MBB->splice(Loc, TBB, TBB->begin(), TIB);