From a63ba966cf8f0f12e303102d3241445579f77043 Mon Sep 17 00:00:00 2001 From: Roman Leshchinskiy Date: Tue, 31 Jul 2007 06:27:11 +0000 Subject: [PATCH] Move vectorisation-related smart constructors into a separate module --- compiler/package.conf.in | 1 + compiler/vectorise/VectCore.hs | 41 +++++++++++++++++++++++++++++++++++++++ compiler/vectorise/VectUtils.hs | 29 ++------------------------- 3 files changed, 44 insertions(+), 27 deletions(-) create mode 100644 compiler/vectorise/VectCore.hs diff --git a/compiler/package.conf.in b/compiler/package.conf.in index 6b33e08..e654822 100644 --- a/compiler/package.conf.in +++ b/compiler/package.conf.in @@ -259,6 +259,7 @@ exposed-modules: Var VarEnv VarSet + VectCore VectMonad VectType VectUtils diff --git a/compiler/vectorise/VectCore.hs b/compiler/vectorise/VectCore.hs new file mode 100644 index 0000000..63178bd --- /dev/null +++ b/compiler/vectorise/VectCore.hs @@ -0,0 +1,41 @@ +module VectCore ( + Vect, VVar, VExpr, + + vectorised, lifted, + mapVect, + + vVar, mkVLams, mkVVarApps +) where + +#include "HsVersions.h" + +import CoreSyn +import Var + +type Vect a = (a,a) +type VVar = Vect Var +type VExpr = Vect CoreExpr + +vectorised :: Vect a -> a +vectorised = fst + +lifted :: Vect a -> a +lifted = snd + +mapVect :: (a -> b) -> Vect a -> Vect b +mapVect f (x,y) = (f x, f y) + +vVar :: VVar -> VExpr +vVar = mapVect Var + +mkVLams :: [VVar] -> VExpr -> VExpr +mkVLams vvs (ve,le) = (mkLams vs ve, mkLams ls le) + where + (vs,ls) = unzip vvs + +mkVVarApps :: Var -> VExpr -> [VVar] -> VExpr +mkVVarApps lc (ve, le) vvs = (ve `mkVarApps` vs, le `mkVarApps` (lc : ls)) + where + (vs,ls) = unzip vvs + + diff --git a/compiler/vectorise/VectUtils.hs b/compiler/vectorise/VectUtils.hs index cbca02f..199af1a 100644 --- a/compiler/vectorise/VectUtils.hs +++ b/compiler/vectorise/VectUtils.hs @@ -11,6 +11,7 @@ module VectUtils ( #include "HsVersions.h" +import VectCore import VectMonad import DsUtils @@ -146,19 +147,6 @@ replicatePA len x = liftM (`mkApps` [len,x]) emptyPA :: Type -> VM CoreExpr emptyPA = paMethod emptyPAVar -type Vect a = (a,a) -type VVar = Vect Var -type VExpr = Vect CoreExpr - -vectorised :: Vect a -> a -vectorised = fst - -lifted :: Vect a -> a -lifted = snd - -mapVect :: (a -> b) -> Vect a -> Vect b -mapVect f (x,y) = (f x, f y) - newLocalVVar :: FastString -> Type -> VM VVar newLocalVVar fs vty = do @@ -167,19 +155,6 @@ newLocalVVar fs vty lv <- newLocalVar fs lty return (vv,lv) -vVar :: VVar -> VExpr -vVar = mapVect Var - -mkVLams :: [VVar] -> VExpr -> VExpr -mkVLams vvs (ve,le) = (mkLams vs ve, mkLams ls le) - where - (vs,ls) = unzip vvs - -mkVVarApps :: Var -> VExpr -> [VVar] -> VExpr -mkVVarApps lc (ve, le) vvs = (ve `mkVarApps` vs, le `mkVarApps` (lc : ls)) - where - (vs,ls) = unzip vvs - polyAbstract :: [TyVar] -> ((CoreExpr -> CoreExpr) -> VM a) -> VM a polyAbstract tvs p = localV @@ -256,7 +231,7 @@ buildClosure tvs lv vars arg body env_bndr <- newLocalVVar FSLIT("env") env_ty fn <- hoistPolyVExpr FSLIT("fn") tvs - . mkVLams [env_bndr, arg] + . mkVLams [env_bndr, arg] . bind (vVar env_bndr) $ mkVVarApps lv body (vars ++ [arg]) -- 1.7.10.4