mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-04 06:12:18 +00:00
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@263495 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c37b05528e
commit
ce1afcccd0
@ -274,6 +274,16 @@ class MachineBlockPlacement : public MachineFunctionPass {
|
|||||||
getFirstUnplacedBlock(MachineFunction &F, const BlockChain &PlacedChain,
|
getFirstUnplacedBlock(MachineFunction &F, const BlockChain &PlacedChain,
|
||||||
MachineFunction::iterator &PrevUnplacedBlockIt,
|
MachineFunction::iterator &PrevUnplacedBlockIt,
|
||||||
const BlockFilterSet *BlockFilter);
|
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,
|
void buildChain(MachineBasicBlock *BB, BlockChain &Chain,
|
||||||
SmallVectorImpl<MachineBasicBlock *> &BlockWorkList,
|
SmallVectorImpl<MachineBasicBlock *> &BlockWorkList,
|
||||||
const BlockFilterSet *BlockFilter = nullptr);
|
const BlockFilterSet *BlockFilter = nullptr);
|
||||||
@ -570,6 +580,31 @@ MachineBasicBlock *MachineBlockPlacement::getFirstUnplacedBlock(
|
|||||||
return nullptr;
|
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(
|
void MachineBlockPlacement::buildChain(
|
||||||
MachineBasicBlock *BB, BlockChain &Chain,
|
MachineBasicBlock *BB, BlockChain &Chain,
|
||||||
SmallVectorImpl<MachineBasicBlock *> &BlockWorkList,
|
SmallVectorImpl<MachineBasicBlock *> &BlockWorkList,
|
||||||
@ -1067,24 +1102,8 @@ void MachineBlockPlacement::buildLoopChains(MachineFunction &F,
|
|||||||
assert(LoopChain.UnscheduledPredecessors == 0);
|
assert(LoopChain.UnscheduledPredecessors == 0);
|
||||||
UpdatedPreds.insert(&LoopChain);
|
UpdatedPreds.insert(&LoopChain);
|
||||||
|
|
||||||
for (MachineBasicBlock *LoopBB : LoopBlockSet) {
|
for (MachineBasicBlock *LoopBB : LoopBlockSet)
|
||||||
BlockChain &Chain = *BlockToChain[LoopBB];
|
fillWorkLists(LoopBB, UpdatedPreds, BlockWorkList, &LoopBlockSet);
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
buildChain(LoopTop, LoopChain, BlockWorkList, &LoopBlockSet);
|
buildChain(LoopTop, LoopChain, BlockWorkList, &LoopBlockSet);
|
||||||
|
|
||||||
@ -1185,24 +1204,8 @@ void MachineBlockPlacement::buildCFGChains(MachineFunction &F) {
|
|||||||
SmallVector<MachineBasicBlock *, 16> BlockWorkList;
|
SmallVector<MachineBasicBlock *, 16> BlockWorkList;
|
||||||
|
|
||||||
SmallPtrSet<BlockChain *, 4> UpdatedPreds;
|
SmallPtrSet<BlockChain *, 4> UpdatedPreds;
|
||||||
for (MachineBasicBlock &MBB : F) {
|
for (MachineBasicBlock &MBB : F)
|
||||||
BlockChain &Chain = *BlockToChain[&MBB];
|
fillWorkLists(&MBB, UpdatedPreds, BlockWorkList);
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
BlockChain &FunctionChain = *BlockToChain[&F.front()];
|
BlockChain &FunctionChain = *BlockToChain[&F.front()];
|
||||||
buildChain(&F.front(), FunctionChain, BlockWorkList);
|
buildChain(&F.front(), FunctionChain, BlockWorkList);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user