llvm.org GIT mirror llvm / 66d847c
Now that we have comparison on probabilities, add some static functions to get important constant branch probabilities and use them for finding the best branch out of a set of possibilities. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142762 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 8 years ago
2 changed file(s) with 8 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
3838 assert(n <= d && "Probability cannot be bigger than 1!");
3939 }
4040
41 static BranchProbability getZero() { return BranchProbability(0, 1); }
42 static BranchProbability getOne() { return BranchProbability(1, 1); }
43
4144 uint32_t getNumerator() const { return N; }
4245 uint32_t getDenominator() const { return D; }
4346
286286 return;
287287
288288 // Walk through the successors looking for the highest probability edge.
289 // FIXME: This is an annoying way to do the comparison, but it's correct.
290 // Support should be added to BranchProbability to properly compare two.
291289 MachineBasicBlock *Successor = 0;
292 BlockFrequency BestFreq;
290 BranchProbability BestProb = BranchProbability::getZero();
293291 DEBUG(dbgs() << "Attempting merge from: " << getBlockName(BB) << "\n");
294292 for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(),
295293 SE = BB->succ_end();
297295 if (BB == *SI || (Filter && !Filter->count(*SI)))
298296 continue;
299297
300 BlockFrequency SuccFreq(BlockFrequency::getEntryFrequency());
301 SuccFreq *= MBPI->getEdgeProbability(BB, *SI);
302 DEBUG(dbgs() << " " << getBlockName(*SI) << " -> " << SuccFreq << "\n");
303 if (!Successor || SuccFreq > BestFreq || (!(SuccFreq < BestFreq) &&
298 BranchProbability SuccProb = MBPI->getEdgeProbability(BB, *SI);
299 DEBUG(dbgs() << " " << getBlockName(*SI) << " -> " << SuccProb << "\n");
300 if (!Successor || SuccProb > BestProb || (!(SuccProb < BestProb) &&
304301 BB->isLayoutSuccessor(*SI))) {
305302 Successor = *SI;
306 BestFreq = SuccFreq;
303 BestProb = SuccProb;
307304 }
308305 }
309306 if (!Successor)