X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Fvectorise%2FVectType.hs;h=b4b3c43b2d231c964120eb469abeb71b462e1846;hp=84d9aa54fdca6375fdd6a7f2e7793ee3c71cf5ba;hb=7e8cba32c6f045dde3db8a9ddc9831ec8ab4ed43;hpb=9d03becc597e5b1ab6c8466209a1263bf8ba6f29 diff --git a/compiler/vectorise/VectType.hs b/compiler/vectorise/VectType.hs index 84d9aa5..b4b3c43 100644 --- a/compiler/vectorise/VectType.hs +++ b/compiler/vectorise/VectType.hs @@ -12,6 +12,7 @@ import VectCore import HscTypes ( TypeEnv, extendTypeEnvList, typeEnvTyCons ) import CoreSyn import CoreUtils +import MkCore ( mkWildCase ) import BuildTyCl import DataCon import TyCon @@ -23,7 +24,6 @@ import OccName import MkId import BasicTypes ( StrictnessMark(..), boolToRecFlag ) import Var ( Var, TyVar ) -import Id ( mkWildId ) import Name ( Name, getOccName ) import NameEnv import TysWiredIn @@ -32,8 +32,8 @@ import TysPrim ( intPrimTy ) import Unique import UniqFM import UniqSet -import Util ( singleton ) -import Digraph ( SCC(..), stronglyConnComp ) +import Util +import Digraph ( SCC(..), stronglyConnCompFromEdgedVertices ) import Outputable import FastString @@ -49,13 +49,8 @@ vectTyCon tc | isFunTyCon tc = builtin closureTyCon | isBoxedTupleTyCon tc = return tc | isUnLiftedTyCon tc = return tc - | otherwise = do - r <- lookupTyCon tc - case r of - Just tc' -> return tc' - - -- FIXME: just for now - Nothing -> pprTrace "ccTyCon:" (ppr tc) $ return tc + | otherwise = maybeCantVectoriseM "Tycon not vectorised:" (ppr tc) + $ lookupTyCon tc vectAndLiftType :: Type -> VM (Type, Type) vectAndLiftType ty | Just ty' <- coreView ty = vectAndLiftType ty' @@ -86,7 +81,7 @@ vectType ty@(ForAllTy _ _) where (tyvars, mono_ty) = splitForAllTys ty -vectType ty = pprPanic "vectType:" (ppr ty) +vectType ty = cantVectorise "Can't vectorise type" (ppr ty) vectAndBoxType :: Type -> VM Type vectAndBoxType ty = vectType ty >>= boxType @@ -154,17 +149,14 @@ vectTypeEnv env vectTyConDecls :: [TyCon] -> VM [TyCon] vectTyConDecls tcs = fixV $ \tcs' -> do - mapM_ (uncurry defTyCon) (lazy_zip tcs tcs') + mapM_ (uncurry defTyCon) (zipLazy tcs tcs') mapM vectTyConDecl tcs - where - lazy_zip [] _ = [] - lazy_zip (x:xs) ~(y:ys) = (x,y) : lazy_zip xs ys vectTyConDecl :: TyCon -> VM TyCon vectTyConDecl tc = do name' <- cloneName mkVectTyConOcc name - rhs' <- vectAlgTyConRhs (algTyConRhs tc) + rhs' <- vectAlgTyConRhs tc (algTyConRhs tc) liftDs $ buildAlgTyCon name' tyvars @@ -179,22 +171,24 @@ vectTyConDecl tc tyvars = tyConTyVars tc rec_flag = boolToRecFlag (isRecursiveTyCon tc) -vectAlgTyConRhs :: AlgTyConRhs -> VM AlgTyConRhs -vectAlgTyConRhs (DataTyCon { data_cons = data_cons - , is_enum = is_enum - }) +vectAlgTyConRhs :: TyCon -> AlgTyConRhs -> VM AlgTyConRhs +vectAlgTyConRhs _ (DataTyCon { data_cons = data_cons + , is_enum = is_enum + }) = do data_cons' <- mapM vectDataCon data_cons zipWithM_ defDataCon data_cons data_cons' return $ DataTyCon { data_cons = data_cons' , is_enum = is_enum } -vectAlgTyConRhs _ = panic "vectAlgTyConRhs" +vectAlgTyConRhs tc _ = cantVectorise "Can't vectorise type definition:" (ppr tc) vectDataCon :: DataCon -> VM DataCon vectDataCon dc - | not . null $ dataConExTyVars dc = pprPanic "vectDataCon: existentials" (ppr dc) - | not . null $ dataConEqSpec dc = pprPanic "vectDataCon: eq spec" (ppr dc) + | not . null $ dataConExTyVars dc + = cantVectorise "Can't vectorise constructor (existentials):" (ppr dc) + | not . null $ dataConEqSpec dc + = cantVectorise "Can't vectorise constructor (eq spec):" (ppr dc) | otherwise = do name' <- cloneName mkVectDataConOcc name @@ -230,6 +224,7 @@ buildPReprTyCon orig_tc vect_tc liftDs $ buildSynTyCon name tyvars (SynonymTyCon rhs_ty) + (typeKind rhs_ty) (Just $ mk_fam_inst prepr_tc vect_tc) where tyvars = tyConTyVars vect_tc @@ -433,7 +428,7 @@ arrReprVars repr mkRepr :: TyCon -> VM Repr mkRepr vect_tc | [tys] <- rep_tys = boxedProductRepr tys - -- | all null rep_tys = enumRepr + -- removed: | all null rep_tys = enumRepr | otherwise = sumRepr =<< mapM unboxedProductRepr rep_tys where rep_tys = map dataConRepArgTys $ tyConDataCons vect_tc @@ -463,7 +458,7 @@ buildToPRepr repr vect_tc prepr_tc _ expr = do (vars, bodies) <- mapAndUnzipM to_unboxed prods - return . Case expr (mkWildId (exprType expr)) res_ty + return . mkWildCase expr (exprType expr) res_ty $ zipWith4 mk_alt cons vars (tyConDataCons tycon) bodies where mk_alt con vars sum_con body @@ -472,7 +467,7 @@ buildToPRepr repr vect_tc prepr_tc _ ty_args = map (Type . reprType) prods to_repr (EnumRepr { enum_data_con = data_con }) expr - = return . Case expr (mkWildId (exprType expr)) res_ty + = return . mkWildCase expr (exprType expr) res_ty $ map mk_alt cons where mk_alt con = (DataAlt con, [], mkConApp data_con [mkDataConTag con]) @@ -480,7 +475,7 @@ buildToPRepr repr vect_tc prepr_tc _ to_repr prod expr = do (vars, body) <- to_unboxed prod - return $ Case expr (mkWildId (exprType expr)) res_ty + return $ mkWildCase expr (exprType expr) res_ty [(DataAlt con, vars, body)] to_unboxed (ProdRepr { prod_components = tys @@ -523,7 +518,7 @@ buildFromPRepr repr vect_tc prepr_tc _ vars <- mapM (newLocalVar (fsLit "x")) (map reprType prods) bodies <- sequence . zipWith3 from_unboxed prods cons $ map Var vars - return . Case expr (mkWildId (reprType repr)) res_ty + return . mkWildCase expr (reprType repr) res_ty $ zipWith3 sum_alt (tyConDataCons tycon) vars bodies where sum_alt data_con var body = (DataAlt data_con, [var], body) @@ -532,11 +527,11 @@ buildFromPRepr repr vect_tc prepr_tc _ = do var <- newLocalVar (fsLit "n") intPrimTy - let res = Case (Var var) (mkWildId intPrimTy) res_ty + let res = mkWildCase (Var var) intPrimTy res_ty $ (DEFAULT, [], error_expr) : zipWith mk_alt (tyConDataCons vect_tc) cons - return $ Case expr (mkWildId (reprType repr)) res_ty + return $ mkWildCase expr (reprType repr) res_ty [(DataAlt data_con, [var], res)] where mk_alt data_con con = (LitAlt (mkDataConTagLit data_con), [], con) @@ -553,7 +548,7 @@ buildFromPRepr repr vect_tc prepr_tc _ expr = do vars <- mapM (newLocalVar (fsLit "y")) tys - return $ Case expr (mkWildId (reprType prod)) res_ty + return $ mkWildCase expr (reprType prod) res_ty [(DataAlt data_con, vars, con `mkVarApps` vars)] from_unboxed (IdRepr _) con expr @@ -588,7 +583,7 @@ buildToArrPRepr repr vect_tc prepr_tc arr_tc return . Lam arg . mkCoerce co - $ Case scrut (mkWildId (mkTyConApp arr_tc var_tys)) res_ty + $ mkWildCase scrut (mkTyConApp arr_tc var_tys) res_ty [(DataAlt arr_dc, shape_vars ++ concat repr_vars, result)] where var_tys = mkTyVarTys $ tyConTyVars vect_tc @@ -688,7 +683,7 @@ buildFromArrPRepr repr vect_tc prepr_tc arr_tc result <- go prods repr_vars vars body let scrut = unwrapFamInstScrut tycon ty_args expr - return . Case scrut (mkWildId scrut_ty) res_ty + return . mkWildCase scrut scrut_ty res_ty $ [(DataAlt data_con, shape_vars ++ vars, result)] where ty_args = map reprType prods @@ -720,7 +715,7 @@ buildFromArrPRepr repr vect_tc prepr_tc arr_tc let scrut = unwrapFamInstScrut tycon tys expr scrut_ty = mkTyConApp tycon tys - return $ Case scrut (mkWildId scrut_ty) res_ty + return $ mkWildCase scrut scrut_ty res_ty [(DataAlt data_con, shape_vars ++ repr_vars, body)] from_prod (EnumRepr { enum_arr_tycon = tycon @@ -733,7 +728,7 @@ buildFromArrPRepr repr vect_tc prepr_tc arr_tc = let scrut = unwrapFamInstScrut tycon [] expr scrut_ty = mkTyConApp tycon [] in - return $ Case scrut (mkWildId scrut_ty) res_ty + return $ mkWildCase scrut scrut_ty res_ty [(DataAlt data_con, shape_vars, body)] from_prod (IdRepr _) @@ -982,7 +977,7 @@ classifyTyCons = classify [] [] -- | Compute mutually recursive groups of tycons in topological order -- tyConGroups :: [TyCon] -> [TyConGroup] -tyConGroups tcs = map mk_grp (stronglyConnComp edges) +tyConGroups tcs = map mk_grp (stronglyConnCompFromEdgedVertices edges) where edges = [((tc, ds), tc, uniqSetToList ds) | tc <- tcs , let ds = tyConsOfTyCon tc]