AMDGPU/SI: Reserve appropriate number of sgprs for flat scratch init.
[oota-llvm.git] / lib / Analysis / BranchProbabilityInfo.cpp
index b813dca9369a029ccaba9d51bdd4800cceb03d52..6cdf43a06a9f559f47a725814e327420d9144f0b 100644 (file)
@@ -514,11 +514,10 @@ void BranchProbabilityInfo::print(raw_ostream &OS) const {
   // We print the probabilities from the last function the analysis ran over,
   // or the function it is currently running over.
   assert(LastF && "Cannot print prior to running over a function");
-  for (Function::const_iterator BI = LastF->begin(), BE = LastF->end();
-       BI != BE; ++BI) {
-    for (succ_const_iterator SI = succ_begin(BI), SE = succ_end(BI);
-         SI != SE; ++SI) {
-      printEdgeProbability(OS << "  ", BI, *SI);
+  for (const auto &BI : *LastF) {
+    for (succ_const_iterator SI = succ_begin(&BI), SE = succ_end(&BI); SI != SE;
+         ++SI) {
+      printEdgeProbability(OS << "  ", &BI, *SI);
     }
   }
 }
@@ -624,6 +623,11 @@ getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const {
   uint32_t N = getEdgeWeight(Src, IndexInSuccessors);
   uint32_t D = getSumForBlock(Src);
 
+  // It is possible that the edge weight on the only successor edge of Src is
+  // zero, in which case we return 100%.
+  if (N == 0 && D == 0)
+    return BranchProbability::getOne();
+
   return BranchProbability(N, D);
 }
 
@@ -635,9 +639,20 @@ getEdgeProbability(const BasicBlock *Src, const BasicBlock *Dst) const {
   uint32_t N = getEdgeWeight(Src, Dst);
   uint32_t D = getSumForBlock(Src);
 
+  // It is possible that the edge weight on the only successor edge of Src is
+  // zero, in which case we return 100%.
+  if (N == 0 && D == 0)
+    return BranchProbability::getOne();
+
   return BranchProbability(N, D);
 }
 
+BranchProbability
+BranchProbabilityInfo::getEdgeProbability(const BasicBlock *Src,
+                                          succ_const_iterator Dst) const {
+  return getEdgeProbability(Src, Dst.getSuccessorIndex());
+}
+
 raw_ostream &
 BranchProbabilityInfo::printEdgeProbability(raw_ostream &OS,
                                             const BasicBlock *Src,