2 -- | Builtin types and functions used by the vectoriser.
3 -- These are all defined in the DPH package.
4 module Vectorise.Builtins.Base (
28 import Vectorise.Builtins.Modules
41 -- Numbers of things exported by the DPH library.
48 mAX_DPH_COMBINE :: Int
51 mAX_DPH_SCALAR_ARGS :: Int
52 mAX_DPH_SCALAR_ARGS = 3
55 -- | Holds the names of the builtin types and functions used by the vectoriser.
58 { dphModules :: Modules
60 -- From dph-common:Data.Array.Parallel.Lifted.PArray
61 , parrayTyCon :: TyCon -- ^ PArray
62 , parrayDataCon :: DataCon -- ^ PArray
63 , pdataTyCon :: TyCon -- ^ PData
64 , paTyCon :: TyCon -- ^ PA
65 , paDataCon :: DataCon -- ^ PA
66 , preprTyCon :: TyCon -- ^ PRepr
67 , prTyCon :: TyCon -- ^ PR
68 , prDataCon :: DataCon -- ^ PR
69 , replicatePDVar :: Var -- ^ replicatePD
70 , emptyPDVar :: Var -- ^ emptyPD
71 , packByTagPDVar :: Var -- ^ packByTagPD
72 , combinePDVars :: Array Int Var -- ^ combinePD
73 , scalarClass :: Class -- ^ Scalar
75 -- From dph-common:Data.Array.Parallel.Lifted.Closure
76 , closureTyCon :: TyCon -- ^ :->
77 , closureVar :: Var -- ^ closure
78 , applyVar :: Var -- ^ $:
79 , liftedClosureVar :: Var -- ^ liftedClosure
80 , liftedApplyVar :: Var -- ^ liftedApply
81 , closureCtrFuns :: Array Int Var -- ^ closure1 .. closure2
83 -- From dph-common:Data.Array.Parallel.Lifted.Repr
84 , voidTyCon :: TyCon -- ^ Void
85 , wrapTyCon :: TyCon -- ^ Wrap
86 , sumTyCons :: Array Int TyCon -- ^ Sum2 .. Sum3
87 , voidVar :: Var -- ^ void
88 , pvoidVar :: Var -- ^ pvoid
89 , fromVoidVar :: Var -- ^ fromVoid
90 , punitVar :: Var -- ^ punit
92 -- From dph-common:Data.Array.Parallel.Lifted.Selector
93 , selTys :: Array Int Type -- ^ Sel2
94 , selReplicates :: Array Int CoreExpr -- ^ replicate2
95 , selPicks :: Array Int CoreExpr -- ^ pick2
96 , selTagss :: Array Int CoreExpr -- ^ tagsSel2
97 , selEls :: Array (Int, Int) CoreExpr -- ^ elementsSel2_0 .. elementsSel_2_1
99 -- From dph-common:Data.Array.Parallel.Lifted.Scalar
100 -- NOTE: map is counted as a zipWith fn with one argument array.
101 , scalarZips :: Array Int Var -- ^ map, zipWith, zipWith3
104 , liftingContext :: Var -- ^ lc
108 -- | Get an element from one of the arrays of contained by a `Builtins`.
109 -- If the indexed thing is not in the array then panic.
111 :: (Ix i, Outputable i)
112 => String -- ^ Name of the selector we've used, for panic messages.
113 -> (Builtins -> Array i a) -- ^ Field selector for the `Builtins`.
114 -> i -- ^ Index into the array.
118 indexBuiltin fn f i bi
119 | inRange (bounds xs) i = xs ! i
121 = pprSorry "Vectorise.Builtins.indexBuiltin"
123 , text "DPH builtin function '" <> text fn <> text "' of size '" <> ppr i <> text "' is not yet implemented."
124 , text "This function does not appear in your source program, but it is needed"
125 , text "to compile your code in the backend. This is a known, current limitation"
126 , text "of DPH. If you want it to to work you should send mail to cvs-ghc@haskell.org"
127 , text "and ask what you can do to help (it might involve some GHC hacking)."])
132 -- Projections ----------------------------------------------------------------
133 -- We use these wrappers instead of indexing the `Builtin` structure directly
134 -- because they give nicer panic messages if the indexed thing cannot be found.
136 selTy :: Int -> Builtins -> Type
137 selTy = indexBuiltin "selTy" selTys
139 selReplicate :: Int -> Builtins -> CoreExpr
140 selReplicate = indexBuiltin "selReplicate" selReplicates
142 selPick :: Int -> Builtins -> CoreExpr
143 selPick = indexBuiltin "selPick" selPicks
145 selTags :: Int -> Builtins -> CoreExpr
146 selTags = indexBuiltin "selTags" selTagss
148 selElements :: Int -> Int -> Builtins -> CoreExpr
149 selElements i j = indexBuiltin "selElements" selEls (i,j)
151 sumTyCon :: Int -> Builtins -> TyCon
152 sumTyCon = indexBuiltin "sumTyCon" sumTyCons
154 prodTyCon :: Int -> Builtins -> TyCon
156 | n >= 2 && n <= mAX_DPH_PROD
160 = pprPanic "prodTyCon" (ppr n)
162 prodDataCon :: Int -> Builtins -> DataCon
164 = case tyConDataCons (prodTyCon n bi) of
166 _ -> pprPanic "prodDataCon" (ppr n)
168 combinePDVar :: Int -> Builtins -> Var
169 combinePDVar = indexBuiltin "combinePDVar" combinePDVars
171 scalarZip :: Int -> Builtins -> Var
172 scalarZip = indexBuiltin "scalarZip" scalarZips
174 closureCtrFun :: Int -> Builtins -> Var
175 closureCtrFun = indexBuiltin "closureCtrFun" closureCtrFuns