From 036eb7c125db75b59c58ea84a24e888b78189cd2 Mon Sep 17 00:00:00 2001 From: Xinliang David Li Date: Fri, 1 Jul 2016 05:46:48 +0000 Subject: [PATCH] [MBP] method interface cleanup Make worklist and ehworklist member of the class so that they don't need to be passed around. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274333 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/MachineBlockPlacement.cpp | 45 ++++++++++++--------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/lib/CodeGen/MachineBlockPlacement.cpp b/lib/CodeGen/MachineBlockPlacement.cpp index 555fde62336..9f8ed7776e9 100644 --- a/lib/CodeGen/MachineBlockPlacement.cpp +++ b/lib/CodeGen/MachineBlockPlacement.cpp @@ -237,6 +237,10 @@ class MachineBlockPlacement : public MachineFunctionPass { /// \brief A typedef for a block filter set. typedef SmallPtrSet BlockFilterSet; + /// \brief work lists of blocks that are ready to be laid out + SmallVector BlockWorkList; + SmallVector EHPadWorkList; + /// \brief Machine Function MachineFunction *F; @@ -280,8 +284,6 @@ class MachineBlockPlacement : public MachineFunctionPass { DenseMap BlockToChain; void markChainSuccessors(BlockChain &Chain, MachineBasicBlock *LoopHeaderBB, - SmallVectorImpl &BlockWorkList, - SmallVectorImpl &EHPadWorkList, const BlockFilterSet *BlockFilter = nullptr); BranchProbability collectViableSuccessors(MachineBasicBlock *BB, BlockChain &Chain, @@ -315,12 +317,8 @@ class MachineBlockPlacement : public MachineFunctionPass { /// is provided, no filtering occurs. void fillWorkLists(MachineBasicBlock *MBB, SmallPtrSetImpl &UpdatedPreds, - SmallVectorImpl &BlockWorkList, - SmallVectorImpl &EHPadWorkList, const BlockFilterSet *BlockFilter); void buildChain(MachineBasicBlock *BB, BlockChain &Chain, - SmallVectorImpl &BlockWorkList, - SmallVectorImpl &EHPadWorkList, const BlockFilterSet *BlockFilter = nullptr); MachineBasicBlock *findBestLoopTop(MachineLoop &L, const BlockFilterSet &LoopBlockSet); @@ -389,8 +387,6 @@ static std::string getBlockName(MachineBasicBlock *BB) { /// chain which reach the zero-predecessor state to the worklist passed in. void MachineBlockPlacement::markChainSuccessors( BlockChain &Chain, MachineBasicBlock *LoopHeaderBB, - SmallVectorImpl &BlockWorkList, - SmallVectorImpl &EHPadWorkList, const BlockFilterSet *BlockFilter) { // Walk all the blocks in this chain, marking their successors as having // a predecessor placed. @@ -812,8 +808,6 @@ MachineBasicBlock *MachineBlockPlacement::getFirstUnplacedBlock( void MachineBlockPlacement::fillWorkLists( MachineBasicBlock *MBB, SmallPtrSetImpl &UpdatedPreds, - SmallVectorImpl &BlockWorkList, - SmallVectorImpl &EHPadWorkList, const BlockFilterSet *BlockFilter = nullptr) { BlockChain &Chain = *BlockToChain[MBB]; if (!UpdatedPreds.insert(&Chain).second) @@ -843,16 +837,13 @@ void MachineBlockPlacement::fillWorkLists( void MachineBlockPlacement::buildChain( MachineBasicBlock *BB, BlockChain &Chain, - SmallVectorImpl &BlockWorkList, - SmallVectorImpl &EHPadWorkList, const BlockFilterSet *BlockFilter) { assert(BB && "BB must not be null.\n"); assert(BlockToChain[BB] == &Chain && "BlockToChainMap mis-match.\n"); MachineFunction::iterator PrevUnplacedBlockIt = F->begin(); MachineBasicBlock *LoopHeaderBB = BB; - markChainSuccessors(Chain, LoopHeaderBB, BlockWorkList, EHPadWorkList, - BlockFilter); + markChainSuccessors(Chain, LoopHeaderBB, BlockFilter); BB = *std::prev(Chain.end()); for (;;) { assert(BB && "null block found at end of chain in loop."); @@ -888,8 +879,7 @@ void MachineBlockPlacement::buildChain( SuccChain.UnscheduledPredecessors = 0; DEBUG(dbgs() << "Merging from " << getBlockName(BB) << " to " << getBlockName(BestSucc) << "\n"); - markChainSuccessors(SuccChain, LoopHeaderBB, BlockWorkList, EHPadWorkList, - BlockFilter); + markChainSuccessors(SuccChain, LoopHeaderBB, BlockFilter); Chain.merge(BestSucc, &SuccChain); BB = *std::prev(Chain.end()); } @@ -1307,8 +1297,8 @@ void MachineBlockPlacement::buildLoopChains(MachineLoop &L) { for (MachineLoop *InnerLoop : L) buildLoopChains(*InnerLoop); - SmallVector BlockWorkList; - SmallVector EHPadWorkList; + assert(BlockWorkList.empty()); + assert(EHPadWorkList.empty()); BlockFilterSet LoopBlockSet = collectLoopBlockSet(L); // Check if we have profile data for this function. If yes, we will rotate @@ -1343,10 +1333,9 @@ void MachineBlockPlacement::buildLoopChains(MachineLoop &L) { UpdatedPreds.insert(&LoopChain); for (MachineBasicBlock *LoopBB : LoopBlockSet) - fillWorkLists(LoopBB, UpdatedPreds, BlockWorkList, EHPadWorkList, - &LoopBlockSet); + fillWorkLists(LoopBB, UpdatedPreds, &LoopBlockSet); - buildChain(LoopTop, LoopChain, BlockWorkList, EHPadWorkList, &LoopBlockSet); + buildChain(LoopTop, LoopChain, &LoopBlockSet); if (RotateLoopWithProfile) rotateLoopWithProfile(LoopChain, L, LoopBlockSet); @@ -1385,6 +1374,9 @@ void MachineBlockPlacement::buildLoopChains(MachineLoop &L) { } assert(!BadLoop && "Detected problems with the placement of this loop."); }); + + BlockWorkList.clear(); + EHPadWorkList.clear(); } /// When OutlineOpitonalBranches is on, this method colects BBs that @@ -1450,15 +1442,15 @@ void MachineBlockPlacement::buildCFGChains() { for (MachineLoop *L : *MLI) buildLoopChains(*L); - SmallVector BlockWorkList; - SmallVector EHPadWorkList; + assert(BlockWorkList.empty()); + assert(EHPadWorkList.empty()); SmallPtrSet UpdatedPreds; for (MachineBasicBlock &MBB : *F) - fillWorkLists(&MBB, UpdatedPreds, BlockWorkList, EHPadWorkList); + fillWorkLists(&MBB, UpdatedPreds); BlockChain &FunctionChain = *BlockToChain[&F->front()]; - buildChain(&F->front(), FunctionChain, BlockWorkList, EHPadWorkList); + buildChain(&F->front(), FunctionChain); #ifndef NDEBUG typedef SmallPtrSet FunctionBlockSetType; @@ -1539,6 +1531,9 @@ void MachineBlockPlacement::buildCFGChains() { MachineBasicBlock *TBB = nullptr, *FBB = nullptr; // For AnalyzeBranch. if (!TII->AnalyzeBranch(F->back(), TBB, FBB, Cond)) F->back().updateTerminator(); + + BlockWorkList.clear(); + EHPadWorkList.clear(); } void MachineBlockPlacement::optimizeBranches() {