X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FcodeGen%2FCgUtils.hs;h=804aeabd13fe95c139ccc925afd877a0ef746b08;hb=7ac266d097639620e4fea22c40450c8d7822f5fb;hp=ab39080c16ed325afb9b0db2cedc5e1213f0bc0e;hpb=49c98d143c382a1341e1046f5ca00819a25691ba;p=ghc-hetmet.git diff --git a/compiler/codeGen/CgUtils.hs b/compiler/codeGen/CgUtils.hs index ab39080..804aeab 100644 --- a/compiler/codeGen/CgUtils.hs +++ b/compiler/codeGen/CgUtils.hs @@ -474,15 +474,18 @@ mk_switch tag_expr branches mb_deflt lo_tag hi_tag via_C where use_switch = {- pprTrace "mk_switch" ( ppr tag_expr <+> text "n_tags:" <+> int n_tags <+> + text "branches:" <+> ppr (map fst branches) <+> text "n_branches:" <+> int n_branches <+> - text "lo_tag: " <+> int lo_tag <+> - text "hi_tag: " <+> int hi_tag <+> - text "real_lo_tag: " <+> int real_lo_tag <+> - text "real_hi_tag: " <+> int real_hi_tag) $ -} + text "lo_tag:" <+> int lo_tag <+> + text "hi_tag:" <+> int hi_tag <+> + text "real_lo_tag:" <+> int real_lo_tag <+> + text "real_hi_tag:" <+> int real_hi_tag) $ -} ASSERT( n_branches > 1 && n_tags > 1 ) - n_tags > 2 && (small || dense || via_C) - -- a 2-branch switch always turns into an if. - small = n_tags <= 4 + n_tags > 2 && (via_C || (dense && big_enough)) + -- up to 4 branches we use a decision tree, otherwise + -- a switch (== jump table in the NCG). This seems to be + -- optimal, and corresponds with what gcc does. + big_enough = n_branches > 4 dense = n_branches > (n_tags `div` 2) n_branches = length branches