import VectMonad
import VectUtils
+import VectType
import DynFlags
import HscTypes
import CoreSyn
import CoreUtils
import CoreFVs
+import SimplMonad ( SimplCount, zeroSimplCount )
+import Rules ( RuleBase )
import DataCon
import TyCon
import Type
-import TypeRep
import Var
import VarEnv
import VarSet
import PrelNames
import TysWiredIn
+import TysPrim ( intPrimTy )
import BasicTypes ( Boxity(..) )
import Outputable
import FastString
import Control.Monad ( liftM, liftM2, mapAndUnzipM, zipWithM_ )
-import Data.Maybe ( maybeToList )
-vectorise :: HscEnv -> ModGuts -> IO ModGuts
-vectorise hsc_env guts
- | not (Opt_Vectorise `dopt` dflags) = return guts
- | otherwise
+vectorise :: HscEnv -> UniqSupply -> RuleBase -> ModGuts
+ -> IO (SimplCount, ModGuts)
+vectorise hsc_env _ _ guts
= do
showPass dflags "Vectorisation"
eps <- hscEPS hsc_env
let info = hptVectInfo hsc_env `plusVectInfo` eps_vect_info eps
Just (info', guts') <- initV hsc_env guts info (vectModule guts)
endPass dflags "Vectorisation" Opt_D_dump_vect (mg_binds guts')
- return $ guts' { mg_vect_info = info' }
+ return (zeroSimplCount dflags, guts' { mg_vect_info = info' })
where
dflags = hsc_dflags hsc_env
vectModule :: ModGuts -> VM ModGuts
-vectModule guts = return guts
+vectModule guts
+ = do
+ binds' <- mapM vectTopBind (mg_binds guts)
+ return $ guts { mg_binds = binds' }
+vectTopBind :: CoreBind -> VM CoreBind
vectTopBind b@(NonRec var expr)
= do
var' <- vectTopBinder var
vectTopBinder :: Var -> VM Var
vectTopBinder var
= do
- vty <- liftM (mkForAllTys tyvars) $ vectType mono_ty
+ vty <- vectType (idType var)
name <- cloneName mkVectOcc (getName var)
let var' | isExportedId var = Id.mkExportedLocalId name vty
| otherwise = Id.mkLocalId name vty
defGlobalVar var var'
return var'
- where
- (tyvars, mono_ty) = splitForAllTys (idType var)
vectTopRhs :: CoreExpr -> VM CoreExpr
vectTopRhs = liftM fst . closedV . vectPolyExpr (panic "Empty lifting context") . freeVars
abstractOverTyVars tvs p
= do
mdicts <- mapM mk_dict_var tvs
- zipWithM_ (\tv -> maybe (deleteTyVarPA tv) (extendTyVarPA tv . Var)) tvs mdicts
+ zipWithM_ (\tv -> maybe (defLocalTyVar tv) (defLocalTyVarWithPA tv . Var)) tvs mdicts
p (mk_lams mdicts)
where
mk_dict_var tv = do
Just ty -> liftM Just (newLocalVar FSLIT("dPA") ty)
Nothing -> return Nothing
- mk_lams mdicts = mkLams [arg | (tv, mdict) <- zip tvs mdicts
- , arg <- tv : maybeToList mdict]
+ mk_lams mdicts = mkLams (tvs ++ [dict | Just dict <- mdicts])
applyToTypes :: CoreExpr -> [Type] -> VM CoreExpr
applyToTypes expr tys
= do
dicts <- mapM paDictOfType tys
- return $ mkApps expr [arg | (ty, dict) <- zip tys dicts
- , arg <- [Type ty, dict]]
-
+ return $ expr `mkTyApps` tys `mkApps` dicts
vectPolyExpr :: CoreExpr -> CoreExprWithFVs -> VM (CoreExpr, CoreExpr)
vectPolyExpr lc expr
vectExpr lc (fvs, AnnLam bndr body)
= do
- let tyvars = filter isTyVar (varSetElems fvs)
+ tyvars <- localTyVars
info <- mkCEnvInfo fvs bndr body
(poly_vfn, poly_lfn) <- mkClosureFns info tyvars bndr body
res_ty <- vectType (exprType $ deAnnotate body)
-- FIXME: move the functions to the top level
- mono_vfn <- applyToTypes (Var vfn_var) (map TyVarTy tyvars)
- mono_lfn <- applyToTypes (Var lfn_var) (map TyVarTy tyvars)
+ mono_vfn <- applyToTypes (Var vfn_var) (mkTyVarTys tyvars)
+ mono_lfn <- applyToTypes (Var lfn_var) (mkTyVarTys tyvars)
mk_clo <- builtin mkClosureVar
mk_cloP <- builtin mkClosurePVar
mkClosureMonoFns :: CEnvInfo -> Var -> CoreExprWithFVs -> VM (CoreExpr, CoreExpr)
mkClosureMonoFns info arg body
= do
- lc_bndr <- newLocalVar FSLIT("lc") intTy
+ lc_bndr <- newLocalVar FSLIT("lc") intPrimTy
(varg : vbndrs, larg : lbndrs, (vbody, lbody))
<- vectBndrsIn (arg : cenv_vars info)
(vectExpr (Var lc_bndr) body)
bind_lenv lenv lbody lc_bndr [lbndr]
= do
lengthPA <- builtin lengthPAVar
+ pa_dict <- paDictOfType vty
return . Let (NonRec lbndr lenv)
- $ Case (mkApps (Var lengthPA) [Type vty, (Var lbndr)])
+ $ Case (mkApps (Var lengthPA) [Type vty, pa_dict, (Var lbndr)])
lc_bndr
- intTy
+ (exprType lbody)
[(DEFAULT, [], lbody)]
bind_lenv lenv lbody lc_bndr lbndrs
- = return
- $ Case (unwrapFamInstScrut (cenv_repr_tycon info)
- (cenv_repr_tyargs info)
- lenv)
- (mkWildId lty)
+ = let scrut = unwrapFamInstScrut (cenv_repr_tycon info)
+ (cenv_repr_tyargs info)
+ lenv
+ lbndrs' | null lbndrs = [mkWildId unitTy]
+ | otherwise = lbndrs
+ in
+ return
+ $ Case scrut
+ (mkWildId (exprType scrut))
(exprType lbody)
- [(DataAlt (cenv_repr_datacon info), lc_bndr : lbndrs, lbody)]
+ [(DataAlt (cenv_repr_datacon info), lc_bndr : lbndrs', lbody)]
vectTyAppExpr :: CoreExpr -> CoreExprWithFVs -> [Type] -> VM (CoreExpr, CoreExpr)
vectTyAppExpr lc (_, AnnVar v) tys = vectPolyVar lc v tys
vectTyAppExpr lc e tys = pprPanic "vectTyAppExpr" (ppr $ deAnnotate e)
--- ----------------------------------------------------------------------------
--- Types
-
-vectTyCon :: TyCon -> VM TyCon
-vectTyCon tc
- | isFunTyCon tc = builtin closureTyCon
- | isBoxedTupleTyCon tc = return tc
- | isUnLiftedTyCon tc = return tc
- | otherwise = do
- r <- lookupTyCon tc
- case r of
- Just tc' -> return tc'
-
- -- FIXME: just for now
- Nothing -> pprTrace "ccTyCon:" (ppr tc) $ return tc
-
-vectType :: Type -> VM Type
-vectType ty | Just ty' <- coreView ty = vectType ty
-vectType (TyVarTy tv) = return $ TyVarTy tv
-vectType (AppTy ty1 ty2) = liftM2 AppTy (vectType ty1) (vectType ty2)
-vectType (TyConApp tc tys) = liftM2 TyConApp (vectTyCon tc) (mapM vectType tys)
-vectType (FunTy ty1 ty2) = liftM2 TyConApp (builtin closureTyCon)
- (mapM vectType [ty1,ty2])
-vectType (ForAllTy tv ty)
- = do
- r <- paDictArgType tv
- ty' <- vectType ty
- return $ ForAllTy tv (wrap r ty')
- where
- wrap Nothing = id
- wrap (Just pa_ty) = FunTy pa_ty
-
-vectType ty = pprPanic "vectType:" (ppr ty)
-