llvm.org GIT mirror
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).
 38 38 assert(n <= d && "Probability cannot be bigger than 1!"); 39 39 } 40 40 41 static BranchProbability getZero() { return BranchProbability(0, 1); } 42 static BranchProbability getOne() { return BranchProbability(1, 1); } 43 41 44 uint32_t getNumerator() const { return N; } 42 45 uint32_t getDenominator() const { return D; } 43 46
 286 286 return; 287 287 288 288 // 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. 291 289 MachineBasicBlock *Successor = 0; 292 BlockFrequency BestFreq;⏎ 290 BranchProbability BestProb = BranchProbability::getZero();⏎ 293 291 DEBUG(dbgs() << "Attempting merge from: " << getBlockName(BB) << "\n"); 294 292 for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(), 295 293 SE = BB->succ_end(); 297 295 if (BB == *SI || (Filter && !Filter->count(*SI))) 298 296 continue; 299 297 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) && 304 301 BB->isLayoutSuccessor(*SI))) { 305 302 Successor = *SI; 306 BestFreq = SuccFreq;⏎ 303 BestProb = SuccProb;⏎ 307 304 } 308 305 } 309 306 if (!Successor)