X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fvectorise%2FVectorise.hs;h=d5b78f14daf5a6af639ddc3badfb26c7e339aee6;hb=3aff16171d3bd0c27826c8947edf8fff7d07fef2;hp=ccb33eecdc61d044347ac8ce791818fa8d95aed8;hpb=40191524ab3597039d7396e23608b2f8e1df1915;p=ghc-hetmet.git diff --git a/compiler/vectorise/Vectorise.hs b/compiler/vectorise/Vectorise.hs index ccb33ee..d5b78f1 100644 --- a/compiler/vectorise/Vectorise.hs +++ b/compiler/vectorise/Vectorise.hs @@ -13,6 +13,8 @@ import CoreLint ( showPass, endPass ) import CoreSyn import CoreUtils import CoreFVs +import SimplMonad ( SimplCount, zeroSimplCount ) +import Rules ( RuleBase ) import DataCon import TyCon import Type @@ -31,6 +33,7 @@ import DsUtils ( mkCoreTup, mkCoreTupTy ) import PrelNames import TysWiredIn +import TysPrim ( intPrimTy ) import BasicTypes ( Boxity(..) ) import Outputable @@ -38,23 +41,26 @@ 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 @@ -78,14 +84,12 @@ vectTopBind b@(Rec bs) 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 @@ -371,7 +375,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,17 +404,21 @@ mkClosureMonoFns info arg body return . Let (NonRec lbndr lenv) $ Case (mkApps (Var lengthPA) [Type vty, (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 @@ -433,7 +441,7 @@ vectTyCon tc Nothing -> pprTrace "ccTyCon:" (ppr tc) $ return tc vectType :: Type -> VM Type -vectType ty | Just ty' <- coreView ty = vectType ty +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)