[llvm] r263495 - Factor out MachineBlockPlacement::fillWorkLists. NFC
Amaury Sechet via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 14 14:24:11 PDT 2016
Author: deadalnix
Date: Mon Mar 14 16:24:11 2016
New Revision: 263495
URL: http://llvm.org/viewvc/llvm-project?rev=263495&view=rev
Log:
Factor out MachineBlockPlacement::fillWorkLists. NFC
Summary: There are places in MachineBlockPlacement where a worklist is filled in pretty much identical way. The code is duplicated. This refactor it so that the same code is used in both scenarii.
Reviewers: chandlerc, majnemer, rafael, MatzeB, escha, silvas
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D18077
Modified:
llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp
Modified: llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp?rev=263495&r1=263494&r2=263495&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp Mon Mar 14 16:24:11 2016
@@ -274,6 +274,16 @@ class MachineBlockPlacement : public Mac
getFirstUnplacedBlock(MachineFunction &F, const BlockChain &PlacedChain,
MachineFunction::iterator &PrevUnplacedBlockIt,
const BlockFilterSet *BlockFilter);
+
+ /// \brief Add a basic block to the work list if it is apropriate.
+ ///
+ /// If the optional parameter BlockFilter is provided, only MBB
+ /// present in the set will be added to the worklist. If nullptr
+ /// is provided, no filtering occurs.
+ void fillWorkLists(MachineBasicBlock *MBB,
+ SmallPtrSetImpl<BlockChain *> &UpdatedPreds,
+ SmallVectorImpl<MachineBasicBlock *> &BlockWorkList,
+ const BlockFilterSet *BlockFilter);
void buildChain(MachineBasicBlock *BB, BlockChain &Chain,
SmallVectorImpl<MachineBasicBlock *> &BlockWorkList,
const BlockFilterSet *BlockFilter = nullptr);
@@ -570,6 +580,31 @@ MachineBasicBlock *MachineBlockPlacement
return nullptr;
}
+void MachineBlockPlacement::fillWorkLists(
+ MachineBasicBlock *MBB,
+ SmallPtrSetImpl<BlockChain *> &UpdatedPreds,
+ SmallVectorImpl<MachineBasicBlock *> &BlockWorkList,
+ const BlockFilterSet *BlockFilter = nullptr) {
+ BlockChain &Chain = *BlockToChain[MBB];
+ if (!UpdatedPreds.insert(&Chain).second)
+ return;
+
+ assert(Chain.UnscheduledPredecessors == 0);
+ for (MachineBasicBlock *ChainBB : Chain) {
+ assert(BlockToChain[ChainBB] == &Chain);
+ for (MachineBasicBlock *Pred : ChainBB->predecessors()) {
+ if (BlockFilter && !BlockFilter->count(Pred))
+ continue;
+ if (BlockToChain[Pred] == &Chain)
+ continue;
+ ++Chain.UnscheduledPredecessors;
+ }
+ }
+
+ if (Chain.UnscheduledPredecessors == 0)
+ BlockWorkList.push_back(*Chain.begin());
+}
+
void MachineBlockPlacement::buildChain(
MachineBasicBlock *BB, BlockChain &Chain,
SmallVectorImpl<MachineBasicBlock *> &BlockWorkList,
@@ -1067,24 +1102,8 @@ void MachineBlockPlacement::buildLoopCha
assert(LoopChain.UnscheduledPredecessors == 0);
UpdatedPreds.insert(&LoopChain);
- for (MachineBasicBlock *LoopBB : LoopBlockSet) {
- BlockChain &Chain = *BlockToChain[LoopBB];
- if (!UpdatedPreds.insert(&Chain).second)
- continue;
-
- assert(Chain.UnscheduledPredecessors == 0);
- for (MachineBasicBlock *ChainBB : Chain) {
- assert(BlockToChain[ChainBB] == &Chain);
- for (MachineBasicBlock *Pred : ChainBB->predecessors()) {
- if (BlockToChain[Pred] == &Chain || !LoopBlockSet.count(Pred))
- continue;
- ++Chain.UnscheduledPredecessors;
- }
- }
-
- if (Chain.UnscheduledPredecessors == 0)
- BlockWorkList.push_back(*Chain.begin());
- }
+ for (MachineBasicBlock *LoopBB : LoopBlockSet)
+ fillWorkLists(LoopBB, UpdatedPreds, BlockWorkList, &LoopBlockSet);
buildChain(LoopTop, LoopChain, BlockWorkList, &LoopBlockSet);
@@ -1185,24 +1204,8 @@ void MachineBlockPlacement::buildCFGChai
SmallVector<MachineBasicBlock *, 16> BlockWorkList;
SmallPtrSet<BlockChain *, 4> UpdatedPreds;
- for (MachineBasicBlock &MBB : F) {
- BlockChain &Chain = *BlockToChain[&MBB];
- if (!UpdatedPreds.insert(&Chain).second)
- continue;
-
- assert(Chain.UnscheduledPredecessors == 0);
- for (MachineBasicBlock *ChainBB : Chain) {
- assert(BlockToChain[ChainBB] == &Chain);
- for (MachineBasicBlock *Pred : ChainBB->predecessors()) {
- if (BlockToChain[Pred] == &Chain)
- continue;
- ++Chain.UnscheduledPredecessors;
- }
- }
-
- if (Chain.UnscheduledPredecessors == 0)
- BlockWorkList.push_back(*Chain.begin());
- }
+ for (MachineBasicBlock &MBB : F)
+ fillWorkLists(&MBB, UpdatedPreds, BlockWorkList);
BlockChain &FunctionChain = *BlockToChain[&F.front()];
buildChain(&F.front(), FunctionChain, BlockWorkList);
More information about the llvm-commits
mailing list