Home | History | Annotate | Download | only in CodeGen

Lines Matching full:mbb

11 // directly to the target block.  This pass often results in dead MBB's, which
106 void BranchFolder::RemoveDeadBlock(MachineBasicBlock *MBB) {
107 assert(MBB->pred_empty() && "MBB must be dead!");
108 DEBUG(dbgs() << "\nRemoving MBB: " << *MBB);
110 MachineFunction *MF = MBB->getParent();
112 while (!MBB->succ_empty())
113 MBB->removeSuccessor(MBB->succ_end()-1);
116 TriedMerging.erase(MBB);
119 MF->erase(MBB);
131 bool BranchFolder::OptimizeImpDefsBlock(MachineBasicBlock *MBB) {
133 MachineBasicBlock::iterator I = MBB->begin();
134 while (I != MBB->end()) {
147 while (I != MBB->end()) {
162 I = MBB->begin();
166 MBB->erase(ImpDefMI);
197 MachineBasicBlock *MBB = I, *TBB = 0, *FBB = 0;
199 if (!TII->AnalyzeBranch(*MBB, TBB, FBB, Cond, true))
200 MadeChange |= MBB->CorrectExtraCFGEdges(TBB, FBB, !Cond.empty());
201 MadeChange |= OptimizeImpDefsBlock(MBB);
285 /// HashEndOfMBB - Hash the last instruction in the MBB.
286 static unsigned HashEndOfMBB(const MachineBasicBlock *MBB) {
287 MachineBasicBlock::const_iterator I = MBB->end();
288 if (I == MBB->begin())
289 return 0; // Empty MBB.
294 if (I==MBB->begin())
295 return 0; // MBB empty except for debug info.
406 /// MBB so that the part before the iterator falls into the part starting at the
407 /// iterator. This returns the new MBB.
501 /// is one, or MBB->end() otherwise.
502 static unsigned CountTerminators(MachineBasicBlock *MBB,
504 I = MBB->end();
507 if (I == MBB->begin()) {
508 I = MBB->end();
587 /// found) and a MachineBasicBlock::iterator into that MBB indicating the
674 MachineBasicBlock *MBB = SameTails[commonTailIndex].getBlock();
678 DEBUG(dbgs() << "\nSplitting BB#" << MBB->getNumber() << ", size "
684 const BasicBlock *BB = (SuccBB && MBB->succ_size() == 1) ?
685 SuccBB->getBasicBlock() : MBB->getBasicBlock();
686 MachineBasicBlock *newMBB = SplitMBBAt(*MBB, BBI, BB);
696 if (PredBB == MBB)
777 MachineBasicBlock *MBB = SameTails[i].getBlock();
778 if (MBB == EntryBB && SameTails[i].tailIsWholeBlock())
780 if (MBB == PredBB) {
801 MachineBasicBlock *MBB = SameTails[commonTailIndex].getBlock();
802 // MBB is common tail. Adjust all other BB's to jump to this one.
804 DEBUG(dbgs() << "\nUsing common tail in BB#" << MBB->getNumber()
812 ReplaceTailWithBranchTo(SameTails[i].getTailStartPos(), MBB);
975 MachineBasicBlock *MBB = I++;
976 MadeChange |= OptimizeBlock(MBB);
979 if (MBB->pred_empty()) {
980 RemoveDeadBlock(MBB);
990 static bool IsEmptyBlock(MachineBasicBlock *MBB) {
991 if (MBB->empty())
993 for (MachineBasicBlock::iterator MBBI = MBB->begin(), MBBE = MBB->end();
1003 static bool IsBranchOnlyBlock(MachineBasicBlock *MBB) {
1005 for (MBBI = MBB->begin(), MBBE = MBB->end(); MBBI!=MBBE; ++MBBI) {
1044 static DebugLoc getBranchDebugLoc(MachineBasicBlock &MBB) {
1045 MachineBasicBlock::iterator I = MBB.end();
1046 if (I == MBB.begin())
1049 while (I->isDebugValue() && I != MBB.begin())
1058 bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
1060 MachineFunction &MF = *MBB->getParent();
1063 MachineFunction::iterator FallThrough = MBB;
1070 if (IsEmptyBlock(MBB) && !MBB->isLandingPad() && !MBB->hasAddressTaken()) {
1072 if (MBB->pred_empty()) return MadeChange;
1079 while (!MBB->pred_empty()) {
1080 MachineBasicBlock *Pred = *(MBB->pred_end()-1);
1081 Pred->ReplaceUsesOfBlockWith(MBB, FallThrough);
1083 // If MBB was the target of a jump table, update jump tables to go to the
1086 MJTI->ReplaceMBBInJumpTables(MBB, FallThrough);
1094 MachineBasicBlock &PrevBB = *prior(MachineFunction::iterator(MBB));
1112 if (PriorTBB != MBB)
1126 if (PriorCond.empty() && !PriorTBB && MBB->pred_size() == 1 &&
1128 !MBB->hasAddressTaken() && !MBB->isLandingPad()) {
1130 << "From MBB: " << *MBB);
1135 MachineBasicBlock::iterator MBBIter = MBB->begin();
1137 // DBG_VALUE at the beginning of MBB.
1138 while (PrevBBIter != PrevBB.begin() && MBBIter != MBB->end()
1147 PrevBB.splice(PrevBB.end(), MBB, MBB->begin(), MBB->end());
1150 PrevBB.transferSuccessors(MBB);
1157 if (PriorTBB == MBB && PriorFBB == 0) {
1166 if (PriorFBB == MBB) {
1178 if (PriorTBB == MBB) {
1198 if (MBB->succ_empty() && !PriorCond.empty() && PriorFBB == 0 &&
1200 !MBB->canFallThrough()) {
1209 !IsBetterFallthrough(PriorTBB, MBB))
1216 DEBUG(dbgs() << "\nMoving MBB: " << *MBB
1221 TII->InsertBranch(PrevBB, MBB, 0, NewPriorCond, dl);
1224 MBB->moveAfter(--MF.end());
1236 bool CurUnAnalyzable= TII->AnalyzeBranch(*MBB, CurTBB, CurFBB, CurCond, true);
1239 MadeChange |= MBB->CorrectExtraCFGEdges(CurTBB, CurFBB, !CurCond.empty());
1246 if (CurTBB && CurFBB && CurFBB == MBB && CurTBB != MBB) {
1249 DebugLoc dl = getBranchDebugLoc(*MBB);
1250 TII->RemoveBranch(*MBB);
1251 TII->InsertBranch(*MBB, CurFBB, CurTBB, NewCond, dl);
1261 IsBranchOnlyBlock(MBB) && CurTBB != MBB &&
1262 !MBB->hasAddressTaken()) {
1263 DebugLoc dl = getBranchDebugLoc(*MBB);
1267 TII->RemoveBranch(*MBB);
1271 if (!MBB->empty()) {
1273 for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end();
1283 MBB->erase(MBB->begin(), MBB->end());
1288 MBB and we can't understand the prior block's branch
1290 if (MBB->empty()) {
1293 !PrevBB.isSuccessor(MBB)) {
1296 if (!PredHasNoFallThrough && PrevBB.isSuccessor(MBB) &&
1297 PriorTBB != MBB && PriorFBB != MBB) {
1301 PriorTBB = MBB;
1304 PriorFBB = MBB;
1315 while(PI != MBB->pred_size()) {
1316 MachineBasicBlock *PMBB = *(MBB->pred_begin() + PI);
1317 if (PMBB == MBB) {
1323 PMBB->ReplaceUsesOfBlockWith(MBB, CurTBB);
1343 // Change any jumptables to go to the new MBB.
1345 MJTI->ReplaceMBBInJumpTables(MBB, CurTBB);
1355 TII->InsertBranch(*MBB, CurTBB, 0, CurCond, dl);
1366 bool CurFallsThru = MBB->canFallThrough();
1368 if (!MBB->isLandingPad()) {
1371 for (MachineBasicBlock::pred_iterator PI = MBB->pred_begin(),
1372 E = MBB->pred_end(); PI != E; ++PI) {
1378 if (PredBB != MBB && !PredBB->canFallThrough() &&
1381 && (!CurFallsThru || MBB->getNumber() >= PredBB->getNumber())) {
1393 MachineBasicBlock *NextBB = llvm::next(MachineFunction::iterator(MBB));
1395 TII->InsertBranch(*MBB, NextBB, 0, CurCond, DebugLoc());
1397 MBB->moveAfter(PredBB);
1406 for (MachineBasicBlock::succ_iterator SI = MBB->succ_begin(),
1407 E = MBB->succ_end(); SI != E; ++SI) {
1416 if (SuccBB != MBB && &*SuccPrev != MBB &&
1419 MBB->moveBefore(SuccBB);
1433 MBB->moveAfter(--MF.end());
1452 MachineBasicBlock *MBB = I++;
1453 MadeChange |= HoistCommonCodeInSuccs(MBB);
1480 MachineBasicBlock::iterator findHoistingInsertPosAndDeps(MachineBasicBlock *MBB,
1485 MachineBasicBlock::iterator Loc = MBB->getFirstTerminator();
1487 return MBB->end();
1502 return MBB->end();
1507 if (Loc == MBB->begin())
1508 return MBB->end();
1514 while (PI != MBB->begin() && Loc->isDebugValue())
1545 return MBB->end();
1573 /// HoistCommonCodeInSuccs - If the successors of MBB has common instruction
1574 /// sequence at the start of the function, move the instructions before MBB
1576 bool BranchFolder::HoistCommonCodeInSuccs(MachineBasicBlock *MBB) {
1579 if (TII->AnalyzeBranch(*MBB, TBB, FBB, Cond, true) || !TBB || Cond.empty())
1582 if (!FBB) FBB = findFalseBlock(MBB, TBB);
1587 // Restrict the optimization to cases where MBB is the only predecessor,
1597 findHoistingInsertPosAndDeps(MBB, TII, TRI, Uses, Defs);
1598 if (Loc == MBB->end())
1718 MBB->splice(Loc, TBB, TBB->begin(), TIB);