X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fvectorise%2FVectorise.hs;h=777c195a2a37d8b322524943e763739157fc711b;hb=ef70af356e3229cc5c64359bf7866e5fdf44bb09;hp=cd1f42945474f6b39a4352036519cea14f4532cc;hpb=9bcd95bad83ee937c178970e8b729732e680fe1e;p=ghc-hetmet.git diff --git a/compiler/vectorise/Vectorise.hs b/compiler/vectorise/Vectorise.hs index cd1f429..777c195 100644 --- a/compiler/vectorise/Vectorise.hs +++ b/compiler/vectorise/Vectorise.hs @@ -193,7 +193,7 @@ vectPolyExpr (_, AnnNote note expr) vectPolyExpr expr = polyAbstract tvs $ \abstract -> do - mono' <- vectExpr mono + mono' <- vectFnExpr False mono return $ mapVect abstract mono' where (tvs, mono) = collectAnnTypeBinders expr @@ -263,15 +263,59 @@ vectExpr (_, AnnLet (AnnRec bs) body) . inBind bndr $ vectExpr rhs -vectExpr e@(fvs, AnnLam bndr _) - | isId bndr = vectLam fvs bs body +vectExpr e@(_, AnnLam bndr _) + | isId bndr = vectFnExpr True e +{- +onlyIfV (isEmptyVarSet fvs) (vectScalarLam bs $ deAnnotate body) + `orElseV` vectLam True fvs bs body where (bs,body) = collectAnnValBinders e +-} vectExpr e = cantVectorise "Can't vectorise expression" (ppr $ deAnnotate e) -vectLam :: VarSet -> [Var] -> CoreExprWithFVs -> VM VExpr -vectLam fvs bs body +vectFnExpr :: Bool -> CoreExprWithFVs -> VM VExpr +vectFnExpr inline e@(fvs, AnnLam bndr _) + | isId bndr = onlyIfV (isEmptyVarSet fvs) (vectScalarLam bs $ deAnnotate body) + `orElseV` vectLam inline fvs bs body + where + (bs,body) = collectAnnValBinders e +vectFnExpr _ e = vectExpr e + + +vectScalarLam :: [Var] -> CoreExpr -> VM VExpr +vectScalarLam args body + = do + scalars <- globalScalars + onlyIfV (all is_scalar_ty arg_tys + && is_scalar_ty res_ty + && is_scalar (extendVarSetList scalars args) body) + $ do + fn_var <- hoistExpr (fsLit "fn") (mkLams args body) + zipf <- zipScalars arg_tys res_ty + clo <- scalarClosure arg_tys res_ty (Var fn_var) + (zipf `App` Var fn_var) + clo_var <- hoistExpr (fsLit "clo") clo + lclo <- liftPA (Var clo_var) + return (Var clo_var, lclo) + where + arg_tys = map idType args + res_ty = exprType body + + is_scalar_ty ty | Just (tycon, []) <- splitTyConApp_maybe ty + = tycon == intTyCon + || tycon == floatTyCon + || tycon == doubleTyCon + + | otherwise = False + + is_scalar vs (Var v) = v `elemVarSet` vs + is_scalar _ e@(Lit _) = is_scalar_ty $ exprType e + is_scalar vs (App e1 e2) = is_scalar vs e1 && is_scalar vs e2 + is_scalar _ _ = False + +vectLam :: Bool -> VarSet -> [Var] -> CoreExprWithFVs -> VM VExpr +vectLam inline fvs bs body = do tyvars <- localTyVars (vs, vvs) <- readLEnv $ \env -> @@ -287,7 +331,9 @@ vectLam fvs bs body lc <- builtin liftingContext (vbndrs, vbody) <- vectBndrsIn (vs ++ bs) (vectExpr body) - return $ vLams lc vbndrs vbody + return . maybe_inline $ vLams lc vbndrs vbody + where + maybe_inline = if inline then vInlineMe else id vectTyAppExpr :: CoreExprWithFVs -> [Type] -> VM VExpr vectTyAppExpr (_, AnnVar v) tys = vectPolyVar v tys