Switch lowering: use profile info to build weight-balanced binary search trees
authorHans Wennborg <hans@hanshq.net>
Thu, 30 Apr 2015 00:57:37 +0000 (00:57 +0000)
committerHans Wennborg <hans@hanshq.net>
Thu, 30 Apr 2015 00:57:37 +0000 (00:57 +0000)
commit49baa9f89617593975fffd665b8c0b606f874aa0
tree3947f9c566803bd5da8a030111243e2e9fbf00c2
parenta607be94caf73ac9001f2cc01bae6298d76b29ae
Switch lowering: use profile info to build weight-balanced binary search trees

This will cause hot nodes to appear closer to the root.

The literature says building the tree like this makes it a near-optimal (in
terms of search time given key frequencies) binary search tree. In LLVM's case,
we can do up to 3 comparisons in each leaf node, so it might be better to opt
for lower tree height in some cases; that's something to look into in the
future.

Differential Revision: http://reviews.llvm.org/D9318

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236192 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
test/CodeGen/Generic/MachineBranchProb.ll
test/CodeGen/X86/switch.ll