The Big INLINE Patch: totally reorganise way that INLINE pragmas work
[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, vInlineMe
14 ) where
15
16 #include "HsVersions.h"
17
18 import CoreSyn
19 import Type           ( Type )
20 import Var
21 import Outputable
22
23 type Vect a = (a,a)
24 type VVar   = Vect Var
25 type VExpr  = Vect CoreExpr
26 type VBind  = Vect CoreBind
27
28 vectorised :: Vect a -> a
29 vectorised = fst
30
31 lifted :: Vect a -> a
32 lifted = snd
33
34 mapVect :: (a -> b) -> Vect a -> Vect b
35 mapVect f (x,y) = (f x, f y)
36
37 zipWithVect :: (a -> b -> c) -> Vect a -> Vect b -> Vect c
38 zipWithVect f (x1,y1) (x2,y2) = (f x1 x2, f y1 y2)
39
40 vVarType :: VVar -> Type
41 vVarType = varType . vectorised
42
43 vVar :: VVar -> VExpr
44 vVar = mapVect Var
45
46 vType :: Type -> VExpr
47 vType ty = (Type ty, Type ty)
48
49 vNote :: Note -> VExpr -> VExpr
50 vNote = mapVect . Note
51
52 vNonRec :: VVar -> VExpr -> VBind
53 vNonRec = zipWithVect NonRec
54
55 vRec :: [VVar] -> [VExpr] -> VBind
56 vRec vs es = (Rec (zip vvs ves), Rec (zip lvs les))
57   where
58     (vvs, lvs) = unzip vs
59     (ves, les) = unzip es
60
61 vLet :: VBind -> VExpr -> VExpr
62 vLet = zipWithVect Let
63
64 vLams :: Var -> [VVar] -> VExpr -> VExpr
65 vLams lc vs (ve, le) = (mkLams vvs ve, mkLams (lc:lvs) le)
66   where
67     (vvs,lvs) = unzip vs
68
69 vLamsWithoutLC :: [VVar] -> VExpr -> VExpr
70 vLamsWithoutLC vvs (ve,le) = (mkLams vs ve, mkLams ls le)
71   where
72     (vs,ls) = unzip vvs
73
74 vVarApps :: Var -> VExpr -> [VVar] -> VExpr
75 vVarApps lc (ve, le) vvs = (ve `mkVarApps` vs, le `mkVarApps` (lc : ls))
76   where
77     (vs,ls) = unzip vvs 
78
79 vCaseDEFAULT :: VExpr -> VVar -> Type -> Type -> VExpr -> VExpr
80 vCaseDEFAULT (vscrut, lscrut) (vbndr, lbndr) vty lty (vbody, lbody)
81   = (Case vscrut vbndr vty (mkDEFAULT vbody),
82      Case lscrut lbndr lty (mkDEFAULT lbody))
83   where
84     mkDEFAULT e = [(DEFAULT, [], e)]
85
86 vInlineMe :: VExpr -> VExpr
87 vInlineMe (vexpr, lexpr) = (mkInlineMe vexpr, mkInlineMe lexpr)
88
89 mkInlineMe :: CoreExpr -> CoreExpr
90 mkInlineMe = pprTrace "VectCore.mkInlineMe" (text "Roman: need to replace mkInlineMe with an InlineRule somehow")