addToMem, addToMemE,
mkWordCLit,
- mkStringCLit,
+ mkStringCLit, mkByteStringCLit,
packHalfWordsCLit,
blankWord
) where
import PackageConfig
import Outputable
+import MachRegs (callerSaveVolatileRegs)
+ -- HACK: this is part of the NCG so we shouldn't use this, but we need
+ -- it for now to eliminate the need for saved regs to be in CmmCall.
+ -- The long term solution is to factor callerSaveVolatileRegs
+ -- from nativeGen into codeGen
+
import Data.Char
import Data.Bits
import Data.Word
-> [(CmmExpr,MachHint)]
-> Maybe [GlobalReg]
-> Code
-emitRtsCall' res fun args vols = stmtC (CmmCall target res args vols)
+emitRtsCall' res fun args vols = do
+ stmtsC caller_save
+ stmtC (CmmCall target res args)
+ stmtsC caller_load
where
+ (caller_save, caller_load) = callerSaveVolatileRegs vols
target = CmmForeignCall fun_expr CCallConv
fun_expr = mkLblExpr (mkRtsCodeLabel fun)
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