- return b
- where
- (vars, exprs) = unzip bs
-
-vectTopBinder :: Var -> VM Var
-vectTopBinder var
- = do
- vty <- vectType (idType var)
- name <- cloneName mkVectOcc (getName var)
- let var' | isExportedId var = Id.mkExportedLocalId name vty
- | otherwise = Id.mkLocalId name vty
- defGlobalVar var var'
- return var'
-
-vectTopRhs :: CoreExpr -> VM CoreExpr
-vectTopRhs = liftM fst . closedV . vectPolyExpr (panic "Empty lifting context") . freeVars
-
--- ----------------------------------------------------------------------------
--- Bindings
-
-vectBndr :: Var -> VM (Var, Var)
-vectBndr v
- = do
- vty <- vectType (idType v)
- lty <- mkPArrayType vty
- let vv = v `Id.setIdType` vty
- lv = v `Id.setIdType` lty
- updLEnv (mapTo vv lv)
- return (vv, lv)
- where
- mapTo vv lv env = env { local_vars = extendVarEnv (local_vars env) v (Var vv, Var lv) }
-
-vectBndrIn :: Var -> VM a -> VM (Var, Var, a)
-vectBndrIn v p
- = localV
- $ do
- (vv, lv) <- vectBndr v
- x <- p
- return (vv, lv, x)
-
-vectBndrsIn :: [Var] -> VM a -> VM ([Var], [Var], a)
-vectBndrsIn vs p
- = localV
- $ do
- (vvs, lvs) <- mapAndUnzipM vectBndr vs
- x <- p
- return (vvs, lvs, x)
-
--- ----------------------------------------------------------------------------
--- Expressions
-
-capply :: (CoreExpr, CoreExpr) -> (CoreExpr, CoreExpr) -> VM (CoreExpr, CoreExpr)
-capply (vfn, lfn) (varg, larg)
- = do
- apply <- builtin applyClosureVar
- applyP <- builtin applyClosurePVar
- return (mkApps (Var apply) [Type arg_ty, Type res_ty, vfn, varg],
- mkApps (Var applyP) [Type arg_ty, Type res_ty, lfn, larg])
- where
- fn_ty = exprType vfn
- (arg_ty, res_ty) = splitClosureTy fn_ty
-
-vectVar :: CoreExpr -> Var -> VM (CoreExpr, CoreExpr)
-vectVar lc v
- = do
- r <- lookupVar v
- case r of
- Local es -> return es
- Global vexpr -> do
- lexpr <- replicatePA vexpr lc
- return (vexpr, lexpr)
-
-vectPolyVar :: CoreExpr -> Var -> [Type] -> VM (CoreExpr, CoreExpr)
-vectPolyVar lc v tys
- = do
- r <- lookupVar v
- case r of
- Local (vexpr, lexpr) -> liftM2 (,) (mk_app vexpr) (mk_app lexpr)
- Global poly -> do
- vexpr <- mk_app poly
- lexpr <- replicatePA vexpr lc
- return (vexpr, lexpr)
- where
- mk_app e = applyToTypes e =<< mapM vectType tys
-
-vectPolyExpr :: CoreExpr -> CoreExprWithFVs -> VM (CoreExpr, CoreExpr)
-vectPolyExpr lc expr
- = localV
- . abstractOverTyVars tvs $ \mk_lams ->
- -- FIXME: shadowing (tvs in lc)
- do
- (vmono, lmono) <- vectExpr lc mono
- return $ (mk_lams vmono, mk_lams lmono)
- where
- (tvs, mono) = collectAnnTypeBinders expr
-
-vectExpr :: CoreExpr -> CoreExprWithFVs -> VM (CoreExpr, CoreExpr)
-vectExpr lc (_, AnnType ty)
- = do
- vty <- vectType ty
- return (Type vty, Type vty)
-
-vectExpr lc (_, AnnVar v) = vectVar lc v
-
-vectExpr lc (_, AnnLit lit)
- = do
- let vexpr = Lit lit
- lexpr <- replicatePA vexpr lc
- return (vexpr, lexpr)
-
-vectExpr lc (_, AnnNote note expr)
- = do
- (vexpr, lexpr) <- vectExpr lc expr
- return (Note note vexpr, Note note lexpr)
-
-vectExpr lc e@(_, AnnApp _ arg)
- | isAnnTypeArg arg
- = vectTyAppExpr lc fn tys
- where
- (fn, tys) = collectAnnTypeArgs e
-
-vectExpr lc (_, AnnApp fn arg)
- = do
- fn' <- vectExpr lc fn
- arg' <- vectExpr lc arg
- capply fn' arg'
-
-vectExpr lc (_, AnnCase expr bndr ty alts)
- = panic "vectExpr: case"
-
-vectExpr lc (_, AnnLet (AnnNonRec bndr rhs) body)
- = do
- (vrhs, lrhs) <- vectPolyExpr lc rhs
- (vbndr, lbndr, (vbody, lbody)) <- vectBndrIn bndr (vectExpr lc body)
- return (Let (NonRec vbndr vrhs) vbody,
- Let (NonRec lbndr lrhs) lbody)
-
-vectExpr lc (_, AnnLet (AnnRec prs) body)
- = do
- (vbndrs, lbndrs, (vrhss, vbody, lrhss, lbody)) <- vectBndrsIn bndrs vect
- return (Let (Rec (zip vbndrs vrhss)) vbody,
- Let (Rec (zip lbndrs lrhss)) lbody)
- where
- (bndrs, rhss) = unzip prs