diff options
author | Hans Wennborg <hans@hanshq.net> | 2015-06-20 17:14:07 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2015-06-20 17:14:07 +0000 |
commit | 6ed81cbcdb6e5f07f6ac71a446d970c2db8945a5 (patch) | |
tree | 9aeb61d8c38c47e8c4ee9c0313f6572ceff2f284 /llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h | |
parent | 056cbfe58d99fb8224279a948d2fd6eb41a3e5c2 (diff) | |
download | bcm5719-llvm-6ed81cbcdb6e5f07f6ac71a446d970c2db8945a5.tar.gz bcm5719-llvm-6ed81cbcdb6e5f07f6ac71a446d970c2db8945a5.zip |
Switch lowering: add heuristic for filling leaf nodes in the weight-balanced binary search tree
Sparse switches with profile info are lowered as weight-balanced BSTs. For
example, if the node weights are {1,1,1,1,1,1000}, the right-most node would
end up in a tree by itself, bringing it closer to the top.
However, a leaf in this BST can contain up to 3 cases, and having a single
case in a leaf node as in the example means the tree might become
unnecessarily high.
This patch adds a heauristic to the pivot selection algorithm that moves more
cases into leaf nodes unless that would lower their rank. It still doesn't
yield the optimal tree in every case, but I believe it's conservatibely correct.
llvm-svn: 240224
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h index f0c03af3f64..f225d54d189 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h @@ -342,6 +342,11 @@ private: }; typedef SmallVector<SwitchWorkListItem, 4> SwitchWorkList; + /// Determine the rank by weight of CC in [First,Last]. If CC has more weight + /// than each cluster in the range, its rank is 0. + static unsigned caseClusterRank(const CaseCluster &CC, CaseClusterIt First, + CaseClusterIt Last); + /// Emit comparison and split W into two subtrees. void splitWorkItem(SwitchWorkList &WorkList, const SwitchWorkListItem &W, Value *Cond, MachineBasicBlock *SwitchMBB); |