{-# LANGUAGE LambdaCase #-}
module GHC.StgToCmm.ArgRep (
ArgRep(..), toArgRep, argRepSizeW,
argRepString, isNonV, idArgRep,
slowCallPattern,
) where
import GHC.Prelude
import GHC.Platform
import GHC.StgToCmm.Closure ( idPrimRep )
import GHC.Runtime.Heap.Layout ( WordOff )
import GHC.Types.Id ( Id )
import GHC.Core.TyCon ( PrimRep(..), primElemRepSizeB )
import GHC.Types.Basic ( RepArity )
import GHC.Settings.Constants ( wORD64_SIZE, dOUBLE_SIZE )
import GHC.Utils.Outputable
import GHC.Data.FastString
data ArgRep = P
| N
| L
| V
| F
| D
| V16
| V32
| V64
instance Outputable ArgRep where ppr :: ArgRep -> SDoc
ppr = String -> SDoc
text (String -> SDoc) -> (ArgRep -> String) -> ArgRep -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArgRep -> String
argRepString
argRepString :: ArgRep -> String
argRepString :: ArgRep -> String
argRepString ArgRep
P = String
"P"
argRepString ArgRep
N = String
"N"
argRepString ArgRep
L = String
"L"
argRepString ArgRep
V = String
"V"
argRepString ArgRep
F = String
"F"
argRepString ArgRep
D = String
"D"
argRepString ArgRep
V16 = String
"V16"
argRepString ArgRep
V32 = String
"V32"
argRepString ArgRep
V64 = String
"V64"
toArgRep :: PrimRep -> ArgRep
toArgRep :: PrimRep -> ArgRep
toArgRep PrimRep
VoidRep = ArgRep
V
toArgRep PrimRep
LiftedRep = ArgRep
P
toArgRep PrimRep
UnliftedRep = ArgRep
P
toArgRep PrimRep
IntRep = ArgRep
N
toArgRep PrimRep
WordRep = ArgRep
N
toArgRep PrimRep
Int8Rep = ArgRep
N
toArgRep PrimRep
Word8Rep = ArgRep
N
toArgRep PrimRep
Int16Rep = ArgRep
N
toArgRep PrimRep
Word16Rep = ArgRep
N
toArgRep PrimRep
Int32Rep = ArgRep
N
toArgRep PrimRep
Word32Rep = ArgRep
N
toArgRep PrimRep
AddrRep = ArgRep
N
toArgRep PrimRep
Int64Rep = ArgRep
L
toArgRep PrimRep
Word64Rep = ArgRep
L
toArgRep PrimRep
FloatRep = ArgRep
F
toArgRep PrimRep
DoubleRep = ArgRep
D
toArgRep (VecRep Int
len PrimElemRep
elem) = case Int
lenInt -> Int -> Int
forall a. Num a => a -> a -> a
*PrimElemRep -> Int
primElemRepSizeB PrimElemRep
elem of
Int
16 -> ArgRep
V16
Int
32 -> ArgRep
V32
Int
64 -> ArgRep
V64
Int
_ -> String -> ArgRep
forall a. HasCallStack => String -> a
error String
"toArgRep: bad vector primrep"
isNonV :: ArgRep -> Bool
isNonV :: ArgRep -> Bool
isNonV ArgRep
V = Bool
False
isNonV ArgRep
_ = Bool
True
argRepSizeW :: Platform -> ArgRep -> WordOff
argRepSizeW :: Platform -> ArgRep -> Int
argRepSizeW Platform
platform = \case
ArgRep
N -> Int
1
ArgRep
P -> Int
1
ArgRep
F -> Int
1
ArgRep
L -> Int
wORD64_SIZE Int -> Int -> Int
forall a. Integral a => a -> a -> a
`quot` Int
ws
ArgRep
D -> Int
dOUBLE_SIZE Int -> Int -> Int
forall a. Integral a => a -> a -> a
`quot` Int
ws
ArgRep
V -> Int
0
ArgRep
V16 -> Int
16 Int -> Int -> Int
forall a. Integral a => a -> a -> a
`quot` Int
ws
ArgRep
V32 -> Int
32 Int -> Int -> Int
forall a. Integral a => a -> a -> a
`quot` Int
ws
ArgRep
V64 -> Int
64 Int -> Int -> Int
forall a. Integral a => a -> a -> a
`quot` Int
ws
where
ws :: Int
ws = Platform -> Int
platformWordSizeInBytes Platform
platform
idArgRep :: Id -> ArgRep
idArgRep :: Id -> ArgRep
idArgRep = PrimRep -> ArgRep
toArgRep (PrimRep -> ArgRep) -> (Id -> PrimRep) -> Id -> ArgRep
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Id -> PrimRep
idPrimRep
slowCallPattern :: [ArgRep] -> (FastString, RepArity)
slowCallPattern :: [ArgRep] -> (FastString, Int)
slowCallPattern (ArgRep
P: ArgRep
P: ArgRep
P: ArgRep
P: ArgRep
P: ArgRep
P: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_pppppp", Int
6)
slowCallPattern (ArgRep
P: ArgRep
P: ArgRep
P: ArgRep
P: ArgRep
P: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_ppppp", Int
5)
slowCallPattern (ArgRep
P: ArgRep
P: ArgRep
P: ArgRep
P: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_pppp", Int
4)
slowCallPattern (ArgRep
P: ArgRep
P: ArgRep
P: ArgRep
V: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_pppv", Int
4)
slowCallPattern (ArgRep
P: ArgRep
P: ArgRep
P: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_ppp", Int
3)
slowCallPattern (ArgRep
P: ArgRep
P: ArgRep
V: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_ppv", Int
3)
slowCallPattern (ArgRep
P: ArgRep
P: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_pp", Int
2)
slowCallPattern (ArgRep
P: ArgRep
V: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_pv", Int
2)
slowCallPattern (ArgRep
P: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_p", Int
1)
slowCallPattern (ArgRep
V: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_v", Int
1)
slowCallPattern (ArgRep
N: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_n", Int
1)
slowCallPattern (ArgRep
F: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_f", Int
1)
slowCallPattern (ArgRep
D: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_d", Int
1)
slowCallPattern (ArgRep
L: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_l", Int
1)
slowCallPattern (ArgRep
V16: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_v16", Int
1)
slowCallPattern (ArgRep
V32: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_v32", Int
1)
slowCallPattern (ArgRep
V64: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_v64", Int
1)
slowCallPattern [] = (String -> FastString
fsLit String
"stg_ap_0", Int
0)