X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fvectorise%2FVectUtils.hs;h=a540b4d10c20102fa5c609d376e032ce696cb45d;hb=7c737416e30137e7053b4bcd0fdd563f07fa43b0;hp=1fb268f8a5c5b4273eea188a68fafa9242fdd37f;hpb=01e4f275e1c8cda513a3fea63a7ccf258af3277b;p=ghc-hetmet.git diff --git a/compiler/vectorise/VectUtils.hs b/compiler/vectorise/VectUtils.hs index 1fb268f..a540b4d 100644 --- a/compiler/vectorise/VectUtils.hs +++ b/compiler/vectorise/VectUtils.hs @@ -1,8 +1,16 @@ +{-# OPTIONS -w #-} +-- The above warning supression flag is a temporary kludge. +-- While working on this module you are encouraged to remove it and fix +-- any warnings in the module. See +-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings +-- for details + module VectUtils ( collectAnnTypeBinders, collectAnnTypeArgs, isAnnTypeArg, collectAnnValBinders, - mkDataConTag, mkDataConTagLit, - splitClosureTy, + dataConTagZ, mkDataConTag, mkDataConTagLit, + + newLocalVVar, mkBuiltinCo, mkPADictType, mkPArrayType, mkPReprType, @@ -10,7 +18,7 @@ module VectUtils ( parrayReprTyCon, parrayReprDataCon, mkVScrut, prDFunOfTyCon, paDictArgType, paDictOfType, paDFunType, - paMethod, mkPR, lengthPA, replicatePA, emptyPA, liftPA, + paMethod, mkPR, lengthPA, replicatePA, emptyPA, packPA, combinePA, liftPA, polyAbstract, polyApply, polyVApply, hoistBinding, hoistExpr, hoistPolyVExpr, takeHoisted, buildClosure, buildClosures, @@ -68,42 +76,14 @@ isAnnTypeArg :: AnnExpr b ann -> Bool isAnnTypeArg (_, AnnType t) = True isAnnTypeArg _ = False +dataConTagZ :: DataCon -> Int +dataConTagZ con = dataConTag con - fIRST_TAG + mkDataConTagLit :: DataCon -> Literal -mkDataConTagLit con - = mkMachInt . toInteger $ dataConTag con - fIRST_TAG +mkDataConTagLit = mkMachInt . toInteger . dataConTagZ mkDataConTag :: DataCon -> CoreExpr -mkDataConTag con = mkIntLitInt (dataConTag con - fIRST_TAG) - -splitUnTy :: String -> Name -> Type -> Type -splitUnTy s name ty - | Just (tc, [ty']) <- splitTyConApp_maybe ty - , tyConName tc == name - = ty' - - | otherwise = pprPanic s (ppr ty) - -splitBinTy :: String -> Name -> Type -> (Type, Type) -splitBinTy s name ty - | Just (tc, [ty1, ty2]) <- splitTyConApp_maybe ty - , tyConName tc == name - = (ty1, ty2) - - | otherwise = pprPanic s (ppr ty) - -splitFixedTyConApp :: TyCon -> Type -> [Type] -splitFixedTyConApp tc ty - | Just (tc', tys) <- splitTyConApp_maybe ty - , tc == tc' - = tys - - | otherwise = pprPanic "splitFixedTyConApp" (ppr tc <+> ppr ty) - -splitClosureTy :: Type -> (Type, Type) -splitClosureTy = splitBinTy "splitClosureTy" closureTyConName - -splitPArrayTy :: Type -> Type -splitPArrayTy = splitUnTy "splitPArrayTy" parrayTyConName +mkDataConTag = mkIntLitInt . dataConTagZ splitPrimTyCon :: Type -> Maybe TyCon splitPrimTyCon ty @@ -245,6 +225,7 @@ type PAMethod = (Builtins -> Var, String) pa_length = (lengthPAVar, "lengthPA") pa_replicate = (replicatePAVar, "replicatePA") pa_empty = (emptyPAVar, "emptyPA") +pa_pack = (packPAVar, "packPA") paMethod :: PAMethod -> Type -> VM CoreExpr paMethod (method, name) ty @@ -267,10 +248,8 @@ mkPR ty dict <- paDictOfType ty return $ mkApps (Var fn) [Type ty, dict] -lengthPA :: CoreExpr -> VM CoreExpr -lengthPA x = liftM (`App` x) (paMethod pa_length ty) - where - ty = splitPArrayTy (exprType x) +lengthPA :: Type -> CoreExpr -> VM CoreExpr +lengthPA ty x = liftM (`App` x) (paMethod pa_length ty) replicatePA :: CoreExpr -> CoreExpr -> VM CoreExpr replicatePA len x = liftM (`mkApps` [len,x]) @@ -279,6 +258,18 @@ replicatePA len x = liftM (`mkApps` [len,x]) emptyPA :: Type -> VM CoreExpr emptyPA = paMethod pa_empty +packPA :: Type -> CoreExpr -> CoreExpr -> CoreExpr -> VM CoreExpr +packPA ty xs len sel = liftM (`mkApps` [len, sel]) + (paMethod pa_pack ty) + +combinePA :: Type -> CoreExpr -> CoreExpr -> CoreExpr -> [CoreExpr] + -> VM CoreExpr +combinePA ty len sel is xs + = liftM (`mkApps` (len : sel : is : xs)) + (paMethod (combinePAVar n, "combine" ++ show n ++ "PA") ty) + where + n = length xs + liftPA :: CoreExpr -> VM CoreExpr liftPA x = do @@ -355,6 +346,19 @@ takeHoisted setGEnv $ env { global_bindings = [] } return $ global_bindings env +boxExpr :: Type -> VExpr -> VM VExpr +boxExpr ty (vexpr, lexpr) + | Just (tycon, []) <- splitTyConApp_maybe ty + , isUnLiftedTyCon tycon + = do + r <- lookupBoxedTyCon tycon + case r of + Just tycon' -> let [dc] = tyConDataCons tycon' + in + return (mkConApp dc [vexpr], lexpr) + Nothing -> return (vexpr, lexpr) + + mkClosure :: Type -> Type -> Type -> VExpr -> VExpr -> VM VExpr mkClosure arg_ty res_ty env_ty (vfn,lfn) (venv,lenv) = do @@ -364,15 +368,13 @@ 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) +mkClosureApp :: Type -> Type -> VExpr -> VExpr -> VM VExpr +mkClosureApp arg_ty res_ty (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] -> [VVar] -> [Type] -> Type -> VM VExpr -> VM VExpr buildClosures tvs vars [] res_ty mk_body @@ -441,7 +443,7 @@ mkLiftEnv :: Var -> [Type] -> [Var] -> VM (CoreExpr, CoreExpr -> CoreExpr -> VM mkLiftEnv lc [ty] [v] = return (Var v, \env body -> do - len <- lengthPA (Var v) + len <- lengthPA ty (Var v) return . Let (NonRec v env) $ Case len lc (exprType body) [(DEFAULT, [], body)])