summaryrefslogtreecommitdiff
path: root/compiler/codeGen/StgCmmUtils.hs
diff options
context:
space:
mode:
authorJoachim Breitner <mail@joachim-breitner.de>2015-03-02 21:35:05 +0100
committerJoachim Breitner <mail@joachim-breitner.de>2015-03-02 23:12:46 +0100
commit5bdfb9beb28206a014d817ddf15f1c6c36d79a69 (patch)
tree48812ddb3125e122b68d5ac07e4571065cafb791 /compiler/codeGen/StgCmmUtils.hs
parentc3eee14d31585445d4a7eff5b6c69a815b911059 (diff)
downloadhaskell-5bdfb9beb28206a014d817ddf15f1c6c36d79a69.tar.gz
Small emitCmmSwitch/emitCmmLitSwitch refactoring
both use the same logic to divide, so put it in divideBranches :: Ord a => [(a,b)] -> ([(a,b)], a, [(a,b)])
Diffstat (limited to 'compiler/codeGen/StgCmmUtils.hs')
-rw-r--r--compiler/codeGen/StgCmmUtils.hs23
1 files changed, 11 insertions, 12 deletions
diff --git a/compiler/codeGen/StgCmmUtils.hs b/compiler/codeGen/StgCmmUtils.hs
index 763177f297..98295c9836 100644
--- a/compiler/codeGen/StgCmmUtils.hs
+++ b/compiler/codeGen/StgCmmUtils.hs
@@ -626,14 +626,18 @@ mk_switch tag_expr branches mb_deflt lo_tag hi_tag via_C
-- lo_tag <= mid_tag < hi_tag
-- lo_branches have tags < mid_tag
-- hi_branches have tags >= mid_tag
+ (lo_branches, mid_tag, hi_branches) = divideBranches branches
- (mid_tag,_) = branches !! (n_branches `div` 2)
- -- 2 branches => n_branches `div` 2 = 1
- -- => branches !! 1 give the *second* tag
- -- There are always at least 2 branches here
+divideBranches :: Ord a => [(a,b)] -> ([(a,b)], a, [(a,b)])
+divideBranches branches = (lo_branches, mid, hi_branches)
+ where
+ -- 2 branches => n_branches `div` 2 = 1
+ -- => branches !! 1 give the *second* tag
+ -- There are always at least 2 branches here
+ (mid,_) = branches !! (length branches `div` 2)
(lo_branches, hi_branches) = span is_lo branches
- is_lo (t,_) = t < mid_tag
+ is_lo (t,_) = t < mid
--------------
emitCmmLitSwitch :: CmmExpr -- Tag to switch on
@@ -681,7 +685,7 @@ mk_lit_switch scrut deflt bounds [(lit,blk)]
where
-- If the bounds already imply scrut == lit, then we can skip the final check (#10129)
l `onlyWithinBounds'` (Just lo, Just hi) = l `onlyWithinBounds` (lo, hi)
- l `onlyWithinBounds'` _ = False
+ _ `onlyWithinBounds'` _ = False
mk_lit_switch scrut deflt_blk_id (lo_bound, hi_bound) branches
= do dflags <- getDynFlags
@@ -689,12 +693,7 @@ mk_lit_switch scrut deflt_blk_id (lo_bound, hi_bound) branches
hi_blk <- mk_lit_switch scrut deflt_blk_id bounds_hi hi_branches
mkCmmIfThenElse (cond dflags) lo_blk hi_blk
where
- n_branches = length branches
- (mid_lit,_) = branches !! (n_branches `div` 2)
- -- See notes above re mid_tag
-
- (lo_branches, hi_branches) = span is_lo branches
- is_lo (t,_) = t < mid_lit
+ (lo_branches, mid_lit, hi_branches) = divideBranches branches
bounds_lo = (lo_bound, Just mid_lit)
bounds_hi = (Just mid_lit, hi_bound)