-import FastString
-import Control.Monad ( liftM, liftM2, zipWithM, mapAndUnzipM )
-
-vectorise :: HscEnv -> UniqSupply -> RuleBase -> ModGuts
- -> IO (SimplCount, ModGuts)
-vectorise hsc_env _ _ guts
- = do
- showPass dflags "Vectorisation"
- eps <- hscEPS hsc_env
- let info = hptVectInfo hsc_env `plusVectInfo` eps_vect_info eps
- Just (info', guts') <- initV hsc_env guts info (vectModule guts)
- endPass dflags "Vectorisation" Opt_D_dump_vect (mg_binds guts')
- return (zeroSimplCount dflags, guts' { mg_vect_info = info' })
- where
- dflags = hsc_dflags hsc_env
-
-vectModule :: ModGuts -> VM ModGuts
-vectModule guts
- = do
- (types', fam_insts, tc_binds) <- vectTypeEnv (mg_types guts)
-
- let fam_inst_env' = extendFamInstEnvList (mg_fam_inst_env guts) fam_insts
- updGEnv (setFamInstEnv fam_inst_env')
-
- -- dicts <- mapM buildPADict pa_insts
- -- workers <- mapM vectDataConWorkers pa_insts
- binds' <- mapM vectTopBind (mg_binds guts)
- return $ guts { mg_types = types'
- , mg_binds = Rec tc_binds : binds'
- , mg_fam_inst_env = fam_inst_env'
- , mg_fam_insts = mg_fam_insts guts ++ fam_insts
- }
-
-vectTopBind :: CoreBind -> VM CoreBind
-vectTopBind b@(NonRec var expr)
- = do
- var' <- vectTopBinder var
- expr' <- vectTopRhs var expr
- hs <- takeHoisted
- return . Rec $ (var, expr) : (var', expr') : hs
- `orElseV`
- return b
-
-vectTopBind b@(Rec bs)
- = do
- vars' <- mapM vectTopBinder vars
- exprs' <- zipWithM vectTopRhs vars exprs
- hs <- takeHoisted
- return . Rec $ bs ++ zip vars' exprs' ++ hs
- `orElseV`
- return b
- where
- (vars, exprs) = unzip bs
-
-vectTopBinder :: Var -> VM Var
-vectTopBinder var
- = do
- vty <- vectType (idType var)
- var' <- cloneId mkVectOcc var vty
- defGlobalVar var var'
- return var'
-
-vectTopRhs :: Var -> CoreExpr -> VM CoreExpr
-vectTopRhs var expr
- = do
- closedV . liftM vectorised
- . inBind var
- $ vectPolyExpr (freeVars expr)
-
--- ----------------------------------------------------------------------------
--- Bindings
-
-vectBndr :: Var -> VM VVar
-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 (vv, lv) }
-
-vectBndrNew :: Var -> FastString -> VM VVar
-vectBndrNew v fs
- = do
- vty <- vectType (idType v)
- vv <- newLocalVVar fs vty
- updLEnv (upd vv)
- return vv
- where
- upd vv env = env { local_vars = extendVarEnv (local_vars env) v vv }
-
-vectBndrIn :: Var -> VM a -> VM (VVar, a)
-vectBndrIn v p
- = localV
- $ do
- vv <- vectBndr v
- x <- p
- return (vv, x)
-
-vectBndrNewIn :: Var -> FastString -> VM a -> VM (VVar, a)
-vectBndrNewIn v fs p
- = localV
- $ do
- vv <- vectBndrNew v fs
- x <- p
- return (vv, x)
-
-vectBndrIn' :: Var -> (VVar -> VM a) -> VM (VVar, a)
-vectBndrIn' v p
- = localV
- $ do
- vv <- vectBndr v
- x <- p vv
- return (vv, x)
-
-vectBndrsIn :: [Var] -> VM a -> VM ([VVar], a)
-vectBndrsIn vs p
- = localV
- $ do
- vvs <- mapM vectBndr vs
- x <- p
- return (vvs, x)