X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fvectorise%2FVectUtils.hs;h=a1f554db50e8d1de4157912e0a6f554a138966d9;hb=430cdcde07075d7e2a6d81578e8b889b53bf24b7;hp=77e037f4779d8a4905de463360b0f7772dfb82a1;hpb=b7994edd84d6350d65080cc147cd9995e61dbf95;p=ghc-hetmet.git diff --git a/compiler/vectorise/VectUtils.hs b/compiler/vectorise/VectUtils.hs index 77e037f..a1f554d 100644 --- a/compiler/vectorise/VectUtils.hs +++ b/compiler/vectorise/VectUtils.hs @@ -9,9 +9,9 @@ module VectUtils ( mkPADictType, mkPArrayType, mkPReprType, parrayCoerce, parrayReprTyCon, parrayReprDataCon, mkVScrut, - prDictOfType, prCoerce, + prDFunOfTyCon, prCoerce, paDictArgType, paDictOfType, paDFunType, - paMethod, lengthPA, replicatePA, emptyPA, liftPA, + paMethod, mkPR, lengthPA, replicatePA, emptyPA, liftPA, polyAbstract, polyApply, polyVApply, hoistBinding, hoistExpr, hoistPolyVExpr, takeHoisted, buildClosure, buildClosures, @@ -41,6 +41,7 @@ import BasicTypes ( Boxity(..) ) import Outputable import FastString +import Maybes ( orElse ) import Data.List ( zipWith4 ) import Control.Monad ( liftM, liftM2, zipWithM_ ) @@ -126,13 +127,15 @@ mkBuiltinTyConApps1 get_tc dft tys mk tc ty1 ty2 = mkTyConApp tc [ty1,ty2] data TyConRepr = TyConRepr { - repr_tyvars :: [TyVar] - , repr_tys :: [[Type]] - - , repr_prod_tycons :: [Maybe TyCon] - , repr_prod_tys :: [Type] - , repr_sum_tycon :: Maybe TyCon - , repr_type :: Type + repr_tyvars :: [TyVar] + , repr_tys :: [[Type]] + + , repr_prod_tycons :: [Maybe TyCon] + , repr_prod_data_cons :: [Maybe DataCon] + , repr_prod_tys :: [Type] + , repr_sum_tycon :: Maybe TyCon + , repr_sum_data_cons :: [DataCon] + , repr_type :: Type } mkTyConRepr :: TyCon -> VM TyConRepr @@ -143,13 +146,15 @@ mkTyConRepr vect_tc sum_tycon <- mk_tycon sumTyCon prod_tys return $ TyConRepr { - repr_tyvars = tyvars - , repr_tys = rep_tys - - , repr_prod_tycons = prod_tycons - , repr_prod_tys = prod_tys - , repr_sum_tycon = sum_tycon - , repr_type = mk_tc_app_maybe sum_tycon prod_tys + repr_tyvars = tyvars + , repr_tys = rep_tys + + , repr_prod_tycons = prod_tycons + , repr_prod_data_cons = map (fmap mk_single_datacon) prod_tycons + , repr_prod_tys = prod_tys + , repr_sum_tycon = sum_tycon + , repr_sum_data_cons = fmap tyConDataCons sum_tycon `orElse` [] + , repr_type = mk_tc_app_maybe sum_tycon prod_tys } where tyvars = tyConTyVars vect_tc @@ -161,6 +166,8 @@ mkTyConRepr vect_tc | otherwise = return Nothing where n = length tys + mk_single_datacon tc | [dc] <- tyConDataCons tc = dc + mk_tc_app_maybe Nothing [] = unitTy mk_tc_app_maybe Nothing [ty] = ty mk_tc_app_maybe (Just tc) tys = mkTyConApp tc tys @@ -241,35 +248,9 @@ mkVScrut (ve, le) (tc, arg_tys) <- parrayReprTyCon (exprType ve) return ((ve, unwrapFamInstScrut tc arg_tys le), tc, arg_tys) -prDictOfType :: Type -> VM CoreExpr -prDictOfType orig_ty - | Just (tycon, ty_args) <- splitTyConApp_maybe orig_ty - = do - dfun <- traceMaybeV "prDictOfType" (ppr tycon) (lookupTyConPR tycon) - prDFunApply (Var dfun) ty_args - -prDFunApply :: CoreExpr -> [Type] -> VM CoreExpr -prDFunApply dfun tys - = do - args <- mapM mkDFunArg arg_tys - return $ mkApps mono_dfun args - where - mono_dfun = mkTyApps dfun tys - (arg_tys, _) = splitFunTys (exprType mono_dfun) - -mkDFunArg :: Type -> VM CoreExpr -mkDFunArg ty - | Just (tycon, [arg]) <- splitTyConApp_maybe ty - - = let name = tyConName tycon - - get_dict | name == paTyConName = paDictOfType - | name == prTyConName = prDictOfType - | otherwise = pprPanic "mkDFunArg" (ppr ty) - - in get_dict arg - -mkDFunArg ty = pprPanic "mkDFunArg" (ppr ty) +prDFunOfTyCon :: TyCon -> VM CoreExpr +prDFunOfTyCon tycon + = liftM Var (traceMaybeV "prDictOfTyCon" (ppr tycon) (lookupTyConPR tycon)) prCoerce :: TyCon -> [Type] -> CoreExpr -> VM CoreExpr prCoerce repr_tc args expr