X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fvectorise%2FVectUtils.hs;h=e5084241d61784106054345b76a82b76d47ebcc4;hb=cfccfa67393fcf8cb43aaa465d421b67c7117580;hp=30ce9ace50bed31d04e6ca4af4a3ca02215c79ef;hpb=3736e30f683990ee94055b60905cce208a467e8b;p=ghc-hetmet.git diff --git a/compiler/vectorise/VectUtils.hs b/compiler/vectorise/VectUtils.hs index 30ce9ac..e508424 100644 --- a/compiler/vectorise/VectUtils.hs +++ b/compiler/vectorise/VectUtils.hs @@ -5,13 +5,13 @@ module VectUtils ( newLocalVVar, - mkBuiltinCo, voidType, + mkBuiltinCo, voidType, mkWrapType, mkPADictType, mkPArrayType, mkPDataType, mkPReprType, mkPArray, pdataReprTyCon, pdataReprDataCon, mkVScrut, - prDFunOfTyCon, + prDictOfType, prDFunOfTyCon, paDictArgType, paDictOfType, paDFunType, - paMethod, mkPR, replicatePD, emptyPD, packPD, + paMethod, wrapPR, replicatePD, emptyPD, packPD, packByTagPD, combinePD, liftPD, zipScalars, scalarClosure, @@ -98,7 +98,10 @@ mkBuiltinTyConApps get_tc tys ty mk tc ty1 ty2 = mkTyConApp tc [ty1,ty2] voidType :: VM Type -voidType = mkBuiltinTyConApp voidTyCon [] +voidType = mkBuiltinTyConApp VectMonad.voidTyCon [] + +mkWrapType :: Type -> VM Type +mkWrapType ty = mkBuiltinTyConApp wrapTyCon [ty] mkClosureTypes :: [Type] -> Type -> VM Type mkClosureTypes = mkBuiltinTyConApps closureTyCon @@ -215,8 +218,6 @@ paDFunApply dfun tys dicts <- mapM paDictOfType tys return $ mkApps (mkTyApps dfun tys) dicts -type PAMethod = (Builtins -> Var, String) - paMethod :: (Builtins -> Var) -> String -> Type -> VM CoreExpr paMethod _ name ty | Just tycon <- splitPrimTyCon ty @@ -230,12 +231,32 @@ paMethod method _ ty dict <- paDictOfType ty return $ mkApps (Var fn) [Type ty, dict] -mkPR :: Type -> VM CoreExpr -mkPR ty +prDictOfType :: Type -> VM CoreExpr +prDictOfType ty = prDictOfTyApp ty_fn ty_args + where + (ty_fn, ty_args) = splitAppTys ty + +prDictOfTyApp :: Type -> [Type] -> VM CoreExpr +prDictOfTyApp ty_fn ty_args + | Just ty_fn' <- coreView ty_fn = prDictOfTyApp ty_fn' ty_args +prDictOfTyApp (TyConApp tc _) ty_args = do - fn <- builtin mkPRVar - dict <- paDictOfType ty - return $ mkApps (Var fn) [Type ty, dict] + dfun <- liftM Var $ maybeV (lookupTyConPR tc) + prDFunApply dfun ty_args +prDictOfTyApp _ _ = noV + +prDFunApply :: CoreExpr -> [Type] -> VM CoreExpr +prDFunApply dfun tys + = do + dicts <- mapM prDictOfType tys + return $ mkApps (mkTyApps dfun tys) dicts + +wrapPR :: Type -> VM CoreExpr +wrapPR ty + = do + pa_dict <- paDictOfType ty + pr_dfun <- prDFunOfTyCon =<< builtin wrapTyCon + return $ mkApps pr_dfun [Type ty, pa_dict] replicatePD :: CoreExpr -> CoreExpr -> VM CoreExpr replicatePD len x = liftM (`mkApps` [len,x]) @@ -248,6 +269,12 @@ packPD :: Type -> CoreExpr -> CoreExpr -> CoreExpr -> VM CoreExpr packPD ty xs len sel = liftM (`mkApps` [xs, len, sel]) (paMethod packPDVar "packPD" ty) +packByTagPD :: Type -> CoreExpr -> CoreExpr -> CoreExpr -> CoreExpr + -> VM CoreExpr +packByTagPD ty xs len tags t + = liftM (`mkApps` [xs, len, tags, t]) + (paMethod packByTagPDVar "packByTagPD" ty) + combinePD :: Type -> CoreExpr -> CoreExpr -> [CoreExpr] -> VM CoreExpr combinePD ty len sel xs @@ -445,11 +472,11 @@ buildEnv vs `mkTyApps` lenv_tyargs `mkApps` map Var lvs - vbind env body = mkWildCase venv ty (exprType body) - [(DataAlt venv_con, vvs, body)] + vbind env body = mkWildCase env ty (exprType body) + [(DataAlt venv_con, vvs, body)] lbind env body = - let scrut = unwrapFamInstScrut lenv_tc lenv_tyargs lenv + let scrut = unwrapFamInstScrut lenv_tc lenv_tyargs env in mkWildCase scrut (exprType scrut) (exprType body) [(DataAlt lenv_con, lvs, body)]