[llvm-commits] [llvm] r142762 - in /llvm/trunk: include/llvm/Support/BranchProbability.h lib/CodeGen/MachineBlockPlacement.cpp

Chandler Carruth chandlerc at gmail.com
Sun Oct 23 13:10:34 PDT 2011


Author: chandlerc
Date: Sun Oct 23 15:10:34 2011
New Revision: 142762

URL: http://llvm.org/viewvc/llvm-project?rev=142762&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/Support/BranchProbability.h
    llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp

Modified: llvm/trunk/include/llvm/Support/BranchProbability.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/BranchProbability.h?rev=142762&r1=142761&r2=142762&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/BranchProbability.h (original)
+++ llvm/trunk/include/llvm/Support/BranchProbability.h Sun Oct 23 15:10:34 2011
@@ -39,6 +39,9 @@
     assert(n <= d && "Probability cannot be bigger than 1!");
   }
 
+  static BranchProbability getZero() { return BranchProbability(0, 1); }
+  static BranchProbability getOne() { return BranchProbability(1, 1); }
+
   uint32_t getNumerator() const { return N; }
   uint32_t getDenominator() const { return D; }
 

Modified: llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp?rev=142762&r1=142761&r2=142762&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp Sun Oct 23 15:10:34 2011
@@ -287,10 +287,8 @@
     return;
 
   // Walk through the successors looking for the highest probability edge.
-  // FIXME: This is an annoying way to do the comparison, but it's correct.
-  // Support should be added to BranchProbability to properly compare two.
   MachineBasicBlock *Successor = 0;
-  BlockFrequency BestFreq;
+  BranchProbability BestProb = BranchProbability::getZero();
   DEBUG(dbgs() << "Attempting merge from: " << getBlockName(BB) << "\n");
   for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(),
                                         SE = BB->succ_end();
@@ -298,13 +296,12 @@
     if (BB == *SI || (Filter && !Filter->count(*SI)))
       continue;
 
-    BlockFrequency SuccFreq(BlockFrequency::getEntryFrequency());
-    SuccFreq *= MBPI->getEdgeProbability(BB, *SI);
-    DEBUG(dbgs() << "    " << getBlockName(*SI) << " -> " << SuccFreq << "\n");
-    if (!Successor || SuccFreq > BestFreq || (!(SuccFreq < BestFreq) &&
+    BranchProbability SuccProb = MBPI->getEdgeProbability(BB, *SI);
+    DEBUG(dbgs() << "    " << getBlockName(*SI) << " -> " << SuccProb << "\n");
+    if (!Successor || SuccProb > BestProb || (!(SuccProb < BestProb) &&
                                               BB->isLayoutSuccessor(*SI))) {
       Successor = *SI;
-      BestFreq = SuccFreq;
+      BestProb = SuccProb;
     }
   }
   if (!Successor)





More information about the llvm-commits mailing list