2 module Vectorise.Convert
6 import Vectorise.Builtins
7 import Vectorise.Type.Type
16 -- | Build an expression that calls the vectorised version of some
17 -- function from a `Closure`.
26 -- We use the type of the original binding to work out how many
27 -- outer lambdas to add.
30 :: Type -- ^ The type of the original binding.
31 -> CoreExpr -- ^ Expression giving the closure to use, eg @$v_foo@.
34 -- Convert the type to the core view if it isn't already.
36 | Just ty' <- coreView ty
39 -- For each function constructor in the original type we add an outer
40 -- lambda to bind the parameter variable, and an inner application of it.
41 fromVect (FunTy arg_ty res_ty) expr
43 arg <- newLocalVar (fsLit "x") arg_ty
44 varg <- toVect arg_ty (Var arg)
45 varg_ty <- vectType arg_ty
46 vres_ty <- vectType res_ty
47 apply <- builtin applyVar
48 body <- fromVect res_ty
49 $ Var apply `mkTyApps` [varg_ty, vres_ty] `mkApps` [expr, varg]
52 -- If the type isn't a function then it's time to call on the closure.
54 = identityConv ty >> return expr
57 -- TODO: What is this really doing?
58 toVect :: Type -> CoreExpr -> VM CoreExpr
59 toVect ty expr = identityConv ty >> return expr
62 -- | Check that we have the vectorised versions of all the
63 -- type constructors in this type.
64 identityConv :: Type -> VM ()
66 | Just ty' <- coreView ty
69 identityConv (TyConApp tycon tys)
70 = do mapM_ identityConv tys
71 identityConvTyCon tycon
76 -- | Check that we have the vectorised version of this type constructor.
77 identityConvTyCon :: TyCon -> VM ()
79 | isBoxedTupleTyCon tc = return ()
80 | isUnLiftedTyCon tc = return ()
82 = do tc' <- maybeV (lookupTyCon tc)
83 if tc == tc' then return () else noV