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