Comments and formatting to vectoriser
[ghc-hetmet.git] / compiler / vectorise / VectUtils.hs
index 9faa0ed..a755143 100644 (file)
@@ -11,7 +11,7 @@ module VectUtils (
   pdataReprTyCon, pdataReprDataCon, mkVScrut,
   prDictOfType, prDFunOfTyCon,
   paDictArgType, paDictOfType, paDFunType,
-  paMethod, wrapPR, replicatePD, emptyPD, packPD, packByTagPD,
+  paMethod, wrapPR, replicatePD, emptyPD, packByTagPD,
   combinePD,
   liftPD,
   zipScalars, scalarClosure,
@@ -25,7 +25,7 @@ module VectUtils (
 import VectCore
 import VectMonad
 
-import MkCore ( mkCoreTup, mkCoreTupTy, mkWildCase )
+import MkCore ( mkCoreTup, mkWildCase )
 import CoreSyn
 import CoreUtils
 import CoreUnfold         ( mkInlineRule )
@@ -38,7 +38,7 @@ import Var
 import MkId               ( unwrapFamInstScrut )
 import Id                 ( setIdUnfolding )
 import TysWiredIn
-import BasicTypes         ( Boxity(..) )
+import BasicTypes         ( Boxity(..), Arity )
 import Literal            ( Literal, mkMachInt )
 
 import Outputable
@@ -267,10 +267,6 @@ replicatePD len x = liftM (`mkApps` [len,x])
 emptyPD :: Type -> VM CoreExpr
 emptyPD = paMethod emptyPDVar "emptyPD"
 
-packPD :: Type -> CoreExpr -> CoreExpr -> CoreExpr -> VM CoreExpr
-packPD ty xs len sel = liftM (`mkApps` [xs, len, sel])
-                             (paMethod packPDVar "packPD" ty)
-
 packByTagPD :: Type -> CoreExpr -> CoreExpr -> CoreExpr -> CoreExpr
                  -> VM CoreExpr
 packByTagPD ty xs len tags t
@@ -285,6 +281,7 @@ combinePD ty len sel xs
   where
     n = length xs
 
+-- | Like `replicatePD` but use the lifting context in the vectoriser state.
 liftPD :: CoreExpr -> VM CoreExpr
 liftPD x
   = do
@@ -352,7 +349,7 @@ polyVApply expr tys
       return $ mapVect (\e -> e `mkTyApps` tys `mkApps` dicts) expr
 
 
-data Inline = Inline Int -- arity
+data Inline = Inline Arity
             | DontInline
 
 addInlineArity :: Inline -> Int -> Inline
@@ -362,6 +359,8 @@ addInlineArity DontInline _ = DontInline
 inlineMe :: Inline
 inlineMe = Inline 0
 
+
+-- Hoising --------------------------------------------------------------------
 hoistBinding :: Var -> CoreExpr -> VM ()
 hoistBinding v e = updGEnv $ \env ->
   env { global_bindings = (v,e) : global_bindings env }
@@ -375,7 +374,7 @@ hoistExpr fs expr inl
   where
     mk_inline var = case inl of
                       Inline arity -> var `setIdUnfolding`
-                                      mkInlineRule InlSat expr arity
+                                      mkInlineRule expr (Just arity)
                       DontInline   -> var
 
 hoistVExpr :: VExpr -> Inline -> VM VVar
@@ -416,24 +415,24 @@ boxExpr ty (vexpr, lexpr)
         Nothing     -> return (vexpr, lexpr)
 -}
 
+-- Closures -------------------------------------------------------------------
 mkClosure :: Type -> Type -> Type -> VExpr -> VExpr -> VM VExpr
 mkClosure arg_ty res_ty env_ty (vfn,lfn) (venv,lenv)
-  = do
-      dict <- paDictOfType env_ty
-      mkv  <- builtin closureVar
-      mkl  <- builtin liftedClosureVar
+ = do Just dict <- paDictOfType env_ty
+      mkv       <- builtin closureVar
+      mkl       <- builtin liftedClosureVar
       return (Var mkv `mkTyApps` [arg_ty, res_ty, env_ty] `mkApps` [dict, vfn, lfn, venv],
               Var mkl `mkTyApps` [arg_ty, res_ty, env_ty] `mkApps` [dict, vfn, lfn, lenv])
 
 mkClosureApp :: Type -> Type -> VExpr -> VExpr -> VM VExpr
 mkClosureApp arg_ty res_ty (vclo, lclo) (varg, larg)
-  = do
-      vapply <- builtin applyVar
+ = do vapply <- builtin applyVar
       lapply <- builtin liftedApplyVar
       lc     <- builtin liftingContext
       return (Var vapply `mkTyApps` [arg_ty, res_ty] `mkApps` [vclo, varg],
               Var lapply `mkTyApps` [arg_ty, res_ty] `mkApps` [Var lc, lclo, larg])
 
+
 buildClosures :: [TyVar] -> [VVar] -> [Type] -> Type -> VM VExpr -> VM VExpr
 buildClosures _   _    [] _ mk_body
   = mk_body
@@ -475,6 +474,8 @@ buildClosure tvs vars arg_ty res_ty mk_body
 
       mkClosure arg_ty res_ty env_ty fn env
 
+
+-- Environments ---------------------------------------------------------------
 buildEnv :: [VVar] -> VM (Type, VExpr, VExpr -> VExpr -> VExpr)
 buildEnv [] = do
              ty    <- voidType
@@ -514,5 +515,5 @@ buildEnv vs
   where
     (vvs, lvs) = unzip vs
     tys        = map vVarType vs
-    ty         = mkCoreTupTy tys
+    ty         = mkBoxedTupleTy tys