X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fvectorise%2FVectorise.hs;h=31defa540e02d2136abec4342ad1e9ca4711c9b1;hb=e2390e76b2f1f2beecd9a0d308c4890a56ae8bca;hp=41164464c51844d897175ad4602518893db20731;hpb=f26b161bf682863353f188c2a8d52b7492bebcfa;p=ghc-hetmet.git diff --git a/compiler/vectorise/Vectorise.hs b/compiler/vectorise/Vectorise.hs index 4116446..31defa5 100644 --- a/compiler/vectorise/Vectorise.hs +++ b/compiler/vectorise/Vectorise.hs @@ -30,8 +30,7 @@ import NameEnv import Id import MkId ( unwrapFamInstScrut ) import OccName -import RdrName ( RdrName, mkRdrQual ) -import Module ( mkModuleNameFS ) +import Module ( Module ) import DsMonad hiding (mapAndUnzipM) import DsUtils ( mkCoreTup, mkCoreTupTy ) @@ -46,22 +45,18 @@ import Outputable import FastString import Control.Monad ( liftM, liftM2, zipWithM, mapAndUnzipM ) -mkNDPVar :: String -> RdrName -mkNDPVar s = mkRdrQual nDP_BUILTIN (mkVarOcc s) - -mkNDPVarFS :: FastString -> RdrName -mkNDPVarFS fs = mkRdrQual nDP_BUILTIN (mkVarOccFS fs) - -builtin_PAs :: [(Name, RdrName)] +builtin_PAs :: [(Name, Module, FastString)] builtin_PAs = [ - mk intTyConName FSLIT("dPA_Int") + (closureTyConName, nDP_CLOSURE, FSLIT("dPA_Clo")) + , mk intTyConName FSLIT("dPA_Int") ] ++ tups where - mk name fs = (name, mkNDPVarFS fs) + mk name fs = (name, nDP_INSTANCES, fs) tups = mk_tup 0 : map mk_tup [2..3] - mk_tup n = (getName $ tupleTyCon Boxed n, mkNDPVar $ "dPA_" ++ show n) + mk_tup n = (getName $ tupleTyCon Boxed n, nDP_INSTANCES, + mkFastString $ "dPA_" ++ show n) vectorise :: HscEnv -> UniqSupply -> RuleBase -> ModGuts -> IO (SimplCount, ModGuts) @@ -79,8 +74,8 @@ vectorise hsc_env _ _ guts vectModule :: ModGuts -> VM ModGuts vectModule guts = do - defTyConRdrPAs builtin_PAs - (types', fam_insts) <- vectTypeEnv (mg_types guts) + defTyConBuiltinPAs builtin_PAs + (types', fam_insts, tc_binds) <- vectTypeEnv (mg_types guts) let fam_inst_env' = extendFamInstEnvList (mg_fam_inst_env guts) fam_insts updGEnv (setFamInstEnv fam_inst_env') @@ -89,8 +84,7 @@ vectModule guts -- workers <- mapM vectDataConWorkers pa_insts binds' <- mapM vectTopBind (mg_binds guts) return $ guts { mg_types = types' - , mg_binds = -- Rec (concat workers ++ concat dicts) : - binds' + , mg_binds = Rec tc_binds : binds' , mg_fam_inst_env = fam_inst_env' , mg_fam_insts = mg_fam_insts guts ++ fam_insts } @@ -154,6 +148,14 @@ vectBndrIn v p x <- p return (vv, x) +vectBndrIn' :: Var -> (VVar -> VM a) -> VM (VVar, a) +vectBndrIn' v p + = localV + $ do + vv <- vectBndr v + x <- p vv + return (vv, x) + vectBndrsIn :: [Var] -> VM a -> VM ([VVar], a) vectBndrsIn vs p = localV @@ -227,6 +229,12 @@ vectExpr (_, AnnApp fn arg) arg' <- vectExpr arg mkClosureApp fn' arg' +vectExpr (_, AnnCase scrut bndr ty alts) + | isAlgType scrut_ty + = vectAlgCase scrut bndr ty alts + where + scrut_ty = exprType (deAnnotate scrut) + vectExpr (_, AnnCase expr bndr ty alts) = panic "vectExpr: case" @@ -279,3 +287,44 @@ vectTyAppExpr :: CoreExprWithFVs -> [Type] -> VM VExpr vectTyAppExpr (_, AnnVar v) tys = vectPolyVar v tys vectTyAppExpr e tys = pprPanic "vectTyAppExpr" (ppr $ deAnnotate e) +type CoreAltWithFVs = AnnAlt Id VarSet + +-- We convert +-- +-- case e :: t of v { ... } +-- +-- to +-- +-- V: let v = e in case v of _ { ... } +-- L: let v = e in case v `cast` ... of _ { ... } +-- +-- When lifting, we have to do it this way because v must have the type +-- [:V(T):] but the scrutinee must be cast to the representation type. +-- + +-- FIXME: this is too lazy +vectAlgCase scrut bndr ty [(DEFAULT, [], body)] + = do + vscrut <- vectExpr scrut + vty <- vectType ty + lty <- mkPArrayType vty + (vbndr, vbody) <- vectBndrIn bndr (vectExpr body) + return $ vCaseDEFAULT vscrut vbndr vty lty vbody + +vectAlgCase scrut bndr ty [(DataAlt dc, bndrs, body)] + = do + vty <- vectType ty + lty <- mkPArrayType vty + vexpr <- vectExpr scrut + (vbndr, (vbndrs, vbody)) <- vectBndrIn bndr + . vectBndrsIn bndrs + $ vectExpr body + + (vscrut, arr_tc, arg_tys) <- mkVScrut (vVar vbndr) + vect_dc <- maybeV (lookupDataCon dc) + let [arr_dc] = tyConDataCons arr_tc + let shape_tys = take (dataConRepArity arr_dc - length bndrs) + (dataConRepArgTys arr_dc) + shape_bndrs <- mapM (newLocalVar FSLIT("s")) shape_tys + return . vLet (vNonRec vbndr vexpr) + $ vCaseProd vscrut vty lty vect_dc arr_dc shape_bndrs vbndrs vbody