X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fvectorise%2FVectUtils.hs;h=d1c1dab9748d437083db89ac8382ab5d72794eeb;hb=ea8027bad72931bce05f36cae99497e7f255eef7;hp=cb1aa3e10d4f24a5959583c35dbc4eacd3c72db6;hpb=d0e5514448562cb59852baacb8f433cd88c3370d;p=ghc-hetmet.git diff --git a/compiler/vectorise/VectUtils.hs b/compiler/vectorise/VectUtils.hs index cb1aa3e..d1c1dab 100644 --- a/compiler/vectorise/VectUtils.hs +++ b/compiler/vectorise/VectUtils.hs @@ -6,6 +6,7 @@ module VectUtils ( mkPRepr, mkToPRepr, mkFromPRepr, mkPADictType, mkPArrayType, mkPReprType, parrayReprTyCon, parrayReprDataCon, mkVScrut, + prDictOfType, prCoerce, paDictArgType, paDictOfType, paDFunType, paMethod, lengthPA, replicatePA, emptyPA, liftPA, polyAbstract, polyApply, polyVApply, @@ -22,6 +23,7 @@ import VectMonad import DsUtils import CoreSyn import CoreUtils +import Coercion import Type import TypeRep import TyCon @@ -254,6 +256,47 @@ mkVScrut (ve, le) (tc, arg_tys) <- parrayReprTyCon (exprType ve) return ((ve, unwrapFamInstScrut tc arg_tys le), tc, arg_tys) +prDictOfType :: Type -> VM CoreExpr +prDictOfType orig_ty + | Just (tycon, ty_args) <- splitTyConApp_maybe orig_ty + = do + dfun <- traceMaybeV "prDictOfType" (ppr tycon) (lookupTyConPR tycon) + prDFunApply (Var dfun) ty_args + +prDFunApply :: CoreExpr -> [Type] -> VM CoreExpr +prDFunApply dfun tys + = do + args <- mapM mkDFunArg arg_tys + return $ mkApps mono_dfun args + where + mono_dfun = mkTyApps dfun tys + (arg_tys, _) = splitFunTys (exprType mono_dfun) + +mkDFunArg :: Type -> VM CoreExpr +mkDFunArg ty + | Just (tycon, [arg]) <- splitTyConApp_maybe ty + + = let name = tyConName tycon + + get_dict | name == paTyConName = paDictOfType + | name == prTyConName = prDictOfType + | otherwise = pprPanic "mkDFunArg" (ppr ty) + + in get_dict arg + +mkDFunArg ty = pprPanic "mkDFunArg" (ppr ty) + +prCoerce :: TyCon -> [Type] -> CoreExpr -> VM CoreExpr +prCoerce repr_tc args expr + | Just arg_co <- tyConFamilyCoercion_maybe repr_tc + = do + pr_tc <- builtin prTyCon + + let co = mkAppCoercion (mkTyConApp pr_tc []) + (mkSymCoercion (mkTyConApp arg_co args)) + + return $ mkCoerce co expr + paDictArgType :: TyVar -> VM (Maybe Type) paDictArgType tv = go (TyVarTy tv) (tyVarKind tv) where