X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fvectorise%2FVectUtils.hs;h=5cd04715391abce4a43bd77e24e4f338851877f2;hb=a3be6a8eea9fe9c93fcedd393fcb0ac45dc48f5e;hp=76d625cccc5beaff0870ea3d129d2ec3fded1039;hpb=98abc79ce8b23f79c34c93bf3779c040a7b11058;p=ghc-hetmet.git diff --git a/compiler/vectorise/VectUtils.hs b/compiler/vectorise/VectUtils.hs index 76d625c..5cd0471 100644 --- a/compiler/vectorise/VectUtils.hs +++ b/compiler/vectorise/VectUtils.hs @@ -1,14 +1,63 @@ module VectUtils ( - paDictArgType + collectAnnTypeBinders, collectAnnTypeArgs, isAnnTypeArg, + splitClosureTy, + mkPADictType, mkPArrayType, + paDictArgType, paDictOfType ) where #include "HsVersions.h" import VectMonad +import CoreSyn import Type import TypeRep +import TyCon import Var +import PrelNames + +import Outputable + +import Control.Monad ( liftM ) + +collectAnnTypeArgs :: AnnExpr b ann -> (AnnExpr b ann, [Type]) +collectAnnTypeArgs expr = go expr [] + where + go (_, AnnApp f (_, AnnType ty)) tys = go f (ty : tys) + go e tys = (e, tys) + +collectAnnTypeBinders :: AnnExpr Var ann -> ([Var], AnnExpr Var ann) +collectAnnTypeBinders expr = go [] expr + where + go bs (_, AnnLam b e) | isTyVar b = go (b:bs) e + go bs e = (reverse bs, e) + +isAnnTypeArg :: AnnExpr b ann -> Bool +isAnnTypeArg (_, AnnType t) = True +isAnnTypeArg _ = False + +isClosureTyCon :: TyCon -> Bool +isClosureTyCon tc = tyConUnique tc == closureTyConKey + +splitClosureTy :: Type -> (Type, Type) +splitClosureTy ty + | Just (tc, [arg_ty, res_ty]) <- splitTyConApp_maybe ty + , isClosureTyCon tc + = (arg_ty, res_ty) + + | otherwise = pprPanic "splitClosureTy" (ppr ty) + +mkPADictType :: Type -> VM Type +mkPADictType ty + = do + tc <- builtin paDictTyCon + return $ TyConApp tc [ty] + +mkPArrayType :: Type -> VM Type +mkPArrayType ty + = do + tc <- builtin parrayTyCon + return $ TyConApp tc [ty] paDictArgType :: TyVar -> VM (Maybe Type) paDictArgType tv = go (TyVarTy tv) (tyVarKind tv) @@ -26,10 +75,32 @@ paDictArgType tv = go (TyVarTy tv) (tyVarKind tv) go ty k | isLiftedTypeKind k - = do - tc <- builtin paDictTyCon - return . Just $ TyConApp tc [ty] - + = liftM Just (mkPADictType ty) go ty k = return Nothing +paDictOfType :: Type -> VM CoreExpr +paDictOfType ty = paDictOfTyApp ty_fn ty_args + where + (ty_fn, ty_args) = splitAppTys ty + +paDictOfTyApp :: Type -> [Type] -> VM CoreExpr +paDictOfTyApp ty_fn ty_args + | Just ty_fn' <- coreView ty_fn = paDictOfTyApp ty_fn' ty_args +paDictOfTyApp (TyVarTy tv) ty_args + = do + dfun <- maybeV (lookupTyVarPA tv) + paDFunApply dfun ty_args +paDictOfTyApp (TyConApp tc _) ty_args + = do + pa_class <- builtin paClass + (dfun, ty_args') <- lookupInst pa_class [TyConApp tc ty_args] + paDFunApply (Var dfun) ty_args' +paDictOfTyApp ty ty_args = pprPanic "paDictOfTyApp" (ppr ty) + +paDFunApply :: CoreExpr -> [Type] -> VM CoreExpr +paDFunApply dfun tys + = do + dicts <- mapM paDictOfType tys + return $ mkApps (mkTyApps dfun tys) dicts +