{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module GHC.Cmm.Reg
(
CmmReg(..)
, cmmRegType
, cmmRegWidth
, LocalReg(..)
, localRegType
, GlobalReg(..), isArgReg, globalRegType
, pprGlobalReg
, spReg, hpReg, spLimReg, hpLimReg, nodeReg
, currentTSOReg, currentNurseryReg, hpAllocReg, cccsReg
, node, baseReg
, VGcPtr(..)
) where
import GHC.Prelude
import GHC.Platform
import GHC.Utils.Outputable
import GHC.Types.Unique
import GHC.Cmm.Type
data CmmReg
= CmmLocal {-# UNPACK #-} !LocalReg
| CmmGlobal GlobalReg
deriving( CmmReg -> CmmReg -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CmmReg -> CmmReg -> Bool
$c/= :: CmmReg -> CmmReg -> Bool
== :: CmmReg -> CmmReg -> Bool
$c== :: CmmReg -> CmmReg -> Bool
Eq, Eq CmmReg
CmmReg -> CmmReg -> Bool
CmmReg -> CmmReg -> Ordering
CmmReg -> CmmReg -> CmmReg
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
min :: CmmReg -> CmmReg -> CmmReg
$cmin :: CmmReg -> CmmReg -> CmmReg
max :: CmmReg -> CmmReg -> CmmReg
$cmax :: CmmReg -> CmmReg -> CmmReg
>= :: CmmReg -> CmmReg -> Bool
$c>= :: CmmReg -> CmmReg -> Bool
> :: CmmReg -> CmmReg -> Bool
$c> :: CmmReg -> CmmReg -> Bool
<= :: CmmReg -> CmmReg -> Bool
$c<= :: CmmReg -> CmmReg -> Bool
< :: CmmReg -> CmmReg -> Bool
$c< :: CmmReg -> CmmReg -> Bool
compare :: CmmReg -> CmmReg -> Ordering
$ccompare :: CmmReg -> CmmReg -> Ordering
Ord, Int -> CmmReg -> ShowS
[CmmReg] -> ShowS
CmmReg -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CmmReg] -> ShowS
$cshowList :: [CmmReg] -> ShowS
show :: CmmReg -> String
$cshow :: CmmReg -> String
showsPrec :: Int -> CmmReg -> ShowS
$cshowsPrec :: Int -> CmmReg -> ShowS
Show )
instance Outputable CmmReg where
ppr :: CmmReg -> SDoc
ppr CmmReg
e = CmmReg -> SDoc
pprReg CmmReg
e
pprReg :: CmmReg -> SDoc
pprReg :: CmmReg -> SDoc
pprReg CmmReg
r
= case CmmReg
r of
CmmLocal LocalReg
local -> LocalReg -> SDoc
pprLocalReg LocalReg
local
CmmGlobal GlobalReg
global -> forall doc. IsLine doc => GlobalReg -> doc
pprGlobalReg GlobalReg
global
cmmRegType :: Platform -> CmmReg -> CmmType
cmmRegType :: Platform -> CmmReg -> CmmType
cmmRegType Platform
_ (CmmLocal LocalReg
reg) = LocalReg -> CmmType
localRegType LocalReg
reg
cmmRegType Platform
platform (CmmGlobal GlobalReg
reg) = Platform -> GlobalReg -> CmmType
globalRegType Platform
platform GlobalReg
reg
cmmRegWidth :: Platform -> CmmReg -> Width
cmmRegWidth :: Platform -> CmmReg -> Width
cmmRegWidth Platform
platform = CmmType -> Width
typeWidth forall b c a. (b -> c) -> (a -> b) -> a -> c
. Platform -> CmmReg -> CmmType
cmmRegType Platform
platform
data LocalReg
= LocalReg {-# UNPACK #-} !Unique !CmmType
deriving Int -> LocalReg -> ShowS
[LocalReg] -> ShowS
LocalReg -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LocalReg] -> ShowS
$cshowList :: [LocalReg] -> ShowS
show :: LocalReg -> String
$cshow :: LocalReg -> String
showsPrec :: Int -> LocalReg -> ShowS
$cshowsPrec :: Int -> LocalReg -> ShowS
Show
instance Eq LocalReg where
(LocalReg Unique
u1 CmmType
_) == :: LocalReg -> LocalReg -> Bool
== (LocalReg Unique
u2 CmmType
_) = Unique
u1 forall a. Eq a => a -> a -> Bool
== Unique
u2
instance Outputable LocalReg where
ppr :: LocalReg -> SDoc
ppr LocalReg
e = LocalReg -> SDoc
pprLocalReg LocalReg
e
instance Ord LocalReg where
compare :: LocalReg -> LocalReg -> Ordering
compare (LocalReg Unique
u1 CmmType
_) (LocalReg Unique
u2 CmmType
_) = Unique -> Unique -> Ordering
nonDetCmpUnique Unique
u1 Unique
u2
instance Uniquable LocalReg where
getUnique :: LocalReg -> Unique
getUnique (LocalReg Unique
uniq CmmType
_) = Unique
uniq
localRegType :: LocalReg -> CmmType
localRegType :: LocalReg -> CmmType
localRegType (LocalReg Unique
_ CmmType
rep) = CmmType
rep
pprLocalReg :: LocalReg -> SDoc
pprLocalReg :: LocalReg -> SDoc
pprLocalReg (LocalReg Unique
uniq CmmType
rep) =
forall doc. IsLine doc => Char -> doc
char Char
'_' forall doc. IsLine doc => doc -> doc -> doc
<> forall {a}. Outputable a => a -> SDoc
pprUnique Unique
uniq forall doc. IsLine doc => doc -> doc -> doc
<>
(if CmmType -> Bool
isWord32 CmmType
rep
then SDoc
dcolon forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
ptr forall doc. IsLine doc => doc -> doc -> doc
<> forall {a}. Outputable a => a -> SDoc
ppr CmmType
rep
else SDoc
dcolon forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
ptr forall doc. IsLine doc => doc -> doc -> doc
<> forall {a}. Outputable a => a -> SDoc
ppr CmmType
rep)
where
pprUnique :: a -> SDoc
pprUnique a
unique = forall a. (SDocContext -> a) -> (a -> SDoc) -> SDoc
sdocOption SDocContext -> Bool
sdocSuppressUniques forall a b. (a -> b) -> a -> b
$ \case
Bool
True -> forall doc. IsLine doc => String -> doc
text String
"_locVar_"
Bool
False -> forall {a}. Outputable a => a -> SDoc
ppr a
unique
ptr :: SDoc
ptr = forall doc. IsOutput doc => doc
empty
data VGcPtr = VGcPtr | VNonGcPtr deriving( VGcPtr -> VGcPtr -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VGcPtr -> VGcPtr -> Bool
$c/= :: VGcPtr -> VGcPtr -> Bool
== :: VGcPtr -> VGcPtr -> Bool
$c== :: VGcPtr -> VGcPtr -> Bool
Eq, Int -> VGcPtr -> ShowS
[VGcPtr] -> ShowS
VGcPtr -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VGcPtr] -> ShowS
$cshowList :: [VGcPtr] -> ShowS
show :: VGcPtr -> String
$cshow :: VGcPtr -> String
showsPrec :: Int -> VGcPtr -> ShowS
$cshowsPrec :: Int -> VGcPtr -> ShowS
Show )
data GlobalReg
= VanillaReg
{-# UNPACK #-} !Int
VGcPtr
| FloatReg
{-# UNPACK #-} !Int
| DoubleReg
{-# UNPACK #-} !Int
| LongReg
{-# UNPACK #-} !Int
| XmmReg
{-# UNPACK #-} !Int
| YmmReg
{-# UNPACK #-} !Int
| ZmmReg
{-# UNPACK #-} !Int
| Sp
| SpLim
| Hp
| HpLim
| CCCS
| CurrentTSO
| CurrentNursery
| HpAlloc
| EagerBlackholeInfo
| GCEnter1
| GCFun
| BaseReg
| MachSp
| UnwindReturnReg
| PicBaseReg
deriving( Int -> GlobalReg -> ShowS
[GlobalReg] -> ShowS
GlobalReg -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GlobalReg] -> ShowS
$cshowList :: [GlobalReg] -> ShowS
show :: GlobalReg -> String
$cshow :: GlobalReg -> String
showsPrec :: Int -> GlobalReg -> ShowS
$cshowsPrec :: Int -> GlobalReg -> ShowS
Show )
instance Eq GlobalReg where
VanillaReg Int
i VGcPtr
_ == :: GlobalReg -> GlobalReg -> Bool
== VanillaReg Int
j VGcPtr
_ = Int
iforall a. Eq a => a -> a -> Bool
==Int
j
FloatReg Int
i == FloatReg Int
j = Int
iforall a. Eq a => a -> a -> Bool
==Int
j
DoubleReg Int
i == DoubleReg Int
j = Int
iforall a. Eq a => a -> a -> Bool
==Int
j
LongReg Int
i == LongReg Int
j = Int
iforall a. Eq a => a -> a -> Bool
==Int
j
XmmReg Int
i == XmmReg Int
j = Int
iforall a. Eq a => a -> a -> Bool
==Int
j
YmmReg Int
i == YmmReg Int
j = Int
iforall a. Eq a => a -> a -> Bool
==Int
j
ZmmReg Int
i == ZmmReg Int
j = Int
iforall a. Eq a => a -> a -> Bool
==Int
j
GlobalReg
Sp == GlobalReg
Sp = Bool
True
GlobalReg
SpLim == GlobalReg
SpLim = Bool
True
GlobalReg
Hp == GlobalReg
Hp = Bool
True
GlobalReg
HpLim == GlobalReg
HpLim = Bool
True
GlobalReg
CCCS == GlobalReg
CCCS = Bool
True
GlobalReg
CurrentTSO == GlobalReg
CurrentTSO = Bool
True
GlobalReg
CurrentNursery == GlobalReg
CurrentNursery = Bool
True
GlobalReg
HpAlloc == GlobalReg
HpAlloc = Bool
True
GlobalReg
EagerBlackholeInfo == GlobalReg
EagerBlackholeInfo = Bool
True
GlobalReg
GCEnter1 == GlobalReg
GCEnter1 = Bool
True
GlobalReg
GCFun == GlobalReg
GCFun = Bool
True
GlobalReg
BaseReg == GlobalReg
BaseReg = Bool
True
GlobalReg
MachSp == GlobalReg
MachSp = Bool
True
GlobalReg
UnwindReturnReg == GlobalReg
UnwindReturnReg = Bool
True
GlobalReg
PicBaseReg == GlobalReg
PicBaseReg = Bool
True
GlobalReg
_r1 == GlobalReg
_r2 = Bool
False
instance Ord GlobalReg where
compare :: GlobalReg -> GlobalReg -> Ordering
compare (VanillaReg Int
i VGcPtr
_) (VanillaReg Int
j VGcPtr
_) = forall a. Ord a => a -> a -> Ordering
compare Int
i Int
j
compare (FloatReg Int
i) (FloatReg Int
j) = forall a. Ord a => a -> a -> Ordering
compare Int
i Int
j
compare (DoubleReg Int
i) (DoubleReg Int
j) = forall a. Ord a => a -> a -> Ordering
compare Int
i Int
j
compare (LongReg Int
i) (LongReg Int
j) = forall a. Ord a => a -> a -> Ordering
compare Int
i Int
j
compare (XmmReg Int
i) (XmmReg Int
j) = forall a. Ord a => a -> a -> Ordering
compare Int
i Int
j
compare (YmmReg Int
i) (YmmReg Int
j) = forall a. Ord a => a -> a -> Ordering
compare Int
i Int
j
compare (ZmmReg Int
i) (ZmmReg Int
j) = forall a. Ord a => a -> a -> Ordering
compare Int
i Int
j
compare GlobalReg
Sp GlobalReg
Sp = Ordering
EQ
compare GlobalReg
SpLim GlobalReg
SpLim = Ordering
EQ
compare GlobalReg
Hp GlobalReg
Hp = Ordering
EQ
compare GlobalReg
HpLim GlobalReg
HpLim = Ordering
EQ
compare GlobalReg
CCCS GlobalReg
CCCS = Ordering
EQ
compare GlobalReg
CurrentTSO GlobalReg
CurrentTSO = Ordering
EQ
compare GlobalReg
CurrentNursery GlobalReg
CurrentNursery = Ordering
EQ
compare GlobalReg
HpAlloc GlobalReg
HpAlloc = Ordering
EQ
compare GlobalReg
EagerBlackholeInfo GlobalReg
EagerBlackholeInfo = Ordering
EQ
compare GlobalReg
GCEnter1 GlobalReg
GCEnter1 = Ordering
EQ
compare GlobalReg
GCFun GlobalReg
GCFun = Ordering
EQ
compare GlobalReg
BaseReg GlobalReg
BaseReg = Ordering
EQ
compare GlobalReg
MachSp GlobalReg
MachSp = Ordering
EQ
compare GlobalReg
UnwindReturnReg GlobalReg
UnwindReturnReg = Ordering
EQ
compare GlobalReg
PicBaseReg GlobalReg
PicBaseReg = Ordering
EQ
compare (VanillaReg Int
_ VGcPtr
_) GlobalReg
_ = Ordering
LT
compare GlobalReg
_ (VanillaReg Int
_ VGcPtr
_) = Ordering
GT
compare (FloatReg Int
_) GlobalReg
_ = Ordering
LT
compare GlobalReg
_ (FloatReg Int
_) = Ordering
GT
compare (DoubleReg Int
_) GlobalReg
_ = Ordering
LT
compare GlobalReg
_ (DoubleReg Int
_) = Ordering
GT
compare (LongReg Int
_) GlobalReg
_ = Ordering
LT
compare GlobalReg
_ (LongReg Int
_) = Ordering
GT
compare (XmmReg Int
_) GlobalReg
_ = Ordering
LT
compare GlobalReg
_ (XmmReg Int
_) = Ordering
GT
compare (YmmReg Int
_) GlobalReg
_ = Ordering
LT
compare GlobalReg
_ (YmmReg Int
_) = Ordering
GT
compare (ZmmReg Int
_) GlobalReg
_ = Ordering
LT
compare GlobalReg
_ (ZmmReg Int
_) = Ordering
GT
compare GlobalReg
Sp GlobalReg
_ = Ordering
LT
compare GlobalReg
_ GlobalReg
Sp = Ordering
GT
compare GlobalReg
SpLim GlobalReg
_ = Ordering
LT
compare GlobalReg
_ GlobalReg
SpLim = Ordering
GT
compare GlobalReg
Hp GlobalReg
_ = Ordering
LT
compare GlobalReg
_ GlobalReg
Hp = Ordering
GT
compare GlobalReg
HpLim GlobalReg
_ = Ordering
LT
compare GlobalReg
_ GlobalReg
HpLim = Ordering
GT
compare GlobalReg
CCCS GlobalReg
_ = Ordering
LT
compare GlobalReg
_ GlobalReg
CCCS = Ordering
GT
compare GlobalReg
CurrentTSO GlobalReg
_ = Ordering
LT
compare GlobalReg
_ GlobalReg
CurrentTSO = Ordering
GT
compare GlobalReg
CurrentNursery GlobalReg
_ = Ordering
LT
compare GlobalReg
_ GlobalReg
CurrentNursery = Ordering
GT
compare GlobalReg
HpAlloc GlobalReg
_ = Ordering
LT
compare GlobalReg
_ GlobalReg
HpAlloc = Ordering
GT
compare GlobalReg
GCEnter1 GlobalReg
_ = Ordering
LT
compare GlobalReg
_ GlobalReg
GCEnter1 = Ordering
GT
compare GlobalReg
GCFun GlobalReg
_ = Ordering
LT
compare GlobalReg
_ GlobalReg
GCFun = Ordering
GT
compare GlobalReg
BaseReg GlobalReg
_ = Ordering
LT
compare GlobalReg
_ GlobalReg
BaseReg = Ordering
GT
compare GlobalReg
MachSp GlobalReg
_ = Ordering
LT
compare GlobalReg
_ GlobalReg
MachSp = Ordering
GT
compare GlobalReg
UnwindReturnReg GlobalReg
_ = Ordering
LT
compare GlobalReg
_ GlobalReg
UnwindReturnReg = Ordering
GT
compare GlobalReg
EagerBlackholeInfo GlobalReg
_ = Ordering
LT
compare GlobalReg
_ GlobalReg
EagerBlackholeInfo = Ordering
GT
instance Outputable GlobalReg where
ppr :: GlobalReg -> SDoc
ppr GlobalReg
e = forall doc. IsLine doc => GlobalReg -> doc
pprGlobalReg GlobalReg
e
instance OutputableP env GlobalReg where
pdoc :: env -> GlobalReg -> SDoc
pdoc env
_ = forall {a}. Outputable a => a -> SDoc
ppr
pprGlobalReg :: IsLine doc => GlobalReg -> doc
pprGlobalReg :: forall doc. IsLine doc => GlobalReg -> doc
pprGlobalReg GlobalReg
gr
= case GlobalReg
gr of
VanillaReg Int
n VGcPtr
_ -> forall doc. IsLine doc => Char -> doc
char Char
'R' forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => Int -> doc
int Int
n
FloatReg Int
n -> forall doc. IsLine doc => Char -> doc
char Char
'F' forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => Int -> doc
int Int
n
DoubleReg Int
n -> forall doc. IsLine doc => Char -> doc
char Char
'D' forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => Int -> doc
int Int
n
LongReg Int
n -> forall doc. IsLine doc => Char -> doc
char Char
'L' forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => Int -> doc
int Int
n
XmmReg Int
n -> forall doc. IsLine doc => String -> doc
text String
"XMM" forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => Int -> doc
int Int
n
YmmReg Int
n -> forall doc. IsLine doc => String -> doc
text String
"YMM" forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => Int -> doc
int Int
n
ZmmReg Int
n -> forall doc. IsLine doc => String -> doc
text String
"ZMM" forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => Int -> doc
int Int
n
GlobalReg
Sp -> forall doc. IsLine doc => String -> doc
text String
"Sp"
GlobalReg
SpLim -> forall doc. IsLine doc => String -> doc
text String
"SpLim"
GlobalReg
Hp -> forall doc. IsLine doc => String -> doc
text String
"Hp"
GlobalReg
HpLim -> forall doc. IsLine doc => String -> doc
text String
"HpLim"
GlobalReg
MachSp -> forall doc. IsLine doc => String -> doc
text String
"MachSp"
GlobalReg
UnwindReturnReg-> forall doc. IsLine doc => String -> doc
text String
"UnwindReturnReg"
GlobalReg
CCCS -> forall doc. IsLine doc => String -> doc
text String
"CCCS"
GlobalReg
CurrentTSO -> forall doc. IsLine doc => String -> doc
text String
"CurrentTSO"
GlobalReg
CurrentNursery -> forall doc. IsLine doc => String -> doc
text String
"CurrentNursery"
GlobalReg
HpAlloc -> forall doc. IsLine doc => String -> doc
text String
"HpAlloc"
GlobalReg
EagerBlackholeInfo -> forall doc. IsLine doc => String -> doc
text String
"stg_EAGER_BLACKHOLE_info"
GlobalReg
GCEnter1 -> forall doc. IsLine doc => String -> doc
text String
"stg_gc_enter_1"
GlobalReg
GCFun -> forall doc. IsLine doc => String -> doc
text String
"stg_gc_fun"
GlobalReg
BaseReg -> forall doc. IsLine doc => String -> doc
text String
"BaseReg"
GlobalReg
PicBaseReg -> forall doc. IsLine doc => String -> doc
text String
"PicBaseReg"
{-# SPECIALIZE pprGlobalReg :: GlobalReg -> SDoc #-}
{-# SPECIALIZE pprGlobalReg :: GlobalReg -> HLine #-}
baseReg, spReg, hpReg, spLimReg, hpLimReg, nodeReg,
currentTSOReg, currentNurseryReg, hpAllocReg, cccsReg :: CmmReg
baseReg :: CmmReg
baseReg = GlobalReg -> CmmReg
CmmGlobal GlobalReg
BaseReg
spReg :: CmmReg
spReg = GlobalReg -> CmmReg
CmmGlobal GlobalReg
Sp
hpReg :: CmmReg
hpReg = GlobalReg -> CmmReg
CmmGlobal GlobalReg
Hp
hpLimReg :: CmmReg
hpLimReg = GlobalReg -> CmmReg
CmmGlobal GlobalReg
HpLim
spLimReg :: CmmReg
spLimReg = GlobalReg -> CmmReg
CmmGlobal GlobalReg
SpLim
nodeReg :: CmmReg
nodeReg = GlobalReg -> CmmReg
CmmGlobal GlobalReg
node
currentTSOReg :: CmmReg
currentTSOReg = GlobalReg -> CmmReg
CmmGlobal GlobalReg
CurrentTSO
currentNurseryReg :: CmmReg
currentNurseryReg = GlobalReg -> CmmReg
CmmGlobal GlobalReg
CurrentNursery
hpAllocReg :: CmmReg
hpAllocReg = GlobalReg -> CmmReg
CmmGlobal GlobalReg
HpAlloc
cccsReg :: CmmReg
cccsReg = GlobalReg -> CmmReg
CmmGlobal GlobalReg
CCCS
node :: GlobalReg
node :: GlobalReg
node = Int -> VGcPtr -> GlobalReg
VanillaReg Int
1 VGcPtr
VGcPtr
globalRegType :: Platform -> GlobalReg -> CmmType
globalRegType :: Platform -> GlobalReg -> CmmType
globalRegType Platform
platform = \case
(VanillaReg Int
_ VGcPtr
VGcPtr) -> Platform -> CmmType
gcWord Platform
platform
(VanillaReg Int
_ VGcPtr
VNonGcPtr) -> Platform -> CmmType
bWord Platform
platform
(FloatReg Int
_) -> Width -> CmmType
cmmFloat Width
W32
(DoubleReg Int
_) -> Width -> CmmType
cmmFloat Width
W64
(LongReg Int
_) -> Width -> CmmType
cmmBits Width
W64
(XmmReg Int
_) -> Int -> CmmType -> CmmType
cmmVec Int
4 (Width -> CmmType
cmmBits Width
W32)
(YmmReg Int
_) -> Int -> CmmType -> CmmType
cmmVec Int
8 (Width -> CmmType
cmmBits Width
W32)
(ZmmReg Int
_) -> Int -> CmmType -> CmmType
cmmVec Int
16 (Width -> CmmType
cmmBits Width
W32)
GlobalReg
Hp -> Platform -> CmmType
gcWord Platform
platform
GlobalReg
_ -> Platform -> CmmType
bWord Platform
platform
isArgReg :: GlobalReg -> Bool
isArgReg :: GlobalReg -> Bool
isArgReg (VanillaReg {}) = Bool
True
isArgReg (FloatReg {}) = Bool
True
isArgReg (DoubleReg {}) = Bool
True
isArgReg (LongReg {}) = Bool
True
isArgReg (XmmReg {}) = Bool
True
isArgReg (YmmReg {}) = Bool
True
isArgReg (ZmmReg {}) = Bool
True
isArgReg GlobalReg
_ = Bool
False