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 , paClass :: Class -- ^ PA
65 , paTyCon :: TyCon -- ^ PA
66 , paDataCon :: DataCon -- ^ PA
67 , paPRSel :: Var -- ^ PA
68 , preprTyCon :: TyCon -- ^ PRepr
69 , prClass :: Class -- ^ PR
70 , prTyCon :: TyCon -- ^ PR
71 , prDataCon :: DataCon -- ^ PR
72 , replicatePDVar :: Var -- ^ replicatePD
73 , emptyPDVar :: Var -- ^ emptyPD
74 , packByTagPDVar :: Var -- ^ packByTagPD
75 , combinePDVars :: Array Int Var -- ^ combinePD
76 , scalarClass :: Class -- ^ Scalar
78 -- From dph-common:Data.Array.Parallel.Lifted.Closure
79 , closureTyCon :: TyCon -- ^ :->
80 , closureVar :: Var -- ^ closure
81 , applyVar :: Var -- ^ $:
82 , liftedClosureVar :: Var -- ^ liftedClosure
83 , liftedApplyVar :: Var -- ^ liftedApply
84 , closureCtrFuns :: Array Int Var -- ^ closure1 .. closure2
86 -- From dph-common:Data.Array.Parallel.Lifted.Repr
87 , voidTyCon :: TyCon -- ^ Void
88 , wrapTyCon :: TyCon -- ^ Wrap
89 , sumTyCons :: Array Int TyCon -- ^ Sum2 .. Sum3
90 , voidVar :: Var -- ^ void
91 , pvoidVar :: Var -- ^ pvoid
92 , fromVoidVar :: Var -- ^ fromVoid
93 , punitVar :: Var -- ^ punit
95 -- From dph-common:Data.Array.Parallel.Lifted.Selector
96 , selTys :: Array Int Type -- ^ Sel2
97 , selReplicates :: Array Int CoreExpr -- ^ replicate2
98 , selPicks :: Array Int CoreExpr -- ^ pick2
99 , selTagss :: Array Int CoreExpr -- ^ tagsSel2
100 , selEls :: Array (Int, Int) CoreExpr -- ^ elementsSel2_0 .. elementsSel_2_1
102 -- From dph-common:Data.Array.Parallel.Lifted.Scalar
103 -- NOTE: map is counted as a zipWith fn with one argument array.
104 , scalarZips :: Array Int Var -- ^ map, zipWith, zipWith3
107 , liftingContext :: Var -- ^ lc
111 -- | Get an element from one of the arrays of contained by a `Builtins`.
112 -- If the indexed thing is not in the array then panic.
114 :: (Ix i, Outputable i)
115 => String -- ^ Name of the selector we've used, for panic messages.
116 -> (Builtins -> Array i a) -- ^ Field selector for the `Builtins`.
117 -> i -- ^ Index into the array.
121 indexBuiltin fn f i bi
122 | inRange (bounds xs) i = xs ! i
124 = pprSorry "Vectorise.Builtins.indexBuiltin"
126 , text "DPH builtin function '" <> text fn <> text "' of size '" <> ppr i <> text "' is not yet implemented."
127 , text "This function does not appear in your source program, but it is needed"
128 , text "to compile your code in the backend. This is a known, current limitation"
129 , text "of DPH. If you want it to to work you should send mail to cvs-ghc@haskell.org"
130 , text "and ask what you can do to help (it might involve some GHC hacking)."])
135 -- Projections ----------------------------------------------------------------
136 -- We use these wrappers instead of indexing the `Builtin` structure directly
137 -- because they give nicer panic messages if the indexed thing cannot be found.
139 selTy :: Int -> Builtins -> Type
140 selTy = indexBuiltin "selTy" selTys
142 selReplicate :: Int -> Builtins -> CoreExpr
143 selReplicate = indexBuiltin "selReplicate" selReplicates
145 selPick :: Int -> Builtins -> CoreExpr
146 selPick = indexBuiltin "selPick" selPicks
148 selTags :: Int -> Builtins -> CoreExpr
149 selTags = indexBuiltin "selTags" selTagss
151 selElements :: Int -> Int -> Builtins -> CoreExpr
152 selElements i j = indexBuiltin "selElements" selEls (i,j)
154 sumTyCon :: Int -> Builtins -> TyCon
155 sumTyCon = indexBuiltin "sumTyCon" sumTyCons
157 prodTyCon :: Int -> Builtins -> TyCon
159 | n >= 2 && n <= mAX_DPH_PROD
163 = pprPanic "prodTyCon" (ppr n)
165 prodDataCon :: Int -> Builtins -> DataCon
167 = case tyConDataCons (prodTyCon n bi) of
169 _ -> pprPanic "prodDataCon" (ppr n)
171 combinePDVar :: Int -> Builtins -> Var
172 combinePDVar = indexBuiltin "combinePDVar" combinePDVars
174 scalarZip :: Int -> Builtins -> Var
175 scalarZip = indexBuiltin "scalarZip" scalarZips
177 closureCtrFun :: Int -> Builtins -> Var
178 closureCtrFun = indexBuiltin "closureCtrFun" closureCtrFuns