diff options
author | simonmar <unknown> | 2000-09-04 14:10:38 +0000 |
---|---|---|
committer | simonmar <unknown> | 2000-09-04 14:10:38 +0000 |
commit | 7cc05eb4300d3d9c60161898cd9bb9078eacbed5 (patch) | |
tree | 9482fc175a736539087bfede533e83ca55078af1 /ghc/compiler/absCSyn | |
parent | 5b4688fd245333edb887a786161d46beae231078 (diff) | |
download | haskell-7cc05eb4300d3d9c60161898cd9bb9078eacbed5.tar.gz |
[project @ 2000-09-04 14:10:38 by simonmar]
Convert one of the alternatives in an algebraic switch into the
default, if we don't already have a default. This generates better
code in particular for inline comparison primops.
Noticed by: Qrczak
Diffstat (limited to 'ghc/compiler/absCSyn')
-rw-r--r-- | ghc/compiler/absCSyn/AbsCUtils.lhs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/ghc/compiler/absCSyn/AbsCUtils.lhs b/ghc/compiler/absCSyn/AbsCUtils.lhs index 7c7151af68..f380da9534 100644 --- a/ghc/compiler/absCSyn/AbsCUtils.lhs +++ b/ghc/compiler/absCSyn/AbsCUtils.lhs @@ -28,10 +28,11 @@ import Unique ( Unique{-instance Eq-} ) import UniqSupply ( uniqFromSupply, uniqsFromSupply, splitUniqSupply, UniqSupply ) import CmdLineOpts ( opt_OutputLanguage, opt_EmitCExternDecls ) -import Maybes ( maybeToBool ) import PrimOp ( PrimOp(..), CCall(..), isDynamicTarget ) import Panic ( panic ) +import Maybe ( isJust ) + infixr 9 `thenFlt` \end{code} @@ -101,8 +102,16 @@ mkAbsCStmtList' other r = other : r mkAlgAltsCSwitch :: CAddrMode -> [(ConTag, AbstractC)] -> AbstractC -> AbstractC mkAlgAltsCSwitch scrutinee tagged_alts deflt_absc - = CSwitch scrutinee (adjust tagged_alts) deflt_absc + | isJust (nonemptyAbsC deflt_absc) + = CSwitch scrutinee (adjust tagged_alts) deflt_absc + | otherwise + = CSwitch scrutinee (adjust rest) first_alt where + -- it's ok to convert one of the alts into a default if we don't already have + -- one, because this is an algebraic case and we're guaranteed that the tag + -- will match one of the branches. + ((tag,first_alt):rest) = tagged_alts + -- Adjust the tags in the switch to start at zero. -- This is the convention used by primitive ops which return algebraic -- data types. Why? Because for two-constructor types, zero is faster |