+{-# OPTIONS -w #-}
+-- The above warning supression flag is a temporary kludge.
+-- While working on this module you are encouraged to remove it and fix
+-- any warnings in the module. See
+-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
+-- for details
+
module Vectorise( vectorise )
where
where
mapTo vv lv env = env { local_vars = extendVarEnv (local_vars env) v (vv, lv) }
+vectBndrNew :: Var -> FastString -> VM VVar
+vectBndrNew v fs
+ = do
+ vty <- vectType (idType v)
+ vv <- newLocalVVar fs vty
+ updLEnv (upd vv)
+ return vv
+ where
+ upd vv env = env { local_vars = extendVarEnv (local_vars env) v vv }
+
vectBndrIn :: Var -> VM a -> VM (VVar, a)
vectBndrIn v p
= localV
x <- p
return (vv, x)
+vectBndrNewIn :: Var -> FastString -> VM a -> VM (VVar, a)
+vectBndrNewIn v fs p
+ = localV
+ $ do
+ vv <- vectBndrNew v fs
+ x <- p
+ return (vv, x)
+
vectBndrIn' :: Var -> (VVar -> VM a) -> VM (VVar, a)
vectBndrIn' v p
= localV
--
-- to
--
--- V: let v = e in case v of _ { ... }
--- L: let v = e in case v `cast` ... of _ { ... }
+-- V: let v' = e in case v' of _ { ... }
+-- L: let v' = e in case v' `cast` ... of _ { ... }
--
-- When lifting, we have to do it this way because v must have the type
--- [:V(T):] but the scrutinee must be cast to the representation type.
+-- [:V(T):] but the scrutinee must be cast to the representation type. We also
+-- have to handle the case where v is a wild var correctly.
--
-- FIXME: this is too lazy
vty <- vectType ty
lty <- mkPArrayType vty
vexpr <- vectExpr scrut
- (vbndr, (vbndrs, vbody)) <- vectBndrIn bndr
+ (vbndr, (vbndrs, vbody)) <- vect_scrut_bndr
. vectBndrsIn bndrs
$ vectExpr body
shape_bndrs <- mapM (newLocalVar FSLIT("s")) shape_tys
return . vLet (vNonRec vbndr vexpr)
$ vCaseProd vscrut vty lty vect_dc arr_dc shape_bndrs vbndrs vbody
+ where
+ vect_scrut_bndr | isDeadBinder bndr = vectBndrNewIn bndr FSLIT("scrut")
+ | otherwise = vectBndrIn bndr
+