Use new closure generation code in vectorisation
[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   vLams,
11   mkVLams, mkVVarApps
12 ) where
13
14 #include "HsVersions.h"
15
16 import CoreSyn
17 import Type           ( Type )
18 import Var
19
20 type Vect a = (a,a)
21 type VVar   = Vect Var
22 type VExpr  = Vect CoreExpr
23 type VBind  = Vect CoreBind
24
25 vectorised :: Vect a -> a
26 vectorised = fst
27
28 lifted :: Vect a -> a
29 lifted = snd
30
31 mapVect :: (a -> b) -> Vect a -> Vect b
32 mapVect f (x,y) = (f x, f y)
33
34 zipWithVect :: (a -> b -> c) -> Vect a -> Vect b -> Vect c
35 zipWithVect f (x1,y1) (x2,y2) = (f x1 x2, f y1 y2)
36
37 vVar :: VVar -> VExpr
38 vVar = mapVect Var
39
40 vType :: Type -> VExpr
41 vType ty = (Type ty, Type ty)
42
43 vNote :: Note -> VExpr -> VExpr
44 vNote = mapVect . Note
45
46 vNonRec :: VVar -> VExpr -> VBind
47 vNonRec = zipWithVect NonRec
48
49 vRec :: [VVar] -> [VExpr] -> VBind
50 vRec vs es = (Rec (zip vvs ves), Rec (zip lvs les))
51   where
52     (vvs, lvs) = unzip vs
53     (ves, les) = unzip es
54
55 vLet :: VBind -> VExpr -> VExpr
56 vLet = zipWithVect Let
57
58 vLams :: Var -> [VVar] -> VExpr -> VExpr
59 vLams lc vs (ve, le) = (mkLams vvs ve, mkLams (lc:lvs) le)
60   where
61     (vvs,lvs) = unzip vs
62
63 mkVLams :: [VVar] -> VExpr -> VExpr
64 mkVLams vvs (ve,le) = (mkLams vs ve, mkLams ls le)
65   where
66     (vs,ls) = unzip vvs
67
68 mkVVarApps :: Var -> VExpr -> [VVar] -> VExpr
69 mkVVarApps lc (ve, le) vvs = (ve `mkVarApps` vs, le `mkVarApps` (lc : ls))
70   where
71     (vs,ls) = unzip vvs 
72
73