More vectorisation-related smart constructors
[ghc-hetmet.git] / compiler / vectorise / VectCore.hs
1 module VectCore (
2   Vect, VVar, VExpr, VBind,
3
4   vectorised, lifted,
5   mapVect,
6
7   vNonRec, vRec,
8
9   vVar, vType, vNote, vLet,
10   mkVLams, mkVVarApps
11 ) where
12
13 #include "HsVersions.h"
14
15 import CoreSyn
16 import Type           ( Type )
17 import Var
18
19 type Vect a = (a,a)
20 type VVar   = Vect Var
21 type VExpr  = Vect CoreExpr
22 type VBind  = Vect CoreBind
23
24 vectorised :: Vect a -> a
25 vectorised = fst
26
27 lifted :: Vect a -> a
28 lifted = snd
29
30 mapVect :: (a -> b) -> Vect a -> Vect b
31 mapVect f (x,y) = (f x, f y)
32
33 zipWithVect :: (a -> b -> c) -> Vect a -> Vect b -> Vect c
34 zipWithVect f (x1,y1) (x2,y2) = (f x1 x2, f y1 y2)
35
36 vVar :: VVar -> VExpr
37 vVar = mapVect Var
38
39 vType :: Type -> VExpr
40 vType ty = (Type ty, Type ty)
41
42 vNote :: Note -> VExpr -> VExpr
43 vNote = mapVect . Note
44
45 vNonRec :: VVar -> VExpr -> VBind
46 vNonRec = zipWithVect NonRec
47
48 vRec :: [VVar] -> [VExpr] -> VBind
49 vRec vs es = (Rec (zip vvs ves), Rec (zip lvs les))
50   where
51     (vvs, lvs) = unzip vs
52     (ves, les) = unzip es
53
54 vLet :: VBind -> VExpr -> VExpr
55 vLet = zipWithVect Let
56
57 mkVLams :: [VVar] -> VExpr -> VExpr
58 mkVLams vvs (ve,le) = (mkLams vs ve, mkLams ls le)
59   where
60     (vs,ls) = unzip vvs
61
62 mkVVarApps :: Var -> VExpr -> [VVar] -> VExpr
63 mkVVarApps lc (ve, le) vvs = (ve `mkVarApps` vs, le `mkVarApps` (lc : ls))
64   where
65     (vs,ls) = unzip vvs 
66
67