X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fvectorise%2FVectorise.hs;h=286680fa27c57b3760cc5288ad6250f158c9a46e;hb=c6eadadbefe2ec5709e9d31893f79c4ff78754b4;hp=166eae65a7ade43a3cfa95ea397e5018d25e52ad;hpb=ffe6bf7b9bcbee65080e0c2d37c702dd912761e8;p=ghc-hetmet.git diff --git a/compiler/vectorise/Vectorise.hs b/compiler/vectorise/Vectorise.hs index 166eae6..286680f 100644 --- a/compiler/vectorise/Vectorise.hs +++ b/compiler/vectorise/Vectorise.hs @@ -5,6 +5,7 @@ where import VectMonad import VectUtils +import VectType import DynFlags import HscTypes @@ -18,7 +19,6 @@ import Rules ( RuleBase ) import DataCon import TyCon import Type -import TypeRep import Var import VarEnv import VarSet @@ -33,12 +33,12 @@ import DsUtils ( mkCoreTup, mkCoreTupTy ) 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 -> UniqSupply -> RuleBase -> ModGuts -> IO (SimplCount, ModGuts) @@ -56,8 +56,10 @@ vectorise hsc_env _ _ guts vectModule :: ModGuts -> VM ModGuts vectModule guts = do + types' <- vectTypeEnv (mg_types guts) binds' <- mapM vectTopBind (mg_binds guts) - return $ guts { mg_binds = binds' } + return $ guts { mg_types = types' + , mg_binds = binds' } vectTopBind :: CoreBind -> VM CoreBind vectTopBind b@(NonRec var expr) @@ -174,7 +176,7 @@ abstractOverTyVars :: [TyVar] -> ((CoreExpr -> CoreExpr) -> VM a) -> VM a 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 @@ -183,16 +185,13 @@ abstractOverTyVars tvs p 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 @@ -264,7 +263,7 @@ vectExpr lc e@(_, AnnLam bndr body) 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 @@ -281,8 +280,8 @@ vectExpr lc (fvs, AnnLam 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 @@ -374,7 +373,7 @@ mkClosureFns info tyvars arg body 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) @@ -400,56 +399,27 @@ mkClosureMonoFns info arg 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) -