Add VECTORISE [SCALAR] type pragma
[ghc.git] / compiler / vectorise / Vectorise / Builtins.hs
1 -- Types and functions declared in the DPH packages and used by the vectoriser.
2 --
3 -- The @Builtins@ structure holds the name of all the things in the DPH packages that appear in
4 -- code generated by the vectoriser. We can get specific things using the selectors, which print a
5 -- civilized panic message if the specified thing cannot be found.
6
7 module Vectorise.Builtins (
8 -- * Builtins
9 Builtins(..),
10 indexBuiltin,
11
12 -- * Wrapped selectors
13 selTy,
14 selReplicate,
15 selPick,
16 selTags,
17 selElements,
18 sumTyCon,
19 prodTyCon,
20 prodDataCon,
21 combinePDVar,
22 scalarZip,
23 closureCtrFun,
24
25 -- * Initialisation
26 initBuiltins, initBuiltinVars, initBuiltinTyCons, initBuiltinDataCons,
27 initBuiltinPAs, initBuiltinPRs,
28 initBuiltinBoxedTyCons,
29
30 -- * Lookup
31 primMethod,
32 primPArray
33 ) where
34
35 import Vectorise.Builtins.Base
36 import Vectorise.Builtins.Modules
37 import Vectorise.Builtins.Initialise
38
39 import TysPrim
40 import IfaceEnv
41 import TyCon
42 import DsMonad
43 import NameEnv
44 import Name
45 import Var
46 import Control.Monad
47
48
49 -- |Lookup a method function given its name and instance type.
50 --
51 primMethod :: TyCon -> String -> Builtins -> DsM (Maybe Var)
52 primMethod tycon method (Builtins { dphModules = mods })
53 | Just suffix <- lookupNameEnv prim_ty_cons (tyConName tycon)
54 = liftM Just
55 $ dsLookupGlobalId =<< lookupOrig (dph_Unboxed mods)
56 (mkVarOcc $ method ++ suffix)
57
58 | otherwise = return Nothing
59
60 -- |Lookup the representation type we use for PArrays that contain a given element type.
61 --
62 primPArray :: TyCon -> Builtins -> DsM (Maybe TyCon)
63 primPArray tycon (Builtins { dphModules = mods })
64 | Just suffix <- lookupNameEnv prim_ty_cons (tyConName tycon)
65 = liftM Just
66 $ dsLookupTyCon =<< lookupOrig (dph_Unboxed mods)
67 (mkTcOcc $ "PArray" ++ suffix)
68
69 | otherwise = return Nothing
70
71 prim_ty_cons :: NameEnv String
72 prim_ty_cons = mkNameEnv [mk_prim intPrimTyCon]
73 where
74 mk_prim tycon = (tyConName tycon, '_' : getOccString tycon)
75