module Vectorise.Builtins.Base (
mAX_DPH_PROD,
mAX_DPH_SUM,
mAX_DPH_COMBINE,
mAX_DPH_SCALAR_ARGS,
aLL_DPH_PRIM_TYCONS,
Builtins(..),
selTy, selsTy,
selReplicate,
selTags,
selElements,
selsLength,
sumTyCon,
prodTyCon,
prodDataCon,
replicatePD_PrimVar,
emptyPD_PrimVar,
packByTagPD_PrimVar,
combinePDVar,
combinePD_PrimVar,
scalarZip,
closureCtrFun
) where
import TysPrim
import BasicTypes
import Class
import CoreSyn
import TysWiredIn
import Type
import TyCon
import DataCon
import NameEnv
import Name
import Outputable
import Data.Array
mAX_DPH_PROD :: Int
mAX_DPH_PROD = 5
mAX_DPH_SUM :: Int
mAX_DPH_SUM = 2
mAX_DPH_COMBINE :: Int
mAX_DPH_COMBINE = 2
mAX_DPH_SCALAR_ARGS :: Int
mAX_DPH_SCALAR_ARGS = 8
aLL_DPH_PRIM_TYCONS :: [Name]
aLL_DPH_PRIM_TYCONS = map tyConName [intPrimTyCon, doublePrimTyCon]
data Builtins
= Builtins
{ parrayTyCon :: TyCon
, pdataTyCon :: TyCon
, pdatasTyCon :: TyCon
, prClass :: Class
, prTyCon :: TyCon
, preprTyCon :: TyCon
, paClass :: Class
, paTyCon :: TyCon
, paDataCon :: DataCon
, paPRSel :: Var
, replicatePDVar :: Var
, replicatePD_PrimVars :: NameEnv Var
, emptyPDVar :: Var
, emptyPD_PrimVars :: NameEnv Var
, packByTagPDVar :: Var
, packByTagPD_PrimVars :: NameEnv Var
, combinePDVars :: Array Int Var
, combinePD_PrimVarss :: Array Int (NameEnv Var)
, scalarClass :: Class
, scalarZips :: Array Int Var
, voidTyCon :: TyCon
, voidVar :: Var
, fromVoidVar :: Var
, sumTyCons :: Array Int TyCon
, wrapTyCon :: TyCon
, pvoidVar :: Var
, pvoidsVar :: Var
, closureTyCon :: TyCon
, closureVar :: Var
, liftedClosureVar :: Var
, applyVar :: Var
, liftedApplyVar :: Var
, closureCtrFuns :: Array Int Var
, selTys :: Array Int Type
, selsTys :: Array Int Type
, selsLengths :: Array Int CoreExpr
, selReplicates :: Array Int CoreExpr
, selTagss :: Array Int CoreExpr
, selElementss :: Array (Int, Int) CoreExpr
, liftingContext :: Var
}
selTy :: Int -> Builtins -> Type
selTy = indexBuiltin "selTy" selTys
selsTy :: Int -> Builtins -> Type
selsTy = indexBuiltin "selsTy" selsTys
selsLength :: Int -> Builtins -> CoreExpr
selsLength = indexBuiltin "selLength" selsLengths
selReplicate :: Int -> Builtins -> CoreExpr
selReplicate = indexBuiltin "selReplicate" selReplicates
selTags :: Int -> Builtins -> CoreExpr
selTags = indexBuiltin "selTags" selTagss
selElements :: Int -> Int -> Builtins -> CoreExpr
selElements i j = indexBuiltin "selElements" selElementss (i, j)
sumTyCon :: Int -> Builtins -> TyCon
sumTyCon = indexBuiltin "sumTyCon" sumTyCons
prodTyCon :: Int -> Builtins -> TyCon
prodTyCon n _
| n >= 2 && n <= mAX_DPH_PROD
= tupleTyCon BoxedTuple n
| otherwise
= pprPanic "prodTyCon" (ppr n)
prodDataCon :: Int -> Builtins -> DataCon
prodDataCon n bi
= case tyConDataCons (prodTyCon n bi) of
[con] -> con
_ -> pprPanic "prodDataCon" (ppr n)
replicatePD_PrimVar :: TyCon -> Builtins -> Var
replicatePD_PrimVar tc bi
= lookupEnvBuiltin "replicatePD_PrimVar" (replicatePD_PrimVars bi) (tyConName tc)
emptyPD_PrimVar :: TyCon -> Builtins -> Var
emptyPD_PrimVar tc bi
= lookupEnvBuiltin "emptyPD_PrimVar" (emptyPD_PrimVars bi) (tyConName tc)
packByTagPD_PrimVar :: TyCon -> Builtins -> Var
packByTagPD_PrimVar tc bi
= lookupEnvBuiltin "packByTagPD_PrimVar" (packByTagPD_PrimVars bi) (tyConName tc)
combinePDVar :: Int -> Builtins -> Var
combinePDVar = indexBuiltin "combinePDVar" combinePDVars
combinePD_PrimVar :: Int -> TyCon -> Builtins -> Var
combinePD_PrimVar i tc bi
= lookupEnvBuiltin "combinePD_PrimVar"
(indexBuiltin "combinePD_PrimVar" combinePD_PrimVarss i bi) (tyConName tc)
scalarZip :: Int -> Builtins -> Var
scalarZip = indexBuiltin "scalarZip" scalarZips
closureCtrFun :: Int -> Builtins -> Var
closureCtrFun = indexBuiltin "closureCtrFun" closureCtrFuns
indexBuiltin :: (Ix i, Outputable i)
=> String
-> (Builtins -> Array i a)
-> i
-> Builtins
-> a
indexBuiltin fn f i bi
| inRange (bounds xs) i = xs ! i
| otherwise
= pprSorry "Vectorise.Builtins.indexBuiltin"
(vcat [ text ""
, text "DPH builtin function '" <> text fn <> text "' of size '" <> ppr i <>
text "' is not yet implemented."
, text "This function does not appear in your source program, but it is needed"
, text "to compile your code in the backend. This is a known, current limitation"
, text "of DPH. If you want it to work, you should send mail to ghc-commits@haskell.org"
, text "and ask what you can do to help (it might involve some GHC hacking)."])
where xs = f bi
lookupEnvBuiltin :: String
-> NameEnv a
-> Name
-> a
lookupEnvBuiltin fn env n
| Just r <- lookupNameEnv env n = r
| otherwise
= pprSorry "Vectorise.Builtins.lookupEnvBuiltin"
(vcat [ text ""
, text "DPH builtin function '" <> text fn <> text "_" <> ppr n <>
text "' is not yet implemented."
, text "This function does not appear in your source program, but it is needed"
, text "to compile your code in the backend. This is a known, current limitation"
, text "of DPH. If you want it to work, you should send mail to ghc-commits@haskell.org"
, text "and ask what you can do to help (it might involve some GHC hacking)."])