X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fvectorise%2FVectUtils.hs;h=199ef68e093c2d3ea349460ab99a1456285d3e85;hb=48fb2b521898998a17873ad6cf30610aa5ab6db3;hp=acf19d4c137113f4c2b0a616fcd8f78b9a7288d7;hpb=398fb62067696bf39ab8f64405b39292b06511c3;p=ghc-hetmet.git diff --git a/compiler/vectorise/VectUtils.hs b/compiler/vectorise/VectUtils.hs index acf19d4..199ef68 100644 --- a/compiler/vectorise/VectUtils.hs +++ b/compiler/vectorise/VectUtils.hs @@ -1,5 +1,10 @@ module VectUtils ( - paDictArgType, paDictOfType + collectAnnTypeBinders, collectAnnTypeArgs, isAnnTypeArg, + splitClosureTy, + mkPADictType, mkPArrayType, + paDictArgType, paDictOfType, + lookupPArrayFamInst, + hoistExpr, takeHoisted ) where #include "HsVersions.h" @@ -7,11 +12,56 @@ module VectUtils ( import VectMonad import CoreSyn +import CoreUtils import Type import TypeRep +import TyCon import Var +import PrelNames import Outputable +import FastString + +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) @@ -29,9 +79,7 @@ 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 @@ -60,3 +108,21 @@ paDFunApply dfun tys dicts <- mapM paDictOfType tys return $ mkApps (mkTyApps dfun tys) dicts +lookupPArrayFamInst :: Type -> VM (TyCon, [Type]) +lookupPArrayFamInst ty = builtin parrayTyCon >>= (`lookupFamInst` [ty]) + +hoistExpr :: FastString -> CoreExpr -> VM Var +hoistExpr fs expr + = do + var <- newLocalVar fs (exprType expr) + updGEnv $ \env -> + env { global_bindings = (var, expr) : global_bindings env } + return var + +takeHoisted :: VM [(Var, CoreExpr)] +takeHoisted + = do + env <- readGEnv id + setGEnv $ env { global_bindings = [] } + return $ global_bindings env +