X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fvectorise%2FVectorise%2FType%2FPADict.hs;h=5a6867d29ef4dff4b51e1bf8975eeb9546893e9c;hb=e7f49f77492af621de30b69046a3f6b1f81650dc;hp=7fdc31acae45ce72c4e95f8bd1fd7e89079d9d92;hpb=f86c92d05b404383e0a98cd5de8c2ba649804fc8;p=ghc-hetmet.git diff --git a/compiler/vectorise/Vectorise/Type/PADict.hs b/compiler/vectorise/Vectorise/Type/PADict.hs index 7fdc31a..5a6867d 100644 --- a/compiler/vectorise/Vectorise/Type/PADict.hs +++ b/compiler/vectorise/Vectorise/Type/PADict.hs @@ -2,13 +2,12 @@ module Vectorise.Type.PADict (buildPADict) where -import VectUtils import Vectorise.Monad import Vectorise.Builtins import Vectorise.Type.Repr import Vectorise.Type.PRepr import Vectorise.Type.PRDict -import Vectorise.Utils.Hoisting +import Vectorise.Utils import BasicTypes import CoreSyn @@ -16,14 +15,20 @@ import CoreUtils import CoreUnfold import TyCon import Type -import OccName import Id import Var import Name +-- | Build the PA dictionary for some type and hoist it to top level. +-- The PA dictionary holds fns that convert values to and from their vectorised representations. +buildPADict + :: TyCon -- ^ tycon of the type being vectorised. + -> TyCon -- ^ tycon of the type used for the vectorised representation. + -> TyCon -- + -> SumRepr -- ^ representation used for the type being vectorised. + -> VM Var -- ^ name of the top-level dictionary function. -buildPADict :: TyCon -> TyCon -> TyCon -> SumRepr -> VM Var buildPADict vect_tc prepr_tc arr_tc repr = polyAbstract tvs $ \args -> do @@ -38,23 +43,25 @@ buildPADict vect_tc prepr_tc arr_tc repr dfun_ty = mkForAllTys tvs $ mkFunTys (map varType args) (mkTyConApp pa_tc [inst_ty]) + -- Set the unfolding for the inliner. raw_dfun <- newExportedVar dfun_name dfun_ty - let dfun = raw_dfun `setIdUnfolding` mkDFunUnfolding dfun_ty (map Var method_ids) + let dfun = raw_dfun `setIdUnfolding` mkDFunUnfolding dfun_ty (map Var method_ids) `setInlinePragma` dfunInlinePragma + -- Add the new binding to the top-level environment. hoistBinding dfun dict return dfun where - tvs = tyConTyVars vect_tc - arg_tys = mkTyVarTys tvs - inst_ty = mkTyConApp vect_tc arg_tys + tvs = tyConTyVars vect_tc + arg_tys = mkTyVarTys tvs + inst_ty = mkTyConApp vect_tc arg_tys dfun_name = mkPADFunOcc (getOccName vect_tc) method args (name, build) = localV $ do - expr <- build vect_tc prepr_tc arr_tc repr + expr <- build vect_tc prepr_tc arr_tc repr let body = mkLams (tvs ++ args) expr raw_var <- newExportedVar (method_name name) (exprType body) let var = raw_var @@ -64,8 +71,7 @@ buildPADict vect_tc prepr_tc arr_tc repr return var method_call args id = mkApps (Var id) (map Type arg_tys ++ map Var args) - - method_name name = mkVarOcc $ occNameString dfun_name ++ ('$' : name) + method_name name = mkVarOcc $ occNameString dfun_name ++ ('$' : name) paMethods :: [(String, TyCon -> TyCon -> TyCon -> SumRepr -> VM CoreExpr)]