Adapt vectoriser to new inlining mechanism
[ghc-hetmet.git] / compiler / vectorise / VectCore.hs
1 module VectCore (
2   Vect, VVar, VExpr, VBind,
3
4   vectorised, lifted,
5   mapVect,
6
7   vVarType,
8
9   vNonRec, vRec,
10
11   vVar, vType, vNote, vLet,
12   vLams, vLamsWithoutLC, vVarApps,
13   vCaseDEFAULT
14 ) where
15
16 #include "HsVersions.h"
17
18 import CoreSyn
19 import Type           ( Type )
20 import Var
21
22 type Vect a = (a,a)
23 type VVar   = Vect Var
24 type VExpr  = Vect CoreExpr
25 type VBind  = Vect CoreBind
26
27 vectorised :: Vect a -> a
28 vectorised = fst
29
30 lifted :: Vect a -> a
31 lifted = snd
32
33 mapVect :: (a -> b) -> Vect a -> Vect b
34 mapVect f (x,y) = (f x, f y)
35
36 zipWithVect :: (a -> b -> c) -> Vect a -> Vect b -> Vect c
37 zipWithVect f (x1,y1) (x2,y2) = (f x1 x2, f y1 y2)
38
39 vVarType :: VVar -> Type
40 vVarType = varType . vectorised
41
42 vVar :: VVar -> VExpr
43 vVar = mapVect Var
44
45 vType :: Type -> VExpr
46 vType ty = (Type ty, Type ty)
47
48 vNote :: Note -> VExpr -> VExpr
49 vNote = mapVect . Note
50
51 vNonRec :: VVar -> VExpr -> VBind
52 vNonRec = zipWithVect NonRec
53
54 vRec :: [VVar] -> [VExpr] -> VBind
55 vRec vs es = (Rec (zip vvs ves), Rec (zip lvs les))
56   where
57     (vvs, lvs) = unzip vs
58     (ves, les) = unzip es
59
60 vLet :: VBind -> VExpr -> VExpr
61 vLet = zipWithVect Let
62
63 vLams :: Var -> [VVar] -> VExpr -> VExpr
64 vLams lc vs (ve, le) = (mkLams vvs ve, mkLams (lc:lvs) le)
65   where
66     (vvs,lvs) = unzip vs
67
68 vLamsWithoutLC :: [VVar] -> VExpr -> VExpr
69 vLamsWithoutLC vvs (ve,le) = (mkLams vs ve, mkLams ls le)
70   where
71     (vs,ls) = unzip vvs
72
73 vVarApps :: Var -> VExpr -> [VVar] -> VExpr
74 vVarApps lc (ve, le) vvs = (ve `mkVarApps` vs, le `mkVarApps` (lc : ls))
75   where
76     (vs,ls) = unzip vvs 
77
78 vCaseDEFAULT :: VExpr -> VVar -> Type -> Type -> VExpr -> VExpr
79 vCaseDEFAULT (vscrut, lscrut) (vbndr, lbndr) vty lty (vbody, lbody)
80   = (Case vscrut vbndr vty (mkDEFAULT vbody),
81      Case lscrut lbndr lty (mkDEFAULT lbody))
82   where
83     mkDEFAULT e = [(DEFAULT, [], e)]
84