• Home
  • Raw
  • Download

Lines Matching +full:implicit +full:- +full:fall +full:- +full:through

1 //===-- BranchFolding.cpp - Fold machine code branch instructions ---------===//
8 //===----------------------------------------------------------------------===//
18 //===----------------------------------------------------------------------===//
53 static cl::opt<cl::boolOrDefault> FlagEnableTailMerge("enable-tail-merge",
58 TailMergeThreshold("tail-merge-threshold",
65 TailMergeSize("tail-merge-size",
70 /// BranchFolderPass - Wrap branch folder in a machine function pass.
90 INITIALIZE_PASS(BranchFolderPass, "branch-folder",
101 PassConfig->getEnableTailMerge(); in runOnMachineFunction()
123 /// RemoveDeadBlock - Remove the specified dead machine basic block from the
126 assert(MBB->pred_empty() && "MBB must be dead!"); in RemoveDeadBlock()
129 MachineFunction *MF = MBB->getParent(); in RemoveDeadBlock()
131 while (!MBB->succ_empty()) in RemoveDeadBlock()
132 MBB->removeSuccessor(MBB->succ_end()-1); in RemoveDeadBlock()
138 MF->erase(MBB); in RemoveDeadBlock()
141 MLI->removeBlock(MBB); in RemoveDeadBlock()
144 /// OptimizeImpDefsBlock - If a basic block is just a bunch of implicit_def
151 /// This block can be optimized away later if the implicit instructions are
155 MachineBasicBlock::iterator I = MBB->begin(); in OptimizeImpDefsBlock()
156 while (I != MBB->end()) { in OptimizeImpDefsBlock()
157 if (!I->isImplicitDef()) in OptimizeImpDefsBlock()
159 unsigned Reg = I->getOperand(0).getReg(); in OptimizeImpDefsBlock()
173 while (I != MBB->end()) { in OptimizeImpDefsBlock()
174 if (!TII->isUnpredicatedTerminator(*I)) in OptimizeImpDefsBlock()
177 for (const MachineOperand &MO : I->operands()) { in OptimizeImpDefsBlock()
187 I = MBB->begin(); in OptimizeImpDefsBlock()
191 MBB->erase(ImpDefMI); in OptimizeImpDefsBlock()
197 /// OptimizeFunction - Perhaps branch folding, tail merging and other
216 UpdateLiveIns = MRI.tracksLiveness() && TRI->trackLivenessAfterRegAlloc(MF); in OptimizeFunction()
225 if (!TII->analyzeBranch(MBB, TBB, FBB, Cond, true)) in OptimizeFunction()
252 BitVector JTIsLive(JTI->getJumpTables().size()); in OptimizeFunction()
267 JTI->RemoveJumpTable(i); in OptimizeFunction()
274 //===----------------------------------------------------------------------===//
276 //===----------------------------------------------------------------------===//
278 /// HashMachineInstr - Compute a hash value for MI and its operands.
296 OperandHash = Op.getMBB()->getNumber(); in HashMachineInstr()
318 /// HashEndOfMBB - Hash the last instruction in the MBB.
327 /// ComputeCommonTailLength - Given two machine basic blocks, compute the number
334 I1 = MBB1->end(); in ComputeCommonTailLength()
335 I2 = MBB2->end(); in ComputeCommonTailLength()
338 while (I1 != MBB1->begin() && I2 != MBB2->begin()) { in ComputeCommonTailLength()
339 --I1; --I2; in ComputeCommonTailLength()
341 while (I1->isDebugValue()) { in ComputeCommonTailLength()
342 if (I1==MBB1->begin()) { in ComputeCommonTailLength()
343 while (I2->isDebugValue()) { in ComputeCommonTailLength()
344 if (I2==MBB2->begin()) in ComputeCommonTailLength()
347 --I2; in ComputeCommonTailLength()
350 // I1==DBG at begin; I2==non-DBG, or first of DBGs not at begin in ComputeCommonTailLength()
353 --I1; in ComputeCommonTailLength()
355 // I1==first (untested) non-DBG preceding known match in ComputeCommonTailLength()
356 while (I2->isDebugValue()) { in ComputeCommonTailLength()
357 if (I2==MBB2->begin()) { in ComputeCommonTailLength()
359 // I1==non-DBG, or first of DBGs not at begin; I2==DBG at begin in ComputeCommonTailLength()
362 --I2; in ComputeCommonTailLength()
364 // I1, I2==first (untested) non-DBGs preceding known match in ComputeCommonTailLength()
365 if (!I1->isIdenticalTo(*I2) || in ComputeCommonTailLength()
371 I1->isInlineAsm()) { in ComputeCommonTailLength()
380 // I1==MBB1->begin() work as expected.) in ComputeCommonTailLength()
381 if (I1 == MBB1->begin() && I2 != MBB2->begin()) { in ComputeCommonTailLength()
382 --I2; in ComputeCommonTailLength()
383 while (I2->isDebugValue()) { in ComputeCommonTailLength()
384 if (I2 == MBB2->begin()) in ComputeCommonTailLength()
386 --I2; in ComputeCommonTailLength()
390 if (I2 == MBB2->begin() && I1 != MBB1->begin()) { in ComputeCommonTailLength()
391 --I1; in ComputeCommonTailLength()
392 while (I1->isDebugValue()) { in ComputeCommonTailLength()
393 if (I1 == MBB1->begin()) in ComputeCommonTailLength()
395 --I1; in ComputeCommonTailLength()
426 /// ReplaceTailWithBranchTo - Delete the instruction OldInst and everything
430 TII->ReplaceTailWithBranchTo(OldInst, NewDest); in ReplaceTailWithBranchTo()
437 /// SplitMBBAt - Given a machine basic block and an iterator into it, split the
443 if (!TII->isLegalToSplitMBBAt(CurMBB, BBI1)) in SplitMBBAt()
448 // Create the fall-through block. in SplitMBBAt()
451 CurMBB.getParent()->insert(++MBBI, NewMBB); in SplitMBBAt()
454 NewMBB->transferSuccessors(&CurMBB); in SplitMBBAt()
456 // Add an edge from CurMBB to NewMBB for the fall-through. in SplitMBBAt()
460 NewMBB->splice(NewMBB->end(), &CurMBB, BBI1, CurMBB.end()); in SplitMBBAt()
464 if (MachineLoop *ML = MLI->getLoopFor(&CurMBB)) in SplitMBBAt()
465 ML->addBasicBlockToLoop(NewMBB, MLI->getBase()); in SplitMBBAt()
475 auto n = FuncletI->second; in SplitMBBAt()
482 /// EstimateRuntime - Make a rough estimate for how long it will take to run
488 if (I->isDebugValue()) in EstimateRuntime()
490 if (I->isCall()) in EstimateRuntime()
492 else if (I->mayLoad() || I->mayStore()) in EstimateRuntime()
506 MachineFunction *MF = CurMBB->getParent(); in FixTail()
511 if (I != MF->end() && !TII->analyzeBranch(*CurMBB, TBB, FBB, Cond, true)) { in FixTail()
514 if (!TII->ReverseBranchCondition(Cond)) { in FixTail()
515 TII->RemoveBranch(*CurMBB); in FixTail()
516 TII->InsertBranch(*CurMBB, SuccBB, nullptr, Cond, dl); in FixTail()
521 TII->InsertBranch(*CurMBB, SuccBB, nullptr, in FixTail()
531 if (getBlock()->getNumber() < o.getBlock()->getNumber()) in operator <()
533 if (getBlock()->getNumber() > o.getBlock()->getNumber()) in operator <()
549 return I->second; in getBlockFreq()
571 /// CountTerminators - Count the number of terminators in the given
572 /// block and set I to the position of the first non-terminator, if there
573 /// is one, or MBB->end() otherwise.
576 I = MBB->end(); in CountTerminators()
579 if (I == MBB->begin()) { in CountTerminators()
580 I = MBB->end(); in CountTerminators()
583 --I; in CountTerminators()
584 if (!I->isTerminator()) break; in CountTerminators()
590 /// ProfitableToMerge - Check if two machine basic blocks have a common tail
601 // It is never profitable to tail-merge blocks from two different funclets. in ProfitableToMerge()
607 if (Funclet1->second != Funclet2->second) in ProfitableToMerge()
614 DEBUG(dbgs() << "Common tail length of BB#" << MBB1->getNumber() in ProfitableToMerge()
615 << " and BB#" << MBB2->getNumber() << " is " << CommonTailLen in ProfitableToMerge()
618 // It's almost always profitable to merge any number of non-terminator in ProfitableToMerge()
619 // instructions with the block that falls through into the common successor. in ProfitableToMerge()
628 // a position where the other could fall through into it, merge any number in ProfitableToMerge()
631 if (MBB1->isLayoutSuccessor(MBB2) && I2 == MBB2->begin()) in ProfitableToMerge()
633 if (MBB2->isLayoutSuccessor(MBB1) && I1 == MBB1->begin()) in ProfitableToMerge()
641 !MBB1->back().isBarrier() && in ProfitableToMerge()
642 !MBB2->back().isBarrier()) in ProfitableToMerge()
653 MachineFunction *MF = MBB1->getParent(); in ProfitableToMerge()
654 return EffectiveTailLen >= 2 && MF->getFunction()->optForSize() && in ProfitableToMerge()
655 (I1 == MBB1->begin() || I2 == MBB2->begin()); in ProfitableToMerge()
658 /// ComputeSameTails - Look through all the blocks in MergePotentials that have
678 CurMPIter != B && CurMPIter->getHash() == CurHash; --CurMPIter) { in ComputeSameTails()
679 for (MPIterator I = std::prev(CurMPIter); I->getHash() == CurHash; --I) { in ComputeSameTails()
681 if (ProfitableToMerge(CurMPIter->getBlock(), I->getBlock(), in ComputeSameTails()
703 /// RemoveBlocksWithHash - Remove all blocks with hash CurHash from
711 CurMPIter->getHash() == CurHash; --CurMPIter) { in RemoveBlocksWithHash()
713 MachineBasicBlock *CurMBB = CurMPIter->getBlock(); in RemoveBlocksWithHash()
719 if (CurMPIter->getHash() != CurHash) in RemoveBlocksWithHash()
724 /// CreateCommonTailOnlyBlock - None of the blocks to be tail-merged consist
740 unsigned t = EstimateRuntime(SameTails[i].getBlock()->begin(), in CreateCommonTailOnlyBlock()
754 DEBUG(dbgs() << "\nSplitting BB#" << MBB->getNumber() << ", size " in CreateCommonTailOnlyBlock()
757 // If the split block unconditionally falls-thru to SuccBB, it will be in CreateCommonTailOnlyBlock()
760 const BasicBlock *BB = (SuccBB && MBB->succ_size() == 1) ? in CreateCommonTailOnlyBlock()
761 SuccBB->getBasicBlock() : MBB->getBasicBlock(); in CreateCommonTailOnlyBlock()
769 SameTails[commonTailIndex].setTailStartPos(newMBB->begin()); in CreateCommonTailOnlyBlock()
782 MachineBasicBlock *MBB = MBBIStartPos->getParent(); in mergeMMOsFromMemoryOperations()
787 for (auto E = MBB->end(); MBBIStartPos != E; ++MBBIStartPos) in mergeMMOsFromMemoryOperations()
790 MachineBasicBlock::reverse_iterator MBBI = MBB->rbegin(); in mergeMMOsFromMemoryOperations()
791 MachineBasicBlock::reverse_iterator MBBIE = MBB->rend(); in mergeMMOsFromMemoryOperations()
795 while (CommonTailLen--) { in mergeMMOsFromMemoryOperations()
799 if (MBBI->isDebugValue()) { in mergeMMOsFromMemoryOperations()
804 while ((MBBICommon != MBBIECommon) && MBBICommon->isDebugValue()) in mergeMMOsFromMemoryOperations()
809 assert(MBBICommon->isIdenticalTo(*MBBI) && "Expected matching MIIs!"); in mergeMMOsFromMemoryOperations()
811 if (MBBICommon->mayLoad() || MBBICommon->mayStore()) in mergeMMOsFromMemoryOperations()
812 MBBICommon->setMemRefs(MBBICommon->mergeMemRefsWith(*MBBI)); in mergeMMOsFromMemoryOperations()
820 // successor, or all have no successor if it is null) can be tail-merged.
822 // tail-merged and are not immediately before Succ must have an unconditional
824 // adjustment). The lone predecessor of Succ that falls through into Succ,
830 // Except for the special cases below, tail-merge if there are at least in TryTailMergeBlocks()
836 dbgs() << "BB#" << MergePotentials[i].getBlock()->getNumber() in TryTailMergeBlocks()
837 << (i == e-1 ? "" : ", "); in TryTailMergeBlocks()
840 dbgs() << " with successor BB#" << SuccBB->getNumber() << '\n'; in TryTailMergeBlocks()
842 dbgs() << " which has fall-through from BB#" in TryTailMergeBlocks()
843 << PredBB->getNumber() << "\n"; in TryTailMergeBlocks()
854 // Walk through equivalence sets looking for actual exact matches. in TryTailMergeBlocks()
876 &MergePotentials.front().getBlock()->getParent()->front(); in TryTailMergeBlocks()
878 // If there are two blocks, check to see if one can be made to fall through in TryTailMergeBlocks()
881 SameTails[0].getBlock()->isLayoutSuccessor(SameTails[1].getBlock()) && in TryTailMergeBlocks()
885 SameTails[1].getBlock()->isLayoutSuccessor( in TryTailMergeBlocks()
890 // Otherwise just pick one, favoring the fall-through predecessor if in TryTailMergeBlocks()
924 DEBUG(dbgs() << "\nUsing common tail in BB#" << MBB->getNumber() in TryTailMergeBlocks()
929 DEBUG(dbgs() << "BB#" << SameTails[i].getBlock()->getNumber() in TryTailMergeBlocks()
930 << (i == e-1 ? "" : ", ")); in TryTailMergeBlocks()
989 // a compile-time infinite loop repeatedly doing and undoing the same in TailMergeBlocks()
994 if (I->pred_size() < 2) continue; in TailMergeBlocks()
999 for (MachineBasicBlock *PBB : I->predecessors()) { in TailMergeBlocks()
1015 if (PBB->hasEHPadSuccessor()) in TailMergeBlocks()
1025 if (MachineLoop *ML = MLI->getLoopFor(IBB)) in TailMergeBlocks()
1026 if (IBB == ML->getHeader() && ML == MLI->getLoopFor(PBB)) in TailMergeBlocks()
1031 if (!TII->analyzeBranch(*PBB, TBB, FBB, Cond, true)) { in TailMergeBlocks()
1036 if (TII->ReverseBranchCondition(NewCond)) in TailMergeBlocks()
1040 auto Next = ++PBB->getIterator(); in TailMergeBlocks()
1049 if (IBB->isEHPad()) { in TailMergeBlocks()
1050 MachineFunction::iterator IP = ++PBB->getIterator(); in TailMergeBlocks()
1072 TII->RemoveBranch(*PBB); in TailMergeBlocks()
1075 TII->InsertBranch(*PBB, (TBB == IBB) ? FBB : TBB, nullptr, in TailMergeBlocks()
1096 MergePotentials.begin()->getBlock() != PredBB) in TailMergeBlocks()
1097 FixTail(MergePotentials.begin()->getBlock(), IBB, TII); in TailMergeBlocks()
1141 EdgeFreq->getFrequency(), SumEdgeFreq); in setCommonTailEdgeWeights()
1147 //===----------------------------------------------------------------------===//
1149 //===----------------------------------------------------------------------===//
1165 if (MBB->pred_empty()) { in OptimizeBranches()
1178 return MBB->getFirstNonDebugInstr() == MBB->end(); in IsEmptyBlock()
1184 MachineBasicBlock::iterator I = MBB->getFirstNonDebugInstr(); in IsBranchOnlyBlock()
1185 assert(I != MBB->end() && "empty block!"); in IsBranchOnlyBlock()
1186 return I->isBranch(); in IsBranchOnlyBlock()
1189 /// IsBetterFallthrough - Return true if it would be clearly better to
1190 /// fall-through to MBB1 than to fall through into MBB2. This has to return
1196 // MBB1 doesn't, we prefer to fall through into MBB1. This allows us to in IsBetterFallthrough()
1199 MachineBasicBlock::iterator MBB1I = MBB1->getLastNonDebugInstr(); in IsBetterFallthrough()
1200 MachineBasicBlock::iterator MBB2I = MBB2->getLastNonDebugInstr(); in IsBetterFallthrough()
1201 if (MBB1I == MBB1->end() || MBB2I == MBB2->end()) in IsBetterFallthrough()
1205 // will fall through to the next in IsBetterFallthrough()
1206 if (MBB1->isSuccessor(MBB2)) return true; in IsBetterFallthrough()
1207 if (MBB2->isSuccessor(MBB1)) return false; in IsBetterFallthrough()
1209 return MBB2I->isCall() && !MBB1I->isCall(); in IsBetterFallthrough()
1212 /// getBranchDebugLoc - Find and return, if any, the DebugLoc of the branch
1216 if (I != MBB.end() && I->isBranch()) in getBranchDebugLoc()
1217 return I->getDebugLoc(); in getBranchDebugLoc()
1221 /// OptimizeBlock - Analyze and optimize control flow related to the specified
1225 MachineFunction &MF = *MBB->getParent(); in OptimizeBlock()
1228 MachineFunction::iterator FallThrough = MBB->getIterator(); in OptimizeBlock()
1238 SameFunclet = MBBFunclet->second == FallThroughFunclet->second; in OptimizeBlock()
1241 // If this block is empty, make everyone use its fall-through, not the block in OptimizeBlock()
1242 // explicitly. Landing pads should not do this since the landing-pad table in OptimizeBlock()
1245 if (IsEmptyBlock(MBB) && !MBB->isEHPad() && !MBB->hasAddressTaken() && in OptimizeBlock()
1248 if (MBB->pred_empty()) return MadeChange; in OptimizeBlock()
1252 } else if (FallThrough->isEHPad()) { in OptimizeBlock()
1257 } else if (MBB->isSuccessor(&*FallThrough)) { in OptimizeBlock()
1260 while (!MBB->pred_empty()) { in OptimizeBlock()
1261 MachineBasicBlock *Pred = *(MBB->pred_end()-1); in OptimizeBlock()
1262 Pred->ReplaceUsesOfBlockWith(MBB, &*FallThrough); in OptimizeBlock()
1267 MJTI->ReplaceMBBInJumpTables(MBB, &*FallThrough); in OptimizeBlock()
1280 TII->analyzeBranch(PrevBB, PriorTBB, PriorFBB, PriorCond, true); in OptimizeBlock()
1288 // a fall-through. in OptimizeBlock()
1291 TII->RemoveBranch(PrevBB); in OptimizeBlock()
1294 TII->InsertBranch(PrevBB, PriorTBB, nullptr, PriorCond, dl); in OptimizeBlock()
1300 // If the previous block unconditionally falls through to this block and in OptimizeBlock()
1303 // has been used, but it can happen if tail merging splits a fall-through in OptimizeBlock()
1305 // This has to check PrevBB->succ_size() because EH edges are ignored by in OptimizeBlock()
1307 if (PriorCond.empty() && !PriorTBB && MBB->pred_size() == 1 && in OptimizeBlock()
1309 !MBB->hasAddressTaken() && !MBB->isEHPad()) { in OptimizeBlock()
1315 --PrevBBIter; in OptimizeBlock()
1316 MachineBasicBlock::iterator MBBIter = MBB->begin(); in OptimizeBlock()
1319 while (PrevBBIter != PrevBB.begin() && MBBIter != MBB->end() in OptimizeBlock()
1320 && PrevBBIter->isDebugValue() && MBBIter->isDebugValue()) { in OptimizeBlock()
1321 if (!MBBIter->isIdenticalTo(*PrevBBIter)) in OptimizeBlock()
1324 ++MBBIter; -- PrevBBIter; in OptimizeBlock()
1328 PrevBB.splice(PrevBB.end(), MBB, MBB->begin(), MBB->end()); in OptimizeBlock()
1339 TII->RemoveBranch(PrevBB); in OptimizeBlock()
1349 TII->RemoveBranch(PrevBB); in OptimizeBlock()
1350 TII->InsertBranch(PrevBB, PriorTBB, nullptr, PriorCond, dl); in OptimizeBlock()
1358 // fall-through. in OptimizeBlock()
1361 if (!TII->ReverseBranchCondition(NewPriorCond)) { in OptimizeBlock()
1363 TII->RemoveBranch(PrevBB); in OptimizeBlock()
1364 TII->InsertBranch(PrevBB, PriorFBB, nullptr, NewPriorCond, dl); in OptimizeBlock()
1372 // a call to a no-return function like abort or __cxa_throw) and if the pred in OptimizeBlock()
1373 // falls through into this block, and if it would otherwise fall through in OptimizeBlock()
1379 if (MBB->succ_empty() && !PriorCond.empty() && !PriorFBB && in OptimizeBlock()
1381 !MBB->canFallThrough()) { in OptimizeBlock()
1384 // We have to be careful that the succs of PredBB aren't both no-successor in OptimizeBlock()
1387 // last. Only do the swap if one is clearly better to fall through than in OptimizeBlock()
1389 if (FallThrough == --MF.end() && in OptimizeBlock()
1394 // Reverse the branch so we will fall through on the previous true cond. in OptimizeBlock()
1396 if (!TII->ReverseBranchCondition(NewPriorCond)) { in OptimizeBlock()
1401 TII->RemoveBranch(PrevBB); in OptimizeBlock()
1402 TII->InsertBranch(PrevBB, MBB, nullptr, NewPriorCond, dl); in OptimizeBlock()
1405 MBB->moveAfter(&MF.back()); in OptimizeBlock()
1418 TII->analyzeBranch(*MBB, CurTBB, CurFBB, CurCond, true); in OptimizeBlock()
1421 MadeChange |= MBB->CorrectExtraCFGEdges(CurTBB, CurFBB, !CurCond.empty()); in OptimizeBlock()
1423 // If this is a two-way branch, and the FBB branches to this block, reverse in OptimizeBlock()
1424 // the condition so the single-basic-block loop is faster. Instead of: in OptimizeBlock()
1430 if (!TII->ReverseBranchCondition(NewCond)) { in OptimizeBlock()
1432 TII->RemoveBranch(*MBB); in OptimizeBlock()
1433 TII->InsertBranch(*MBB, CurFBB, CurTBB, NewCond, dl); in OptimizeBlock()
1444 !MBB->hasAddressTaken() && !MBB->isEHPad()) { in OptimizeBlock()
1447 // be 'non-branch terminators' in the block, try removing the branch and in OptimizeBlock()
1449 TII->RemoveBranch(*MBB); in OptimizeBlock()
1451 // as well, so this will behave the same as an empty block in non-debug in OptimizeBlock()
1456 MBB->erase(MBB->begin(), MBB->end()); in OptimizeBlock()
1461 // falls through into MBB and we can't understand the prior block's branch in OptimizeBlock()
1463 if (MBB->empty()) { in OptimizeBlock()
1467 // If the prior block falls through into us, turn it into an in OptimizeBlock()
1480 TII->RemoveBranch(PrevBB); in OptimizeBlock()
1481 TII->InsertBranch(PrevBB, PriorTBB, PriorFBB, PriorCond, pdl); in OptimizeBlock()
1484 // Iterate through all the predecessors, revectoring each in-turn. in OptimizeBlock()
1488 while(PI != MBB->pred_size()) { in OptimizeBlock()
1489 MachineBasicBlock *PMBB = *(MBB->pred_begin() + PI); in OptimizeBlock()
1496 PMBB->ReplaceUsesOfBlockWith(MBB, CurTBB); in OptimizeBlock()
1502 bool NewCurUnAnalyzable = TII->analyzeBranch( in OptimizeBlock()
1506 TII->RemoveBranch(*PMBB); in OptimizeBlock()
1508 TII->InsertBranch(*PMBB, NewCurTBB, nullptr, NewCurCond, pdl); in OptimizeBlock()
1511 PMBB->CorrectExtraCFGEdges(NewCurTBB, nullptr, false); in OptimizeBlock()
1518 MJTI->ReplaceMBBInJumpTables(MBB, CurTBB); in OptimizeBlock()
1528 TII->InsertBranch(*MBB, CurTBB, nullptr, CurCond, dl); in OptimizeBlock()
1532 // If the prior block doesn't fall through into this block, and if this in OptimizeBlock()
1533 // block doesn't fall through into some other block, see if we can find a in OptimizeBlock()
1534 // place to move this block where a fall-through will happen. in OptimizeBlock()
1537 // Now we know that there was no fall-through into this block, check to in OptimizeBlock()
1538 // see if it has a fall-through into its successor. in OptimizeBlock()
1539 bool CurFallsThru = MBB->canFallThrough(); in OptimizeBlock()
1541 if (!MBB->isEHPad()) { in OptimizeBlock()
1542 // Check all the predecessors of this block. If one of them has no fall in OptimizeBlock()
1544 for (MachineBasicBlock *PredBB : MBB->predecessors()) { in OptimizeBlock()
1548 if (PredBB != MBB && !PredBB->canFallThrough() && in OptimizeBlock()
1549 !TII->analyzeBranch(*PredBB, PredTBB, PredFBB, PredCond, true) && in OptimizeBlock()
1551 (!CurFallsThru || MBB->getNumber() >= PredBB->getNumber())) { in OptimizeBlock()
1552 // If the current block doesn't fall through, just move it. in OptimizeBlock()
1553 // If the current block can fall through and does not end with a in OptimizeBlock()
1555 // the (current) next block. To avoid a possible compile-time in OptimizeBlock()
1563 MachineBasicBlock *NextBB = &*std::next(MBB->getIterator()); in OptimizeBlock()
1565 TII->InsertBranch(*MBB, NextBB, nullptr, CurCond, DebugLoc()); in OptimizeBlock()
1567 MBB->moveAfter(PredBB); in OptimizeBlock()
1576 for (MachineBasicBlock *SuccBB : MBB->successors()) { in OptimizeBlock()
1578 MachineFunction::iterator SuccPrev = --SuccBB->getIterator(); in OptimizeBlock()
1580 // If this block doesn't already fall-through to that successor, and if in OptimizeBlock()
1581 // the succ doesn't already have a block that can fall through into it, in OptimizeBlock()
1585 !SuccPrev->canFallThrough() && !CurUnAnalyzable && in OptimizeBlock()
1586 !SuccBB->isEHPad()) { in OptimizeBlock()
1587 MBB->moveBefore(SuccBB); in OptimizeBlock()
1594 // the block before this one would be a fall-through if this block were in OptimizeBlock()
1598 // We're looking for cases where PrevBB could possibly fall through to in OptimizeBlock()
1602 while (FallThrough != MF.end() && FallThrough->isEHPad()) in OptimizeBlock()
1605 // a block to which it could fall through. in OptimizeBlock()
1607 !TII->analyzeBranch(PrevBB, PrevTBB, PrevFBB, PrevCond, true) && in OptimizeBlock()
1609 MBB->moveAfter(&MF.back()); in OptimizeBlock()
1619 //===----------------------------------------------------------------------===//
1621 //===----------------------------------------------------------------------===//
1623 /// HoistCommonCode - Hoist common instruction sequences at the start of basic
1635 /// findFalseBlock - BB has a fallthrough. Find its 'false' successor given
1639 for (MachineBasicBlock *SuccBB : BB->successors()) in findFalseBlock()
1656 /// findHoistingInsertPosAndDeps - Find the location to move common instructions
1669 MachineBasicBlock::iterator Loc = MBB->getFirstTerminator(); in findHoistingInsertPosAndDeps()
1670 if (!TII->isUnpredicatedTerminator(*Loc)) in findHoistingInsertPosAndDeps()
1671 return MBB->end(); in findHoistingInsertPosAndDeps()
1673 for (const MachineOperand &MO : Loc->operands()) { in findHoistingInsertPosAndDeps()
1685 return MBB->end(); in findHoistingInsertPosAndDeps()
1695 if (Loc == MBB->begin()) in findHoistingInsertPosAndDeps()
1696 return MBB->end(); in findHoistingInsertPosAndDeps()
1701 --PI; in findHoistingInsertPosAndDeps()
1702 while (PI != MBB->begin() && PI->isDebugValue()) in findHoistingInsertPosAndDeps()
1703 --PI; in findHoistingInsertPosAndDeps()
1706 for (const MachineOperand &MO : PI->operands()) { in findHoistingInsertPosAndDeps()
1726 // side-effects. And since it's potentially bad to separate flag setting in findHoistingInsertPosAndDeps()
1732 if (!PI->isSafeToMove(nullptr, DontMoveAcrossStore) || TII->isPredicated(*PI)) in findHoistingInsertPosAndDeps()
1733 return MBB->end(); in findHoistingInsertPosAndDeps()
1738 for (const MachineOperand &MO : PI->operands()) { in findHoistingInsertPosAndDeps()
1750 Uses.erase(*SubRegs); // Use sub-registers to be conservative in findHoistingInsertPosAndDeps()
1760 /// HoistCommonCodeInSuccs - If the successors of MBB has common instruction
1766 if (TII->analyzeBranch(*MBB, TBB, FBB, Cond, true) || !TBB || Cond.empty()) in HoistCommonCodeInSuccs()
1776 if (TBB->pred_size() > 1 || FBB->pred_size() > 1) in HoistCommonCodeInSuccs()
1785 if (Loc == MBB->end()) in HoistCommonCodeInSuccs()
1791 MachineBasicBlock::iterator TIB = TBB->begin(); in HoistCommonCodeInSuccs()
1792 MachineBasicBlock::iterator FIB = FBB->begin(); in HoistCommonCodeInSuccs()
1793 MachineBasicBlock::iterator TIE = TBB->end(); in HoistCommonCodeInSuccs()
1794 MachineBasicBlock::iterator FIE = FBB->end(); in HoistCommonCodeInSuccs()
1797 if (TIB->isDebugValue()) { in HoistCommonCodeInSuccs()
1798 while (TIB != TIE && TIB->isDebugValue()) in HoistCommonCodeInSuccs()
1803 if (FIB->isDebugValue()) { in HoistCommonCodeInSuccs()
1804 while (FIB != FIE && FIB->isDebugValue()) in HoistCommonCodeInSuccs()
1809 if (!TIB->isIdenticalTo(*FIB, MachineInstr::CheckKillDead)) in HoistCommonCodeInSuccs()
1812 if (TII->isPredicated(*TIB)) in HoistCommonCodeInSuccs()
1817 for (MachineOperand &MO : TIB->operands()) { in HoistCommonCodeInSuccs()
1868 if (!TIB->isSafeToMove(nullptr, DontMoveAcrossStore)) in HoistCommonCodeInSuccs()
1872 for (const MachineOperand &MO : TIB->operands()) { in HoistCommonCodeInSuccs()
1887 for (const MachineOperand &MO : TIB->operands()) { in HoistCommonCodeInSuccs()
1905 MBB->splice(Loc, TBB, TBB->begin(), TIB); in HoistCommonCodeInSuccs()
1906 FBB->erase(FBB->begin(), FIB); in HoistCommonCodeInSuccs()
1912 TBB->addLiveIn(Def); in HoistCommonCodeInSuccs()
1913 FBB->addLiveIn(Def); in HoistCommonCodeInSuccs()