Lines Matching refs:MachineBasicBlock
38 #include "llvm/CodeGen/MachineBasicBlock.h"
237 using BlockToChainMapType = DenseMap<const MachineBasicBlock *, BlockChain *>;
255 SmallVector<MachineBasicBlock *, 4> Blocks;
271 BlockChain(BlockToChainMapType &BlockToChain, MachineBasicBlock *BB)
278 using iterator = SmallVectorImpl<MachineBasicBlock *>::iterator;
279 using const_iterator = SmallVectorImpl<MachineBasicBlock *>::const_iterator;
289 bool remove(MachineBasicBlock* BB) {
305 void merge(MachineBasicBlock *BB, BlockChain *Chain) {
323 for (MachineBasicBlock *ChainBB : *Chain) {
333 for (MachineBasicBlock *MBB : *this)
352 using BlockFilterSet = SmallSetVector<const MachineBasicBlock *, 16>;
356 MachineBasicBlock *BB = nullptr;
363 MachineBasicBlock *Src = nullptr;
364 MachineBasicBlock *Dest = nullptr;
368 SmallVector<MachineBasicBlock *, 16> BlockWorkList;
369 SmallVector<MachineBasicBlock *, 16> EHPadWorkList;
372 DenseMap<const MachineBasicBlock *, BlockAndTailDupResult> ComputedEdges;
389 MachineBasicBlock *PreferredLoopExit = nullptr;
431 DenseMap<const MachineBasicBlock *, BlockChain *> BlockToChain;
438 SmallPtrSet<MachineBasicBlock *, 4> BlocksWithUnanalyzableExits;
443 BlockFrequency getBlockCountOrFrequency(const MachineBasicBlock *BB) {
455 BlockFrequency scaleThreshold(MachineBasicBlock *BB);
461 const BlockChain &Chain, const MachineBasicBlock *LoopHeaderBB,
467 const BlockChain &Chain, const MachineBasicBlock *BB,
468 const MachineBasicBlock *LoopHeaderBB,
473 const MachineBasicBlock *BB, const BlockChain &Chain,
475 SmallVector<MachineBasicBlock *, 4> &Successors);
476 bool isBestSuccessor(MachineBasicBlock *BB, MachineBasicBlock *Pred,
478 void findDuplicateCandidates(SmallVectorImpl<MachineBasicBlock *> &Candidates,
479 MachineBasicBlock *BB,
482 MachineBasicBlock *BB, MachineBasicBlock *&LPred,
483 const MachineBasicBlock *LoopHeaderBB, BlockChain &Chain,
488 maybeTailDuplicateBlock(MachineBasicBlock *BB, MachineBasicBlock *LPred,
494 const MachineBasicBlock *BB, const MachineBasicBlock *Succ,
499 const MachineBasicBlock *BB, const BlockChain &Chain,
501 MachineBasicBlock *selectBestCandidateBlock(
502 const BlockChain &Chain, SmallVectorImpl<MachineBasicBlock *> &WorkList);
503 MachineBasicBlock *
506 MachineBasicBlock *
516 void fillWorkLists(const MachineBasicBlock *MBB,
520 void buildChain(const MachineBasicBlock *BB, BlockChain &Chain,
522 bool canMoveBottomBlockToTop(const MachineBasicBlock *BottomBlock,
523 const MachineBasicBlock *OldTop);
524 bool hasViableTopFallthrough(const MachineBasicBlock *Top,
526 BlockFrequency TopFallThroughFreq(const MachineBasicBlock *Top,
528 BlockFrequency FallThroughGains(const MachineBasicBlock *NewTop,
529 const MachineBasicBlock *OldTop,
530 const MachineBasicBlock *ExitBB,
532 MachineBasicBlock *findBestLoopTopHelper(MachineBasicBlock *OldTop,
534 MachineBasicBlock *findBestLoopTop(
536 MachineBasicBlock *findBestLoopExit(
542 BlockChain &LoopChain, const MachineBasicBlock *ExitingBB,
552 bool shouldTailDuplicate(MachineBasicBlock *BB);
556 const MachineBasicBlock *BB, const MachineBasicBlock *Succ,
561 bool isTrellis(const MachineBasicBlock *BB,
562 const SmallVectorImpl<MachineBasicBlock *> &ViableSuccs,
567 const MachineBasicBlock *BB,
568 const SmallVectorImpl<MachineBasicBlock *> &ViableSuccs,
574 const MachineBasicBlock *BB,
580 const MachineBasicBlock *BB, MachineBasicBlock *Succ,
591 void assignBlockOrder(const std::vector<const MachineBasicBlock *> &NewOrder);
642 static std::string getBlockName(const MachineBasicBlock *BB) {
659 const BlockChain &Chain, const MachineBasicBlock *LoopHeaderBB,
663 for (MachineBasicBlock *MBB : Chain) {
675 const BlockChain &Chain, const MachineBasicBlock *MBB,
676 const MachineBasicBlock *LoopHeaderBB, const BlockFilterSet *BlockFilter) {
681 for (MachineBasicBlock *Succ : MBB->successors()) {
708 const MachineBasicBlock *BB, const BlockChain &Chain,
710 SmallVector<MachineBasicBlock *, 4> &Successors) {
728 for (MachineBasicBlock *Succ : BB->successors()) {
769 hasSameSuccessors(MachineBasicBlock &BB,
770 SmallPtrSetImpl<const MachineBasicBlock *> &Successors) {
776 for (MachineBasicBlock *Succ : BB.successors())
785 bool MachineBlockPlacement::shouldTailDuplicate(MachineBasicBlock *BB) {
815 const MachineBasicBlock *BB, const MachineBasicBlock *Succ,
841 MachineBasicBlock *PDom = nullptr;
842 SmallVector<MachineBasicBlock *, 4> SuccSuccs;
859 for (MachineBasicBlock *SuccSucc : SuccSuccs) {
872 for (MachineBasicBlock *SuccPred : Succ->predecessors()) {
969 const MachineBasicBlock *BB,
970 const SmallVectorImpl<MachineBasicBlock *> &ViableSuccs,
977 SmallPtrSet<const MachineBasicBlock *, 2> Successors(BB->succ_begin(),
980 SmallPtrSet<const MachineBasicBlock *, 8> SeenPreds;
982 for (MachineBasicBlock *Succ : ViableSuccs) {
988 for (MachineBasicBlock *CheckSucc : SuccPred->successors())
1020 const MachineBasicBlock *BB,
1064 const MachineBasicBlock *BB,
1065 const SmallVectorImpl<MachineBasicBlock *> &ViableSuccs,
1070 SmallPtrSet<const MachineBasicBlock *, 4> Successors(BB->succ_begin(),
1083 for (MachineBasicBlock *SuccPred : Succ->predecessors()) {
1115 MachineBasicBlock *Succ1 = BestA.Dest;
1116 MachineBasicBlock *Succ2 = BestB.Dest;
1149 const MachineBasicBlock *BB, MachineBasicBlock *Succ,
1160 SmallPtrSet<const MachineBasicBlock *, 4> Successors(BB->succ_begin(),
1162 for (MachineBasicBlock *Pred : Succ->predecessors()) {
1273 std::vector<MachineBasicBlock *> Edges;
1275 TriangleChain(MachineBasicBlock *src, MachineBasicBlock *dst)
1278 void append(MachineBasicBlock *dst) {
1286 MachineBasicBlock *getKey() const {
1297 DenseMap<const MachineBasicBlock *, TriangleChain> TriangleChainMap;
1298 for (MachineBasicBlock &BB : *F) {
1302 MachineBasicBlock *PDom = nullptr;
1303 for (MachineBasicBlock *Succ : BB.successors()) {
1323 for (MachineBasicBlock* Pred : PDom->predecessors()) {
1365 MachineBasicBlock *dst = Chain.Edges.back();
1367 for (MachineBasicBlock *src : reverse(Chain.Edges)) {
1384 const MachineBasicBlock *BB) {
1388 const MachineBasicBlock *Succ1 = *BB->succ_begin();
1389 const MachineBasicBlock *Succ2 = *(BB->succ_begin() + 1);
1416 const MachineBasicBlock *BB, const MachineBasicBlock *Succ,
1545 for (MachineBasicBlock *Pred : Succ->predecessors()) {
1597 const MachineBasicBlock *BB, const BlockChain &Chain,
1604 SmallVector<MachineBasicBlock *, 4> Successors;
1615 MachineBasicBlock *Succ = FoundEdge->second.BB;
1632 SmallVector<std::pair<BranchProbability, MachineBasicBlock *>, 4>
1634 for (MachineBasicBlock *Succ : Successors) {
1671 [](std::tuple<BranchProbability, MachineBasicBlock *> L,
1672 std::tuple<BranchProbability, MachineBasicBlock *> R) {
1677 MachineBasicBlock *Succ;
1708 MachineBasicBlock *MachineBlockPlacement::selectBestCandidateBlock(
1709 const BlockChain &Chain, SmallVectorImpl<MachineBasicBlock *> &WorkList) {
1714 llvm::erase_if(WorkList, [&](MachineBasicBlock *BB) {
1723 MachineBasicBlock *BestBlock = nullptr;
1725 for (MachineBasicBlock *MBB : WorkList) {
1776 MachineBasicBlock *MachineBlockPlacement::getFirstUnplacedBlock(
1803 MachineBasicBlock *MachineBlockPlacement::getFirstUnplacedBlock(
1819 const MachineBasicBlock *MBB,
1829 for (MachineBasicBlock *ChainBB : Chain) {
1832 for (MachineBasicBlock *Pred : ChainBB->predecessors()) {
1844 MachineBasicBlock *BB = *Chain.begin();
1852 const MachineBasicBlock *HeadBB, BlockChain &Chain,
1861 const MachineBasicBlock *LoopHeaderBB = HeadBB;
1863 MachineBasicBlock *BB = *std::prev(Chain.end());
1873 MachineBasicBlock* BestSucc = Result.BB;
1945 const MachineBasicBlock *BottomBlock,
1946 const MachineBasicBlock *OldTop) {
1949 MachineBasicBlock *Pred = *BottomBlock->pred_begin();
1953 MachineBasicBlock *OtherBB = *Pred->succ_begin();
1965 const MachineBasicBlock *Top,
1968 for (MachineBasicBlock *Pred : Top->predecessors()) {
1976 for (MachineBasicBlock *Succ : Pred->successors()) {
2021 const MachineBasicBlock *NewTop,
2022 const MachineBasicBlock *OldTop,
2023 const MachineBasicBlock *ExitBB,
2034 MachineBasicBlock *BestPred = nullptr;
2036 for (MachineBasicBlock *Pred : NewTop->predecessors()) {
2054 for (MachineBasicBlock *Succ : BestPred->successors()) {
2110 MachineBasicBlock *
2112 MachineBasicBlock *OldTop,
2128 MachineBasicBlock *BestPred = nullptr;
2129 for (MachineBasicBlock *Pred : OldTop->predecessors()) {
2140 MachineBasicBlock *OtherBB = nullptr;
2180 MachineBasicBlock *
2195 MachineBasicBlock *OldTop = nullptr;
2196 MachineBasicBlock *NewTop = L.getHeader();
2211 MachineBasicBlock *
2229 MachineBasicBlock *ExitingBB = nullptr;
2233 SmallPtrSet<MachineBasicBlock *, 4> BlocksExitingToOuterLoop;
2237 for (MachineBasicBlock *MBB : L.getBlocks()) {
2248 MachineBasicBlock *OldExitingBB = ExitingBB;
2251 for (MachineBasicBlock *Succ : MBB->successors()) {
2335 const MachineBasicBlock *Top,
2337 for (MachineBasicBlock *Pred : Top->predecessors()) {
2345 for (MachineBasicBlock *Succ : Pred->successors()) {
2369 const MachineBasicBlock *ExitingBB,
2375 MachineBasicBlock *Top = *LoopChain.begin();
2376 MachineBasicBlock *Bottom = *std::prev(LoopChain.end());
2392 for (MachineBasicBlock *Succ : Bottom->successors()) {
2432 MachineBasicBlock *NextBlockInChain = *std::next(ExitIt);
2460 MachineBasicBlock *ChainHeaderBB = *LoopChain.begin();
2502 SmallVector<std::pair<MachineBasicBlock *, BlockFrequency>, 4> ExitsWithFreq;
2617 for (MachineBasicBlock *LoopBB : L.getBlocks()) {
2624 for (MachineBasicBlock *ChainBB : *Chain)
2662 MachineBasicBlock *LoopTop = findBestLoopTop(L, LoopBlockSet);
2685 for (const MachineBasicBlock *LoopBB : LoopBlockSet)
2704 for (MachineBasicBlock *ChainBB : LoopChain) {
2719 for (const MachineBasicBlock *LoopBB : LoopBlockSet)
2738 MachineBasicBlock *BB = &*FI;
2745 MachineBasicBlock *TBB = nullptr, *FBB = nullptr; // For analyzeBranch.
2750 MachineBasicBlock *NextBB = &*NextFI;
2777 for (MachineBasicBlock &MBB : *F)
2784 using FunctionBlockSetType = SmallPtrSet<MachineBasicBlock *, 16>;
2790 for (MachineBasicBlock &MBB : *F)
2793 for (MachineBasicBlock *ChainBB : FunctionChain)
2802 for (MachineBasicBlock *RemainingBB : FunctionBlockSet)
2811 SmallVector<MachineBasicBlock *, 4> OriginalLayoutSuccessors(
2814 MachineBasicBlock *LastMBB = nullptr;
2826 for (MachineBasicBlock *ChainBB : FunctionChain) {
2838 MachineBasicBlock *PrevBB = &*std::prev(MachineFunction::iterator(ChainBB));
2844 MachineBasicBlock *TBB = nullptr, *FBB = nullptr; // For analyzeBranch.
2887 MachineBasicBlock *TBB = nullptr, *FBB = nullptr; // For analyzeBranch.
2889 MachineBasicBlock *PrevBB = &F->back();
2907 for (MachineBasicBlock *ChainBB : FunctionChain) {
2909 MachineBasicBlock *TBB = nullptr, *FBB = nullptr; // For analyzeBranch.
2946 for (MachineBasicBlock *ChainBB : FunctionChain) {
2992 MachineBasicBlock *LoopHeader = L->getHeader();
3004 MachineBasicBlock *LayoutPred =
3055 MachineBasicBlock *BB, MachineBasicBlock *&LPred,
3056 const MachineBasicBlock *LoopHeaderBB, BlockChain &Chain,
3072 MachineBasicBlock *DupBB, *DupPred;
3113 MachineBasicBlock *BB, MachineBasicBlock *LPred, BlockChain &Chain,
3128 [&](MachineBasicBlock *RemBB) {
3149 SmallVectorImpl<MachineBasicBlock *> &RemoveList = BlockWorkList;
3162 const MachineBasicBlock *PrevBB = *PrevUnplacedBlockInFilterIt;
3187 function_ref<void(MachineBasicBlock*)>(RemovalCallback);
3189 SmallVector<MachineBasicBlock *, 8> DuplicatedPreds;
3191 SmallVector<MachineBasicBlock *, 8> CandidatePreds;
3192 SmallVectorImpl<MachineBasicBlock *> *CandidatePtr = nullptr;
3206 for (MachineBasicBlock *Pred : DuplicatedPreds) {
3214 for (MachineBasicBlock *NewSucc : Pred->successors()) {
3226 static uint64_t countMBBInstruction(MachineBasicBlock *MBB) {
3238 BlockFrequency MachineBlockPlacement::scaleThreshold(MachineBasicBlock *BB) {
3243 bool MachineBlockPlacement::isBestSuccessor(MachineBasicBlock *BB,
3244 MachineBasicBlock *Pred,
3256 for (MachineBasicBlock *Succ : Pred->successors())
3282 SmallVectorImpl<MachineBasicBlock *> &Candidates,
3283 MachineBasicBlock *BB,
3285 MachineBasicBlock *Fallthrough = nullptr;
3288 SmallVector<MachineBasicBlock *, 8> Preds(BB->predecessors());
3289 SmallVector<MachineBasicBlock *, 8> Succs(BB->successors());
3292 auto CmpSucc = [&](MachineBasicBlock *A, MachineBasicBlock *B) {
3295 auto CmpPred = [&](MachineBasicBlock *A, MachineBasicBlock *B) {
3347 for (MachineBasicBlock *Pred : Preds) {
3408 for (MachineBasicBlock &MBB : *F) {
3534 for (MachineBasicBlock &MBB : MF) {
3570 DenseMap<const MachineBasicBlock *, uint64_t> BlockIndex;
3572 std::vector<const MachineBasicBlock *> CurrentBlockOrder;
3575 for (const MachineBasicBlock &MBB : *F) {
3583 for (MachineBasicBlock &MBB : *F) {
3598 for (MachineBasicBlock *Succ : MBB.successors()) {
3616 std::vector<const MachineBasicBlock *> NewBlockOrder;
3630 const std::vector<const MachineBasicBlock *> &NewBlockOrder) {
3645 SmallVector<MachineBasicBlock *, 4> PrevFallThroughs(F->getNumBlockIDs());
3651 DenseMap<const MachineBasicBlock *, size_t> NewIndex;
3652 for (const MachineBasicBlock *MBB : NewBlockOrder) {
3655 F->sort([&](MachineBasicBlock &L, MachineBasicBlock &R) {
3676 MachineBasicBlock *TBB = nullptr, *FBB = nullptr;
3693 MachineBasicBlock *HeadBB = &F->front();
3697 for (MachineBasicBlock &MBB : *F) {
3760 for (MachineBasicBlock &MBB : F) {
3766 for (MachineBasicBlock *Succ : MBB.successors()) {