{-# LANGUAGE LambdaCase #-}
module GHC.StgToCmm.ArgRep (
ArgRep(..), toArgRep, toArgRepOrV, argRepSizeW,
argRepString, isNonV, idArgRep,
slowCallPattern,
) where
import GHC.Prelude
import GHC.Platform
import GHC.StgToCmm.Closure ( idPrimRep1 )
import GHC.Runtime.Heap.Layout ( WordOff )
import GHC.Types.Id ( Id )
import GHC.Core.TyCon ( PrimRep(..), PrimOrVoidRep(..), 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
deriving ( ArgRep -> ArgRep -> Bool
(ArgRep -> ArgRep -> Bool)
-> (ArgRep -> ArgRep -> Bool) -> Eq ArgRep
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ArgRep -> ArgRep -> Bool
== :: ArgRep -> ArgRep -> Bool
$c/= :: ArgRep -> ArgRep -> Bool
/= :: ArgRep -> ArgRep -> Bool
Eq, Eq ArgRep
Eq ArgRep =>
(ArgRep -> ArgRep -> Ordering)
-> (ArgRep -> ArgRep -> Bool)
-> (ArgRep -> ArgRep -> Bool)
-> (ArgRep -> ArgRep -> Bool)
-> (ArgRep -> ArgRep -> Bool)
-> (ArgRep -> ArgRep -> ArgRep)
-> (ArgRep -> ArgRep -> ArgRep)
-> Ord ArgRep
ArgRep -> ArgRep -> Bool
ArgRep -> ArgRep -> Ordering
ArgRep -> ArgRep -> ArgRep
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ArgRep -> ArgRep -> Ordering
compare :: ArgRep -> ArgRep -> Ordering
$c< :: ArgRep -> ArgRep -> Bool
< :: ArgRep -> ArgRep -> Bool
$c<= :: ArgRep -> ArgRep -> Bool
<= :: ArgRep -> ArgRep -> Bool
$c> :: ArgRep -> ArgRep -> Bool
> :: ArgRep -> ArgRep -> Bool
$c>= :: ArgRep -> ArgRep -> Bool
>= :: ArgRep -> ArgRep -> Bool
$cmax :: ArgRep -> ArgRep -> ArgRep
max :: ArgRep -> ArgRep -> ArgRep
$cmin :: ArgRep -> ArgRep -> ArgRep
min :: ArgRep -> ArgRep -> ArgRep
Ord )
instance Outputable ArgRep where ppr :: ArgRep -> SDoc
ppr = String -> SDoc
forall doc. IsLine doc => String -> doc
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 :: Platform -> PrimRep -> ArgRep
toArgRep :: Platform -> PrimRep -> ArgRep
toArgRep Platform
platform PrimRep
rep = case PrimRep
rep of
BoxedRep Maybe Levity
_ -> ArgRep
P
PrimRep
IntRep -> ArgRep
N
PrimRep
WordRep -> ArgRep
N
PrimRep
Int8Rep -> ArgRep
N
PrimRep
Word8Rep -> ArgRep
N
PrimRep
Int16Rep -> ArgRep
N
PrimRep
Word16Rep -> ArgRep
N
PrimRep
Int32Rep -> ArgRep
N
PrimRep
Word32Rep -> ArgRep
N
PrimRep
AddrRep -> ArgRep
N
PrimRep
Int64Rep -> case Platform -> PlatformWordSize
platformWordSize Platform
platform of
PlatformWordSize
PW4 -> ArgRep
L
PlatformWordSize
PW8 -> ArgRep
N
PrimRep
Word64Rep -> case Platform -> PlatformWordSize
platformWordSize Platform
platform of
PlatformWordSize
PW4 -> ArgRep
L
PlatformWordSize
PW8 -> ArgRep
N
PrimRep
FloatRep -> ArgRep
F
PrimRep
DoubleRep -> ArgRep
D
(VecRep WordOff
len PrimElemRep
elem) -> case WordOff
lenWordOff -> WordOff -> WordOff
forall a. Num a => a -> a -> a
*Platform -> PrimElemRep -> WordOff
primElemRepSizeB Platform
platform PrimElemRep
elem of
WordOff
16 -> ArgRep
V16
WordOff
32 -> ArgRep
V32
WordOff
64 -> ArgRep
V64
WordOff
_ -> String -> ArgRep
forall a. HasCallStack => String -> a
error String
"toArgRep: bad vector primrep"
toArgRepOrV :: Platform -> PrimOrVoidRep -> ArgRep
toArgRepOrV :: Platform -> PrimOrVoidRep -> ArgRep
toArgRepOrV Platform
_ PrimOrVoidRep
VoidRep = ArgRep
V
toArgRepOrV Platform
platform (NVRep PrimRep
rep) = Platform -> PrimRep -> ArgRep
toArgRep Platform
platform PrimRep
rep
isNonV :: ArgRep -> Bool
isNonV :: ArgRep -> Bool
isNonV ArgRep
V = Bool
False
isNonV ArgRep
_ = Bool
True
argRepSizeW :: Platform -> ArgRep -> WordOff
argRepSizeW :: Platform -> ArgRep -> WordOff
argRepSizeW Platform
platform = \case
ArgRep
N -> WordOff
1
ArgRep
P -> WordOff
1
ArgRep
F -> WordOff
1
ArgRep
L -> WordOff
wORD64_SIZE WordOff -> WordOff -> WordOff
forall a. Integral a => a -> a -> a
`quot` WordOff
ws
ArgRep
D -> WordOff
dOUBLE_SIZE WordOff -> WordOff -> WordOff
forall a. Integral a => a -> a -> a
`quot` WordOff
ws
ArgRep
V -> WordOff
0
ArgRep
V16 -> WordOff
16 WordOff -> WordOff -> WordOff
forall a. Integral a => a -> a -> a
`quot` WordOff
ws
ArgRep
V32 -> WordOff
32 WordOff -> WordOff -> WordOff
forall a. Integral a => a -> a -> a
`quot` WordOff
ws
ArgRep
V64 -> WordOff
64 WordOff -> WordOff -> WordOff
forall a. Integral a => a -> a -> a
`quot` WordOff
ws
where
ws :: WordOff
ws = Platform -> WordOff
platformWordSizeInBytes Platform
platform
idArgRep :: Platform -> Id -> ArgRep
idArgRep :: Platform -> Id -> ArgRep
idArgRep Platform
platform = Platform -> PrimOrVoidRep -> ArgRep
toArgRepOrV Platform
platform (PrimOrVoidRep -> ArgRep) -> (Id -> PrimOrVoidRep) -> Id -> ArgRep
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Id -> PrimOrVoidRep
idPrimRep1
slowCallPattern :: [ArgRep] -> (FastString, RepArity)
slowCallPattern :: [ArgRep] -> (FastString, WordOff)
slowCallPattern (ArgRep
P: ArgRep
P: ArgRep
P: ArgRep
P: ArgRep
P: ArgRep
P: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_pppppp", WordOff
6)
slowCallPattern (ArgRep
P: ArgRep
P: ArgRep
P: ArgRep
P: ArgRep
P: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_ppppp", WordOff
5)
slowCallPattern (ArgRep
P: ArgRep
P: ArgRep
P: ArgRep
P: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_pppp", WordOff
4)
slowCallPattern (ArgRep
P: ArgRep
P: ArgRep
P: ArgRep
V: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_pppv", WordOff
4)
slowCallPattern (ArgRep
P: ArgRep
P: ArgRep
P: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_ppp", WordOff
3)
slowCallPattern (ArgRep
P: ArgRep
P: ArgRep
V: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_ppv", WordOff
3)
slowCallPattern (ArgRep
P: ArgRep
P: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_pp", WordOff
2)
slowCallPattern (ArgRep
P: ArgRep
V: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_pv", WordOff
2)
slowCallPattern (ArgRep
P: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_p", WordOff
1)
slowCallPattern (ArgRep
V: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_v", WordOff
1)
slowCallPattern (ArgRep
N: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_n", WordOff
1)
slowCallPattern (ArgRep
F: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_f", WordOff
1)
slowCallPattern (ArgRep
D: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_d", WordOff
1)
slowCallPattern (ArgRep
L: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_l", WordOff
1)
slowCallPattern (ArgRep
V16: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_v16", WordOff
1)
slowCallPattern (ArgRep
V32: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_v32", WordOff
1)
slowCallPattern (ArgRep
V64: [ArgRep]
_) = (String -> FastString
fsLit String
"stg_ap_v64", WordOff
1)
slowCallPattern [] = (String -> FastString
fsLit String
"stg_ap_0", WordOff
0)