[llvm-commits] [PATCH] Update definition of an edge in BranchProbabilityInfo from (SrcBlock, DstBlock) to (PredBlock, index in Successors)

Manman Ren mren at apple.com
Tue Aug 21 17:12:25 PDT 2012

Hi all,

We used to associate branch weight with a pair of blocks (SrcBlock, DstBlock) in BranchProbabilityInfo:
-  typedef std::pair<const BasicBlock *, const BasicBlock *> Edge;
+  // Since we allow duplicate edges from one basic block to another, we use
+  // a pair (PredBlock and an index in the successors) to specify an edge.
+  typedef std::pair<const BasicBlock *, unsigned> Edge;

Since we can have multiple edges from SrcBlock to DstBlock, the definition of an edge needs to be updated in BranchProbabilityInfo.

The patch also tries to make sure we set the weight correctly when building SelectionDAG from LLVM IR, especially when converting a Switch.
IntegersSubsetMapping is updated to calculate the weight for each cluster.
We used to do the following, which is not correct when the weights for items in the cluster is not equal.
-    unsigned W = 0;
-    if (BPI) {
-      W = BPI->getEdgeWeight(SI.getParent(), C.second->getBasicBlock());
-      if (!W)
-        W = 16;
-      W *= C.first.Weight;
-      BPI->setEdgeWeight(SI.getParent(), C.second->getBasicBlock(), W);  
-    }
+    // Update edge weight for the cluster.
+    unsigned W = C.first.Weight;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: edgeweight4.patch
Type: application/octet-stream
Size: 28540 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120821/e19a7180/attachment.obj>

More information about the llvm-commits mailing list