forked from OSchip/llvm-project
Begin chipping away at one of the biggest quadratic-ish behaviors in
this pass. We're leaving already merged blocks on the worklist, and scanning them again and again only to determine each time through that indeed they aren't viable. We can instead remove them once we're going to have to scan the worklist. This is the easy way to implement removing them. If this remains on the profile (as I somewhat suspect it will), we can get a lot more clever here, as the worklist's order is essentially irrelevant. We can use swapping and fold the two loops to reduce overhead even when there are many blocks on the worklist but only a few of them are removed. llvm-svn: 144531
This commit is contained in:
parent
84cd44c750
commit
0af6a0bb69
|
@ -377,6 +377,23 @@ MachineBasicBlock *MachineBlockPlacement::selectBestSuccessor(
|
||||||
return BestSucc;
|
return BestSucc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
/// \brief Predicate struct to detect blocks already placed.
|
||||||
|
class IsBlockPlaced {
|
||||||
|
const BlockChain &PlacedChain;
|
||||||
|
const BlockToChainMapType &BlockToChain;
|
||||||
|
|
||||||
|
public:
|
||||||
|
IsBlockPlaced(const BlockChain &PlacedChain,
|
||||||
|
const BlockToChainMapType &BlockToChain)
|
||||||
|
: PlacedChain(PlacedChain), BlockToChain(BlockToChain) {}
|
||||||
|
|
||||||
|
bool operator()(MachineBasicBlock *BB) const {
|
||||||
|
return BlockToChain.lookup(BB) == &PlacedChain;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// \brief Select the best block from a worklist.
|
/// \brief Select the best block from a worklist.
|
||||||
///
|
///
|
||||||
/// This looks through the provided worklist as a list of candidate basic
|
/// This looks through the provided worklist as a list of candidate basic
|
||||||
|
@ -390,13 +407,20 @@ MachineBasicBlock *MachineBlockPlacement::selectBestSuccessor(
|
||||||
MachineBasicBlock *MachineBlockPlacement::selectBestCandidateBlock(
|
MachineBasicBlock *MachineBlockPlacement::selectBestCandidateBlock(
|
||||||
BlockChain &Chain, SmallVectorImpl<MachineBasicBlock *> &WorkList,
|
BlockChain &Chain, SmallVectorImpl<MachineBasicBlock *> &WorkList,
|
||||||
const BlockFilterSet *BlockFilter) {
|
const BlockFilterSet *BlockFilter) {
|
||||||
|
// Once we need to walk the worklist looking for a candidate, cleanup the
|
||||||
|
// worklist of already placed entries.
|
||||||
|
// FIXME: If this shows up on profiles, it could be folded (at the cost of
|
||||||
|
// some code complexity) into the loop below.
|
||||||
|
WorkList.erase(std::remove_if(WorkList.begin(), WorkList.end(),
|
||||||
|
IsBlockPlaced(Chain, BlockToChain)),
|
||||||
|
WorkList.end());
|
||||||
|
|
||||||
MachineBasicBlock *BestBlock = 0;
|
MachineBasicBlock *BestBlock = 0;
|
||||||
BlockFrequency BestFreq;
|
BlockFrequency BestFreq;
|
||||||
for (SmallVectorImpl<MachineBasicBlock *>::iterator WBI = WorkList.begin(),
|
for (SmallVectorImpl<MachineBasicBlock *>::iterator WBI = WorkList.begin(),
|
||||||
WBE = WorkList.end();
|
WBE = WorkList.end();
|
||||||
WBI != WBE; ++WBI) {
|
WBI != WBE; ++WBI) {
|
||||||
if (BlockFilter && !BlockFilter->count(*WBI))
|
assert(!BlockFilter || BlockFilter->count(*WBI));
|
||||||
continue;
|
|
||||||
BlockChain &SuccChain = *BlockToChain[*WBI];
|
BlockChain &SuccChain = *BlockToChain[*WBI];
|
||||||
if (&SuccChain == &Chain) {
|
if (&SuccChain == &Chain) {
|
||||||
DEBUG(dbgs() << " " << getBlockName(*WBI)
|
DEBUG(dbgs() << " " << getBlockName(*WBI)
|
||||||
|
|
Loading…
Reference in New Issue