X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fvectorise%2FVectorise.hs;h=aad5144b6bc824db51966add25887d70cdb406ff;hb=02c988e586dedff6d252ef59ef487dd4a8f567aa;hp=f60ed6f7ac5c74f4a1e47158f04f2a2c0209c03b;hpb=791ad7585b4509480592643d0f448b5244122812;p=ghc-hetmet.git diff --git a/compiler/vectorise/Vectorise.hs b/compiler/vectorise/Vectorise.hs index f60ed6f..aad5144 100644 --- a/compiler/vectorise/Vectorise.hs +++ b/compiler/vectorise/Vectorise.hs @@ -5,8 +5,10 @@ where import VectMonad import VectUtils +import VectVar import VectType -import VectCore +import Vectorise.Vect +import Vectorise.Env import HscTypes hiding ( MonadThings(..) ) @@ -28,7 +30,7 @@ import Id import OccName import BasicTypes ( isLoopBreaker ) -import Literal ( Literal, mkMachInt ) +import Literal import TysWiredIn import TysPrim ( intPrimTy ) @@ -221,109 +223,8 @@ tryConvert var vect_var rhs -- ---------------------------------------------------------------------------- --- Bindings - --- | Vectorise a binder variable, along with its attached type. -vectBndr :: Var -> VM VVar -vectBndr v - = do - (vty, lty) <- vectAndLiftType (idType v) - let vv = v `Id.setIdType` vty - lv = v `Id.setIdType` lty - updLEnv (mapTo vv lv) - return (vv, lv) - where - mapTo vv lv env = env { local_vars = extendVarEnv (local_vars env) v (vv, lv) } - - --- | Vectorise a binder variable, along with its attached type, --- but give the result a new name. -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 } - - --- | Vectorise a binder then run a computation with that binder in scope. -vectBndrIn :: Var -> VM a -> VM (VVar, a) -vectBndrIn v p - = localV - $ do - vv <- vectBndr v - x <- p - return (vv, x) - - --- | Vectorise a binder, give it a new name, then run a computation with that binder in scope. -vectBndrNewIn :: Var -> FastString -> VM a -> VM (VVar, a) -vectBndrNewIn v fs p - = localV - $ do - vv <- vectBndrNew v fs - x <- p - return (vv, x) - --- | Vectorise some binders, then run a computation with them in scope. -vectBndrsIn :: [Var] -> VM a -> VM ([VVar], a) -vectBndrsIn vs p - = localV - $ do - vvs <- mapM vectBndr vs - x <- p - return (vvs, x) - - --- ---------------------------------------------------------------------------- -- Expressions --- | Vectorise a variable, producing the vectorised and lifted versions. -vectVar :: Var -> VM VExpr -vectVar v - = do - -- lookup the variable from the environment. - r <- lookupVar v - - case r of - -- If it's been locally bound then we'll already have both versions available. - Local (vv,lv) - -> return (Var vv, Var lv) - - -- To create the lifted version of a global variable we replicate it. - Global vv - -> do let vexpr = Var vv - lexpr <- liftPD vexpr - return (vexpr, lexpr) - - --- | Like `vectVar` but also add type applications to the variables. -vectPolyVar :: Var -> [Type] -> VM VExpr -vectPolyVar v tys - = do - vtys <- mapM vectType tys - r <- lookupVar v - case r of - Local (vv, lv) - -> liftM2 (,) (polyApply (Var vv) vtys) - (polyApply (Var lv) vtys) - - Global poly - -> do vexpr <- polyApply (Var poly) vtys - lexpr <- liftPD vexpr - return (vexpr, lexpr) - - --- | Lifted literals are created by replicating them. -vectLiteral :: Literal -> VM VExpr -vectLiteral lit - = do - lexpr <- liftPD (Lit lit) - return (Lit lit, lexpr) - -- | Vectorise a polymorphic expression vectPolyExpr