X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fvectorise%2FVectorise.hs;h=286680fa27c57b3760cc5288ad6250f158c9a46e;hb=8bac478832e0cf9fa7ad1cfc81c08b0b9f13938e;hp=a42298fb16ed4bb34cf792099d01aaec344a0b43;hpb=9d899efe741906ad957cf3ad84122f62c73a9de6;p=ghc-hetmet.git diff --git a/compiler/vectorise/Vectorise.hs b/compiler/vectorise/Vectorise.hs index a42298f..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 @@ -39,7 +39,6 @@ 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) @@ -57,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) @@ -175,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 @@ -184,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 @@ -265,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 @@ -282,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 @@ -401,10 +399,11 @@ 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 - intPrimTy + (exprType lbody) [(DEFAULT, [], lbody)] bind_lenv lenv lbody lc_bndr lbndrs @@ -424,37 +423,3 @@ 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) -