module Vectorise.Builtins.Base (
mAX_DPH_PROD,
mAX_DPH_SUM,
mAX_DPH_COMBINE,
mAX_DPH_SCALAR_ARGS,
Builtins(..),
indexBuiltin,
selTy,
selReplicate,
selPick,
selTags,
selElements,
sumTyCon,
prodTyCon,
prodDataCon,
combinePDVar,
scalarZip,
closureCtrFun
) where
import Vectorise.Builtins.Modules
import BasicTypes
import Class
import CoreSyn
import TysWiredIn
import Type
import TyCon
import DataCon
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 = 3
data Builtins
= Builtins
{ dphModules :: Modules
, parrayTyCon :: TyCon
, parrayDataCon :: DataCon
, pdataTyCon :: TyCon
, paClass :: Class
, paTyCon :: TyCon
, paDataCon :: DataCon
, paPRSel :: Var
, preprTyCon :: TyCon
, prClass :: Class
, prTyCon :: TyCon
, prDataCon :: DataCon
, replicatePDVar :: Var
, emptyPDVar :: Var
, packByTagPDVar :: Var
, combinePDVars :: Array Int Var
, scalarClass :: Class
, closureTyCon :: TyCon
, closureVar :: Var
, applyVar :: Var
, liftedClosureVar :: Var
, liftedApplyVar :: Var
, closureCtrFuns :: Array Int Var
, voidTyCon :: TyCon
, wrapTyCon :: TyCon
, sumTyCons :: Array Int TyCon
, voidVar :: Var
, pvoidVar :: Var
, fromVoidVar :: Var
, punitVar :: Var
, selTys :: Array Int Type
, selReplicates :: Array Int CoreExpr
, selPicks :: Array Int CoreExpr
, selTagss :: Array Int CoreExpr
, selEls :: Array (Int, Int) CoreExpr
, scalarZips :: Array Int Var
, liftingContext :: Var
}
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 to work you should send mail to cvs-ghc@haskell.org"
, text "and ask what you can do to help (it might involve some GHC hacking)."])
where xs = f bi
selTy :: Int -> Builtins -> Type
selTy = indexBuiltin "selTy" selTys
selReplicate :: Int -> Builtins -> CoreExpr
selReplicate = indexBuiltin "selReplicate" selReplicates
selPick :: Int -> Builtins -> CoreExpr
selPick = indexBuiltin "selPick" selPicks
selTags :: Int -> Builtins -> CoreExpr
selTags = indexBuiltin "selTags" selTagss
selElements :: Int -> Int -> Builtins -> CoreExpr
selElements i j = indexBuiltin "selElements" selEls (i,j)
sumTyCon :: Int -> Builtins -> TyCon
sumTyCon = indexBuiltin "sumTyCon" sumTyCons
prodTyCon :: Int -> Builtins -> TyCon
prodTyCon n _
| n >= 2 && n <= mAX_DPH_PROD
= tupleTyCon Boxed 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)
combinePDVar :: Int -> Builtins -> Var
combinePDVar = indexBuiltin "combinePDVar" combinePDVars
scalarZip :: Int -> Builtins -> Var
scalarZip = indexBuiltin "scalarZip" scalarZips
closureCtrFun :: Int -> Builtins -> Var
closureCtrFun = indexBuiltin "closureCtrFun" closureCtrFuns