Move vectorisation-related smart constructors into a separate module
authorRoman Leshchinskiy <rl@cse.unsw.edu.au>
Tue, 31 Jul 2007 06:27:11 +0000 (06:27 +0000)
committerRoman Leshchinskiy <rl@cse.unsw.edu.au>
Tue, 31 Jul 2007 06:27:11 +0000 (06:27 +0000)
compiler/package.conf.in
compiler/vectorise/VectCore.hs [new file with mode: 0644]
compiler/vectorise/VectUtils.hs

index 6b33e08..e654822 100644 (file)
@@ -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 (file)
index 0000000..63178bd
--- /dev/null
@@ -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 
+
+
index cbca02f..199af1a 100644 (file)
@@ -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])