X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fvectorise%2FVectUtils.hs;h=718db856d2200d700cbf7d40af76aef8df5018df;hb=e1364f66b4e743237e942e0826ed096f5e06de76;hp=3abbe44b49b656ae5fbc6b0766837fcd0f277bcf;hpb=76cec9c6231e5e73c5dd17e5c7111a79ffde0b03;p=ghc-hetmet.git diff --git a/compiler/vectorise/VectUtils.hs b/compiler/vectorise/VectUtils.hs index 3abbe44..718db85 100644 --- a/compiler/vectorise/VectUtils.hs +++ b/compiler/vectorise/VectUtils.hs @@ -1,5 +1,6 @@ module VectUtils ( collectAnnTypeBinders, collectAnnTypeArgs, isAnnTypeArg, + collectAnnValBinders, splitClosureTy, mkPADictType, mkPArrayType, paDictArgType, paDictOfType, @@ -7,7 +8,8 @@ module VectUtils ( polyAbstract, polyApply, polyVApply, lookupPArrayFamInst, hoistExpr, hoistPolyVExpr, takeHoisted, - buildClosure + buildClosure, buildClosures, + mkClosureApp ) where #include "HsVersions.h" @@ -46,6 +48,12 @@ collectAnnTypeBinders expr = go [] expr go bs (_, AnnLam b e) | isTyVar b = go (b:bs) e go bs e = (reverse bs, e) +collectAnnValBinders :: AnnExpr Var ann -> ([Var], AnnExpr Var ann) +collectAnnValBinders expr = go [] expr + where + go bs (_, AnnLam b e) | isId b = go (b:bs) e + go bs e = (reverse bs, e) + isAnnTypeArg :: AnnExpr b ann -> Bool isAnnTypeArg (_, AnnType t) = True isAnnTypeArg _ = False @@ -72,6 +80,20 @@ splitPArrayTy ty | otherwise = pprPanic "splitPArrayTy" (ppr ty) +mkClosureType :: Type -> Type -> VM Type +mkClosureType arg_ty res_ty + = do + tc <- builtin closureTyCon + return $ mkTyConApp tc [arg_ty, res_ty] + +mkClosureTypes :: [Type] -> Type -> VM Type +mkClosureTypes arg_tys res_ty + = do + tc <- builtin closureTyCon + return $ foldr (mk tc) res_ty arg_tys + where + mk tc arg_ty res_ty = mkTyConApp tc [arg_ty, res_ty] + mkPADictType :: Type -> VM Type mkPADictType ty = do @@ -195,19 +217,20 @@ hoistExpr fs expr env { global_bindings = (var, expr) : global_bindings env } return var -hoistVExpr :: FastString -> VExpr -> VM VVar -hoistVExpr fs (ve, le) +hoistVExpr :: VExpr -> VM VVar +hoistVExpr (ve, le) = do + fs <- getBindName vv <- hoistExpr ('v' `consFS` fs) ve lv <- hoistExpr ('l' `consFS` fs) le return (vv, lv) -hoistPolyVExpr :: FastString -> [TyVar] -> VM VExpr -> VM VExpr -hoistPolyVExpr fs tvs p +hoistPolyVExpr :: [TyVar] -> VM VExpr -> VM VExpr +hoistPolyVExpr tvs p = do expr <- closedV . polyAbstract tvs $ \abstract -> liftM (mapVect abstract) p - fn <- hoistVExpr fs expr + fn <- hoistVExpr expr polyVApply (vVar fn) (mkTyVarTys tvs) takeHoisted :: VM [(Var, CoreExpr)] @@ -217,7 +240,6 @@ takeHoisted setGEnv $ env { global_bindings = [] } return $ global_bindings env - mkClosure :: Type -> Type -> Type -> VExpr -> VExpr -> VM VExpr mkClosure arg_ty res_ty env_ty (vfn,lfn) (venv,lenv) = do @@ -227,11 +249,34 @@ mkClosure arg_ty res_ty env_ty (vfn,lfn) (venv,lenv) return (Var mkv `mkTyApps` [arg_ty, res_ty, env_ty] `mkApps` [dict, vfn, lfn, venv], Var mkl `mkTyApps` [arg_ty, res_ty, env_ty] `mkApps` [dict, vfn, lfn, lenv]) +mkClosureApp :: VExpr -> VExpr -> VM VExpr +mkClosureApp (vclo, lclo) (varg, larg) + = do + vapply <- builtin applyClosureVar + lapply <- builtin applyClosurePVar + return (Var vapply `mkTyApps` [arg_ty, res_ty] `mkApps` [vclo, varg], + Var lapply `mkTyApps` [arg_ty, res_ty] `mkApps` [lclo, larg]) + where + (arg_ty, res_ty) = splitClosureTy (exprType vclo) + +buildClosures :: [TyVar] -> Var -> [VVar] -> [Type] -> Type -> VM VExpr -> VM VExpr +buildClosures tvs lc vars [arg_ty] res_ty mk_body + = buildClosure tvs lc vars arg_ty res_ty mk_body +buildClosures tvs lc vars (arg_ty : arg_tys) res_ty mk_body + = do + res_ty' <- mkClosureTypes arg_tys res_ty + arg <- newLocalVVar FSLIT("x") arg_ty + buildClosure tvs lc vars arg_ty res_ty' + . hoistPolyVExpr tvs + $ do + clo <- buildClosures tvs lc (vars ++ [arg]) arg_tys res_ty mk_body + return $ vLams lc (vars ++ [arg]) clo + -- (clo , aclo (Arr lc xs1 ... xsn) ) -- where -- f = \env v -> case env of -> e x1 ... xn v -- f^ = \env v -> case env of Arr l xs1 ... xsn -> e^ l x1 ... xn v - +-- buildClosure :: [TyVar] -> Var -> [VVar] -> Type -> Type -> VM VExpr -> VM VExpr buildClosure tvs lv vars arg_ty res_ty mk_body = do @@ -239,7 +284,7 @@ buildClosure tvs lv vars arg_ty res_ty mk_body env_bndr <- newLocalVVar FSLIT("env") env_ty arg_bndr <- newLocalVVar FSLIT("arg") arg_ty - fn <- hoistPolyVExpr FSLIT("fn") tvs + fn <- hoistPolyVExpr tvs $ do body <- mk_body body' <- bind (vVar env_bndr)