mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-16 08:29:43 +00:00
Add InEdges (edges from header to the loop) in Loop Branch Heuristics, so
there is no frequency difference whether condition is in the header or in the latch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136398 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1ddaa9c1c6
commit
fa44725233
@ -205,6 +205,9 @@ void BranchProbabilityAnalysis::calcLoopBranchHeuristics(BasicBlock *BB) {
|
||||
|
||||
SmallVector<BasicBlock *, 8> BackEdges;
|
||||
SmallVector<BasicBlock *, 8> ExitingEdges;
|
||||
SmallVector<BasicBlock *, 8> InEdges; // Edges from header to the loop.
|
||||
|
||||
bool isHeader = BB == L->getHeader();
|
||||
|
||||
for (succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I) {
|
||||
BasicBlock *Succ = *I;
|
||||
@ -213,6 +216,8 @@ void BranchProbabilityAnalysis::calcLoopBranchHeuristics(BasicBlock *BB) {
|
||||
ExitingEdges.push_back(Succ);
|
||||
else if (Succ == L->getHeader())
|
||||
BackEdges.push_back(Succ);
|
||||
else if (isHeader)
|
||||
InEdges.push_back(Succ);
|
||||
}
|
||||
|
||||
if (uint32_t numBackEdges = BackEdges.size()) {
|
||||
@ -227,6 +232,18 @@ void BranchProbabilityAnalysis::calcLoopBranchHeuristics(BasicBlock *BB) {
|
||||
}
|
||||
}
|
||||
|
||||
if (uint32_t numInEdges = InEdges.size()) {
|
||||
uint32_t inWeight = LBH_TAKEN_WEIGHT / numInEdges;
|
||||
if (inWeight < NORMAL_WEIGHT)
|
||||
inWeight = NORMAL_WEIGHT;
|
||||
|
||||
for (SmallVector<BasicBlock *, 8>::iterator EI = InEdges.begin(),
|
||||
EE = InEdges.end(); EI != EE; ++EI) {
|
||||
BasicBlock *Back = *EI;
|
||||
BP->setEdgeWeight(BB, Back, inWeight);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t numExitingEdges = ExitingEdges.size();
|
||||
if (uint32_t numNonExitingEdges = numSuccs - numExitingEdges) {
|
||||
uint32_t exitWeight = LBH_NONTAKEN_WEIGHT / numNonExitingEdges;
|
||||
|
Loading…
Reference in New Issue
Block a user