X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fvectorise%2FVectUtils.hs;h=71ba7a38acbeeef76d3ccc9cfa945edb2aff3b56;hb=f83010b119096699d1efef2f7bb45460719c48f9;hp=0df16722bd2df457796752f18b257075ad6e9238;hpb=a2cc9611495710ab00355ebbd8e3d526b1a7d617;p=ghc-hetmet.git diff --git a/compiler/vectorise/VectUtils.hs b/compiler/vectorise/VectUtils.hs index 0df1672..71ba7a3 100644 --- a/compiler/vectorise/VectUtils.hs +++ b/compiler/vectorise/VectUtils.hs @@ -4,6 +4,7 @@ module VectUtils ( mkPADictType, mkPArrayType, paDictArgType, paDictOfType, paMethod, lengthPA, replicatePA, emptyPA, + abstractOverTyVars, applyToTypes, lookupPArrayFamInst, hoistExpr, takeHoisted ) where @@ -23,7 +24,7 @@ import PrelNames import Outputable import FastString -import Control.Monad ( liftM ) +import Control.Monad ( liftM, zipWithM_ ) collectAnnTypeArgs :: AnnExpr b ann -> (AnnExpr b ann, [Type]) collectAnnTypeArgs expr = go expr [] @@ -42,7 +43,7 @@ isAnnTypeArg (_, AnnType t) = True isAnnTypeArg _ = False isClosureTyCon :: TyCon -> Bool -isClosureTyCon tc = tyConUnique tc == closureTyConKey +isClosureTyCon tc = tyConName tc == closureTyConName splitClosureTy :: Type -> (Type, Type) splitClosureTy ty @@ -52,6 +53,17 @@ splitClosureTy ty | otherwise = pprPanic "splitClosureTy" (ppr ty) +isPArrayTyCon :: TyCon -> Bool +isPArrayTyCon tc = tyConName tc == parrayTyConName + +splitPArrayTy :: Type -> Type +splitPArrayTy ty + | Just (tc, [arg_ty]) <- splitTyConApp_maybe ty + , isPArrayTyCon tc + = arg_ty + + | otherwise = pprPanic "splitPArrayTy" (ppr ty) + mkPADictType :: Type -> VM Type mkPADictType ty = do @@ -117,7 +129,9 @@ paMethod method ty return $ mkApps (Var fn) [Type ty, dict] lengthPA :: CoreExpr -> VM CoreExpr -lengthPA x = liftM (`App` x) (paMethod lengthPAVar (exprType x)) +lengthPA x = liftM (`App` x) (paMethod lengthPAVar ty) + where + ty = splitPArrayTy (exprType x) replicatePA :: CoreExpr -> CoreExpr -> VM CoreExpr replicatePA len x = liftM (`mkApps` [len,x]) @@ -126,6 +140,27 @@ replicatePA len x = liftM (`mkApps` [len,x]) emptyPA :: Type -> VM CoreExpr emptyPA = paMethod emptyPAVar +abstractOverTyVars :: [TyVar] -> ((CoreExpr -> CoreExpr) -> VM a) -> VM a +abstractOverTyVars tvs p + = do + mdicts <- mapM mk_dict_var tvs + zipWithM_ (\tv -> maybe (defLocalTyVar tv) (defLocalTyVarWithPA tv . Var)) tvs mdicts + p (mk_lams mdicts) + where + mk_dict_var tv = do + r <- paDictArgType tv + case r of + Just ty -> liftM Just (newLocalVar FSLIT("dPA") ty) + Nothing -> return Nothing + + mk_lams mdicts = mkLams (tvs ++ [dict | Just dict <- mdicts]) + +applyToTypes :: CoreExpr -> [Type] -> VM CoreExpr +applyToTypes expr tys + = do + dicts <- mapM paDictOfType tys + return $ expr `mkTyApps` tys `mkApps` dicts + lookupPArrayFamInst :: Type -> VM (TyCon, [Type]) lookupPArrayFamInst ty = builtin parrayTyCon >>= (`lookupFamInst` [ty])