{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}
module GHC.Cmm.Expr
( CmmExpr(..), cmmExprType, cmmExprWidth, cmmExprAlignment, maybeInvertCmmExpr
, CmmReg(..), cmmRegType, cmmRegWidth
, CmmLit(..), cmmLitType
, AlignmentSpec(..)
, LocalReg(..), localRegType
, GlobalReg(..), isArgReg, globalRegType
, spReg, hpReg, spLimReg, hpLimReg, nodeReg
, currentTSOReg, currentNurseryReg, hpAllocReg, cccsReg
, node, baseReg
, VGcPtr(..)
, DefinerOfRegs, UserOfRegs
, foldRegsDefd, foldRegsUsed
, foldLocalRegsDefd, foldLocalRegsUsed
, RegSet, LocalRegSet, GlobalRegSet
, emptyRegSet, elemRegSet, extendRegSet, deleteFromRegSet, mkRegSet
, plusRegSet, minusRegSet, timesRegSet, sizeRegSet, nullRegSet
, regSetToList
, Area(..)
, module GHC.Cmm.MachOp
, module GHC.Cmm.Type
)
where
import GHC.Prelude
import GHC.Platform
import GHC.Cmm.BlockId
import GHC.Cmm.CLabel
import GHC.Cmm.MachOp
import GHC.Cmm.Type
import GHC.Utils.Panic (panic)
import GHC.Utils.Outputable
import GHC.Types.Unique
import Data.Set (Set)
import qualified Data.Set as Set
import GHC.Types.Basic (Alignment, mkAlignment, alignmentOf)
data CmmExpr
= CmmLit !CmmLit
| CmmLoad !CmmExpr !CmmType !AlignmentSpec
| CmmReg !CmmReg
| CmmMachOp MachOp [CmmExpr]
| CmmStackSlot Area {-# UNPACK #-} !Int
| CmmRegOff !CmmReg !Int
deriving Int -> CmmExpr -> ShowS
[CmmExpr] -> ShowS
CmmExpr -> String
(Int -> CmmExpr -> ShowS)
-> (CmmExpr -> String) -> ([CmmExpr] -> ShowS) -> Show CmmExpr
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CmmExpr -> ShowS
showsPrec :: Int -> CmmExpr -> ShowS
$cshow :: CmmExpr -> String
show :: CmmExpr -> String
$cshowList :: [CmmExpr] -> ShowS
showList :: [CmmExpr] -> ShowS
Show
instance Eq CmmExpr where
CmmLit CmmLit
l1 == :: CmmExpr -> CmmExpr -> Bool
== CmmLit CmmLit
l2 = CmmLit
l1CmmLit -> CmmLit -> Bool
forall a. Eq a => a -> a -> Bool
==CmmLit
l2
CmmLoad CmmExpr
e1 CmmType
_ AlignmentSpec
_ == CmmLoad CmmExpr
e2 CmmType
_ AlignmentSpec
_ = CmmExpr
e1CmmExpr -> CmmExpr -> Bool
forall a. Eq a => a -> a -> Bool
==CmmExpr
e2
CmmReg CmmReg
r1 == CmmReg CmmReg
r2 = CmmReg
r1CmmReg -> CmmReg -> Bool
forall a. Eq a => a -> a -> Bool
==CmmReg
r2
CmmRegOff CmmReg
r1 Int
i1 == CmmRegOff CmmReg
r2 Int
i2 = CmmReg
r1CmmReg -> CmmReg -> Bool
forall a. Eq a => a -> a -> Bool
==CmmReg
r2 Bool -> Bool -> Bool
&& Int
i1Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
==Int
i2
CmmMachOp MachOp
op1 [CmmExpr]
es1 == CmmMachOp MachOp
op2 [CmmExpr]
es2 = MachOp
op1MachOp -> MachOp -> Bool
forall a. Eq a => a -> a -> Bool
==MachOp
op2 Bool -> Bool -> Bool
&& [CmmExpr]
es1[CmmExpr] -> [CmmExpr] -> Bool
forall a. Eq a => a -> a -> Bool
==[CmmExpr]
es2
CmmStackSlot Area
a1 Int
i1 == CmmStackSlot Area
a2 Int
i2 = Area
a1Area -> Area -> Bool
forall a. Eq a => a -> a -> Bool
==Area
a2 Bool -> Bool -> Bool
&& Int
i1Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
==Int
i2
CmmExpr
_e1 == CmmExpr
_e2 = Bool
False
data AlignmentSpec = NaturallyAligned | Unaligned
deriving (AlignmentSpec -> AlignmentSpec -> Bool
(AlignmentSpec -> AlignmentSpec -> Bool)
-> (AlignmentSpec -> AlignmentSpec -> Bool) -> Eq AlignmentSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AlignmentSpec -> AlignmentSpec -> Bool
== :: AlignmentSpec -> AlignmentSpec -> Bool
$c/= :: AlignmentSpec -> AlignmentSpec -> Bool
/= :: AlignmentSpec -> AlignmentSpec -> Bool
Eq, Eq AlignmentSpec
Eq AlignmentSpec
-> (AlignmentSpec -> AlignmentSpec -> Ordering)
-> (AlignmentSpec -> AlignmentSpec -> Bool)
-> (AlignmentSpec -> AlignmentSpec -> Bool)
-> (AlignmentSpec -> AlignmentSpec -> Bool)
-> (AlignmentSpec -> AlignmentSpec -> Bool)
-> (AlignmentSpec -> AlignmentSpec -> AlignmentSpec)
-> (AlignmentSpec -> AlignmentSpec -> AlignmentSpec)
-> Ord AlignmentSpec
AlignmentSpec -> AlignmentSpec -> Bool
AlignmentSpec -> AlignmentSpec -> Ordering
AlignmentSpec -> AlignmentSpec -> AlignmentSpec
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 :: AlignmentSpec -> AlignmentSpec -> Ordering
compare :: AlignmentSpec -> AlignmentSpec -> Ordering
$c< :: AlignmentSpec -> AlignmentSpec -> Bool
< :: AlignmentSpec -> AlignmentSpec -> Bool
$c<= :: AlignmentSpec -> AlignmentSpec -> Bool
<= :: AlignmentSpec -> AlignmentSpec -> Bool
$c> :: AlignmentSpec -> AlignmentSpec -> Bool
> :: AlignmentSpec -> AlignmentSpec -> Bool
$c>= :: AlignmentSpec -> AlignmentSpec -> Bool
>= :: AlignmentSpec -> AlignmentSpec -> Bool
$cmax :: AlignmentSpec -> AlignmentSpec -> AlignmentSpec
max :: AlignmentSpec -> AlignmentSpec -> AlignmentSpec
$cmin :: AlignmentSpec -> AlignmentSpec -> AlignmentSpec
min :: AlignmentSpec -> AlignmentSpec -> AlignmentSpec
Ord, Int -> AlignmentSpec -> ShowS
[AlignmentSpec] -> ShowS
AlignmentSpec -> String
(Int -> AlignmentSpec -> ShowS)
-> (AlignmentSpec -> String)
-> ([AlignmentSpec] -> ShowS)
-> Show AlignmentSpec
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AlignmentSpec -> ShowS
showsPrec :: Int -> AlignmentSpec -> ShowS
$cshow :: AlignmentSpec -> String
show :: AlignmentSpec -> String
$cshowList :: [AlignmentSpec] -> ShowS
showList :: [AlignmentSpec] -> ShowS
Show)
data CmmReg
= CmmLocal {-# UNPACK #-} !LocalReg
| CmmGlobal GlobalReg
deriving( CmmReg -> CmmReg -> Bool
(CmmReg -> CmmReg -> Bool)
-> (CmmReg -> CmmReg -> Bool) -> Eq CmmReg
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CmmReg -> CmmReg -> Bool
== :: CmmReg -> CmmReg -> Bool
$c/= :: CmmReg -> CmmReg -> Bool
/= :: CmmReg -> CmmReg -> Bool
Eq, Eq CmmReg
Eq CmmReg
-> (CmmReg -> CmmReg -> Ordering)
-> (CmmReg -> CmmReg -> Bool)
-> (CmmReg -> CmmReg -> Bool)
-> (CmmReg -> CmmReg -> Bool)
-> (CmmReg -> CmmReg -> Bool)
-> (CmmReg -> CmmReg -> CmmReg)
-> (CmmReg -> CmmReg -> CmmReg)
-> Ord 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
$ccompare :: CmmReg -> CmmReg -> Ordering
compare :: CmmReg -> CmmReg -> Ordering
$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
>= :: CmmReg -> CmmReg -> Bool
$cmax :: CmmReg -> CmmReg -> CmmReg
max :: CmmReg -> CmmReg -> CmmReg
$cmin :: CmmReg -> CmmReg -> CmmReg
min :: CmmReg -> CmmReg -> CmmReg
Ord, Int -> CmmReg -> ShowS
[CmmReg] -> ShowS
CmmReg -> String
(Int -> CmmReg -> ShowS)
-> (CmmReg -> String) -> ([CmmReg] -> ShowS) -> Show CmmReg
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CmmReg -> ShowS
showsPrec :: Int -> CmmReg -> ShowS
$cshow :: CmmReg -> String
show :: CmmReg -> String
$cshowList :: [CmmReg] -> ShowS
showList :: [CmmReg] -> ShowS
Show )
data Area
= Old
| Young {-# UNPACK #-} !BlockId
deriving (Area -> Area -> Bool
(Area -> Area -> Bool) -> (Area -> Area -> Bool) -> Eq Area
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Area -> Area -> Bool
== :: Area -> Area -> Bool
$c/= :: Area -> Area -> Bool
/= :: Area -> Area -> Bool
Eq, Eq Area
Eq Area
-> (Area -> Area -> Ordering)
-> (Area -> Area -> Bool)
-> (Area -> Area -> Bool)
-> (Area -> Area -> Bool)
-> (Area -> Area -> Bool)
-> (Area -> Area -> Area)
-> (Area -> Area -> Area)
-> Ord Area
Area -> Area -> Bool
Area -> Area -> Ordering
Area -> Area -> Area
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 :: Area -> Area -> Ordering
compare :: Area -> Area -> Ordering
$c< :: Area -> Area -> Bool
< :: Area -> Area -> Bool
$c<= :: Area -> Area -> Bool
<= :: Area -> Area -> Bool
$c> :: Area -> Area -> Bool
> :: Area -> Area -> Bool
$c>= :: Area -> Area -> Bool
>= :: Area -> Area -> Bool
$cmax :: Area -> Area -> Area
max :: Area -> Area -> Area
$cmin :: Area -> Area -> Area
min :: Area -> Area -> Area
Ord, Int -> Area -> ShowS
[Area] -> ShowS
Area -> String
(Int -> Area -> ShowS)
-> (Area -> String) -> ([Area] -> ShowS) -> Show Area
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Area -> ShowS
showsPrec :: Int -> Area -> ShowS
$cshow :: Area -> String
show :: Area -> String
$cshowList :: [Area] -> ShowS
showList :: [Area] -> ShowS
Show)
data CmmLit
= CmmInt !Integer !Width
| CmmFloat Rational !Width
| CmmVec [CmmLit]
| CmmLabel CLabel
| CmmLabelOff CLabel !Int
| CmmLabelDiffOff CLabel CLabel !Int !Width
| CmmBlock {-# UNPACK #-} !BlockId
| CmmHighStackMark
deriving (CmmLit -> CmmLit -> Bool
(CmmLit -> CmmLit -> Bool)
-> (CmmLit -> CmmLit -> Bool) -> Eq CmmLit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CmmLit -> CmmLit -> Bool
== :: CmmLit -> CmmLit -> Bool
$c/= :: CmmLit -> CmmLit -> Bool
/= :: CmmLit -> CmmLit -> Bool
Eq, Int -> CmmLit -> ShowS
[CmmLit] -> ShowS
CmmLit -> String
(Int -> CmmLit -> ShowS)
-> (CmmLit -> String) -> ([CmmLit] -> ShowS) -> Show CmmLit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CmmLit -> ShowS
showsPrec :: Int -> CmmLit -> ShowS
$cshow :: CmmLit -> String
show :: CmmLit -> String
$cshowList :: [CmmLit] -> ShowS
showList :: [CmmLit] -> ShowS
Show)
instance Outputable CmmLit where
ppr :: CmmLit -> SDoc
ppr (CmmInt Integer
n Width
w) = String -> SDoc
text String
"CmmInt" SDoc -> SDoc -> SDoc
<+> Integer -> SDoc
forall a. Outputable a => a -> SDoc
ppr Integer
n SDoc -> SDoc -> SDoc
<+> Width -> SDoc
forall a. Outputable a => a -> SDoc
ppr Width
w
ppr (CmmFloat Rational
n Width
w) = String -> SDoc
text String
"CmmFloat" SDoc -> SDoc -> SDoc
<+> String -> SDoc
text (Rational -> String
forall a. Show a => a -> String
show Rational
n) SDoc -> SDoc -> SDoc
<+> Width -> SDoc
forall a. Outputable a => a -> SDoc
ppr Width
w
ppr (CmmVec [CmmLit]
xs) = String -> SDoc
text String
"CmmVec" SDoc -> SDoc -> SDoc
<+> [CmmLit] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [CmmLit]
xs
ppr (CmmLabel CLabel
_) = String -> SDoc
text String
"CmmLabel"
ppr (CmmLabelOff CLabel
_ Int
_) = String -> SDoc
text String
"CmmLabelOff"
ppr (CmmLabelDiffOff CLabel
_ CLabel
_ Int
_ Width
_) = String -> SDoc
text String
"CmmLabelDiffOff"
ppr (CmmBlock BlockId
blk) = String -> SDoc
text String
"CmmBlock" SDoc -> SDoc -> SDoc
<+> BlockId -> SDoc
forall a. Outputable a => a -> SDoc
ppr BlockId
blk
ppr CmmLit
CmmHighStackMark = String -> SDoc
text String
"CmmHighStackMark"
cmmExprType :: Platform -> CmmExpr -> CmmType
cmmExprType :: Platform -> CmmExpr -> CmmType
cmmExprType Platform
platform = \case
(CmmLit CmmLit
lit) -> Platform -> CmmLit -> CmmType
cmmLitType Platform
platform CmmLit
lit
(CmmLoad CmmExpr
_ CmmType
rep AlignmentSpec
_) -> CmmType
rep
(CmmReg CmmReg
reg) -> Platform -> CmmReg -> CmmType
cmmRegType Platform
platform CmmReg
reg
(CmmMachOp MachOp
op [CmmExpr]
args) -> Platform -> MachOp -> [CmmType] -> CmmType
machOpResultType Platform
platform MachOp
op ((CmmExpr -> CmmType) -> [CmmExpr] -> [CmmType]
forall a b. (a -> b) -> [a] -> [b]
map (Platform -> CmmExpr -> CmmType
cmmExprType Platform
platform) [CmmExpr]
args)
(CmmRegOff CmmReg
reg Int
_) -> Platform -> CmmReg -> CmmType
cmmRegType Platform
platform CmmReg
reg
(CmmStackSlot Area
_ Int
_) -> Platform -> CmmType
bWord Platform
platform
cmmLitType :: Platform -> CmmLit -> CmmType
cmmLitType :: Platform -> CmmLit -> CmmType
cmmLitType Platform
platform = \case
(CmmInt Integer
_ Width
width) -> Width -> CmmType
cmmBits Width
width
(CmmFloat Rational
_ Width
width) -> Width -> CmmType
cmmFloat Width
width
(CmmVec []) -> String -> CmmType
forall a. String -> a
panic String
"cmmLitType: CmmVec []"
(CmmVec (CmmLit
l:[CmmLit]
ls)) -> let ty :: CmmType
ty = Platform -> CmmLit -> CmmType
cmmLitType Platform
platform CmmLit
l
in if (CmmType -> Bool) -> [CmmType] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (CmmType -> CmmType -> Bool
`cmmEqType` CmmType
ty) ((CmmLit -> CmmType) -> [CmmLit] -> [CmmType]
forall a b. (a -> b) -> [a] -> [b]
map (Platform -> CmmLit -> CmmType
cmmLitType Platform
platform) [CmmLit]
ls)
then Int -> CmmType -> CmmType
cmmVec (Int
1Int -> Int -> Int
forall a. Num a => a -> a -> a
+[CmmLit] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [CmmLit]
ls) CmmType
ty
else String -> CmmType
forall a. String -> a
panic String
"cmmLitType: CmmVec"
(CmmLabel CLabel
lbl) -> Platform -> CLabel -> CmmType
cmmLabelType Platform
platform CLabel
lbl
(CmmLabelOff CLabel
lbl Int
_) -> Platform -> CLabel -> CmmType
cmmLabelType Platform
platform CLabel
lbl
(CmmLabelDiffOff CLabel
_ CLabel
_ Int
_ Width
width) -> Width -> CmmType
cmmBits Width
width
(CmmBlock BlockId
_) -> Platform -> CmmType
bWord Platform
platform
(CmmLit
CmmHighStackMark) -> Platform -> CmmType
bWord Platform
platform
cmmLabelType :: Platform -> CLabel -> CmmType
cmmLabelType :: Platform -> CLabel -> CmmType
cmmLabelType Platform
platform CLabel
lbl
| CLabel -> Bool
isGcPtrLabel CLabel
lbl = Platform -> CmmType
gcWord Platform
platform
| Bool
otherwise = Platform -> CmmType
bWord Platform
platform
cmmExprWidth :: Platform -> CmmExpr -> Width
cmmExprWidth :: Platform -> CmmExpr -> Width
cmmExprWidth Platform
platform CmmExpr
e = CmmType -> Width
typeWidth (Platform -> CmmExpr -> CmmType
cmmExprType Platform
platform CmmExpr
e)
cmmExprAlignment :: CmmExpr -> Alignment
cmmExprAlignment :: CmmExpr -> Alignment
cmmExprAlignment (CmmLit (CmmInt Integer
intOff Width
_)) = Int -> Alignment
alignmentOf (Integer -> Int
forall a. Num a => Integer -> a
fromInteger Integer
intOff)
cmmExprAlignment CmmExpr
_ = Int -> Alignment
mkAlignment Int
1
maybeInvertCmmExpr :: CmmExpr -> Maybe CmmExpr
maybeInvertCmmExpr :: CmmExpr -> Maybe CmmExpr
maybeInvertCmmExpr (CmmMachOp MachOp
op [CmmExpr]
args) = do MachOp
op' <- MachOp -> Maybe MachOp
maybeInvertComparison MachOp
op
CmmExpr -> Maybe CmmExpr
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (MachOp -> [CmmExpr] -> CmmExpr
CmmMachOp MachOp
op' [CmmExpr]
args)
maybeInvertCmmExpr CmmExpr
_ = Maybe CmmExpr
forall a. Maybe a
Nothing
data LocalReg
= LocalReg {-# UNPACK #-} !Unique !CmmType
deriving Int -> LocalReg -> ShowS
[LocalReg] -> ShowS
LocalReg -> String
(Int -> LocalReg -> ShowS)
-> (LocalReg -> String) -> ([LocalReg] -> ShowS) -> Show LocalReg
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LocalReg -> ShowS
showsPrec :: Int -> LocalReg -> ShowS
$cshow :: LocalReg -> String
show :: LocalReg -> String
$cshowList :: [LocalReg] -> ShowS
showList :: [LocalReg] -> ShowS
Show
instance Eq LocalReg where
(LocalReg Unique
u1 CmmType
_) == :: LocalReg -> LocalReg -> Bool
== (LocalReg Unique
u2 CmmType
_) = Unique
u1 Unique -> Unique -> Bool
forall a. Eq a => a -> a -> Bool
== Unique
u2
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
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 (CmmType -> Width) -> (CmmReg -> CmmType) -> CmmReg -> Width
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Platform -> CmmReg -> CmmType
cmmRegType Platform
platform
localRegType :: LocalReg -> CmmType
localRegType :: LocalReg -> CmmType
localRegType (LocalReg Unique
_ CmmType
rep) = CmmType
rep
type RegSet r = Set r
type LocalRegSet = RegSet LocalReg
type GlobalRegSet = RegSet GlobalReg
emptyRegSet :: RegSet r
nullRegSet :: RegSet r -> Bool
elemRegSet :: Ord r => r -> RegSet r -> Bool
extendRegSet :: Ord r => RegSet r -> r -> RegSet r
deleteFromRegSet :: Ord r => RegSet r -> r -> RegSet r
mkRegSet :: Ord r => [r] -> RegSet r
minusRegSet, plusRegSet, timesRegSet :: Ord r => RegSet r -> RegSet r -> RegSet r
sizeRegSet :: RegSet r -> Int
regSetToList :: RegSet r -> [r]
emptyRegSet :: forall r. RegSet r
emptyRegSet = Set r
forall r. RegSet r
Set.empty
nullRegSet :: forall r. RegSet r -> Bool
nullRegSet = Set r -> Bool
forall r. RegSet r -> Bool
Set.null
elemRegSet :: forall r. Ord r => r -> RegSet r -> Bool
elemRegSet = r -> Set r -> Bool
forall r. Ord r => r -> RegSet r -> Bool
Set.member
extendRegSet :: forall r. Ord r => RegSet r -> r -> RegSet r
extendRegSet = (r -> RegSet r -> RegSet r) -> RegSet r -> r -> RegSet r
forall a b c. (a -> b -> c) -> b -> a -> c
flip r -> RegSet r -> RegSet r
forall a. Ord a => a -> Set a -> Set a
Set.insert
deleteFromRegSet :: forall r. Ord r => RegSet r -> r -> RegSet r
deleteFromRegSet = (r -> RegSet r -> RegSet r) -> RegSet r -> r -> RegSet r
forall a b c. (a -> b -> c) -> b -> a -> c
flip r -> RegSet r -> RegSet r
forall a. Ord a => a -> Set a -> Set a
Set.delete
mkRegSet :: forall r. Ord r => [r] -> RegSet r
mkRegSet = [r] -> Set r
forall r. Ord r => [r] -> RegSet r
Set.fromList
minusRegSet :: forall r. Ord r => RegSet r -> RegSet r -> RegSet r
minusRegSet = Set r -> Set r -> Set r
forall r. Ord r => RegSet r -> RegSet r -> RegSet r
Set.difference
plusRegSet :: forall r. Ord r => RegSet r -> RegSet r -> RegSet r
plusRegSet = Set r -> Set r -> Set r
forall r. Ord r => RegSet r -> RegSet r -> RegSet r
Set.union
timesRegSet :: forall r. Ord r => RegSet r -> RegSet r -> RegSet r
timesRegSet = Set r -> Set r -> Set r
forall r. Ord r => RegSet r -> RegSet r -> RegSet r
Set.intersection
sizeRegSet :: forall r. RegSet r -> Int
sizeRegSet = Set r -> Int
forall r. RegSet r -> Int
Set.size
regSetToList :: forall r. RegSet r -> [r]
regSetToList = Set r -> [r]
forall r. RegSet r -> [r]
Set.toList
class Ord r => UserOfRegs r a where
foldRegsUsed :: Platform -> (b -> r -> b) -> b -> a -> b
foldLocalRegsUsed :: UserOfRegs LocalReg a
=> Platform -> (b -> LocalReg -> b) -> b -> a -> b
foldLocalRegsUsed :: forall a b.
UserOfRegs LocalReg a =>
Platform -> (b -> LocalReg -> b) -> b -> a -> b
foldLocalRegsUsed = Platform -> (b -> LocalReg -> b) -> b -> a -> b
forall b. Platform -> (b -> LocalReg -> b) -> b -> a -> b
forall r a b.
UserOfRegs r a =>
Platform -> (b -> r -> b) -> b -> a -> b
foldRegsUsed
class Ord r => DefinerOfRegs r a where
foldRegsDefd :: Platform -> (b -> r -> b) -> b -> a -> b
foldLocalRegsDefd :: DefinerOfRegs LocalReg a
=> Platform -> (b -> LocalReg -> b) -> b -> a -> b
foldLocalRegsDefd :: forall a b.
DefinerOfRegs LocalReg a =>
Platform -> (b -> LocalReg -> b) -> b -> a -> b
foldLocalRegsDefd = Platform -> (b -> LocalReg -> b) -> b -> a -> b
forall b. Platform -> (b -> LocalReg -> b) -> b -> a -> b
forall r a b.
DefinerOfRegs r a =>
Platform -> (b -> r -> b) -> b -> a -> b
foldRegsDefd
instance UserOfRegs LocalReg CmmReg where
foldRegsUsed :: forall b. Platform -> (b -> LocalReg -> b) -> b -> CmmReg -> b
foldRegsUsed Platform
_ b -> LocalReg -> b
f b
z (CmmLocal LocalReg
reg) = b -> LocalReg -> b
f b
z LocalReg
reg
foldRegsUsed Platform
_ b -> LocalReg -> b
_ b
z (CmmGlobal GlobalReg
_) = b
z
instance DefinerOfRegs LocalReg CmmReg where
foldRegsDefd :: forall b. Platform -> (b -> LocalReg -> b) -> b -> CmmReg -> b
foldRegsDefd Platform
_ b -> LocalReg -> b
f b
z (CmmLocal LocalReg
reg) = b -> LocalReg -> b
f b
z LocalReg
reg
foldRegsDefd Platform
_ b -> LocalReg -> b
_ b
z (CmmGlobal GlobalReg
_) = b
z
instance UserOfRegs GlobalReg CmmReg where
{-# INLINEABLE foldRegsUsed #-}
foldRegsUsed :: forall b. Platform -> (b -> GlobalReg -> b) -> b -> CmmReg -> b
foldRegsUsed Platform
_ b -> GlobalReg -> b
_ b
z (CmmLocal LocalReg
_) = b
z
foldRegsUsed Platform
_ b -> GlobalReg -> b
f b
z (CmmGlobal GlobalReg
reg) = b -> GlobalReg -> b
f b
z GlobalReg
reg
instance DefinerOfRegs GlobalReg CmmReg where
foldRegsDefd :: forall b. Platform -> (b -> GlobalReg -> b) -> b -> CmmReg -> b
foldRegsDefd Platform
_ b -> GlobalReg -> b
_ b
z (CmmLocal LocalReg
_) = b
z
foldRegsDefd Platform
_ b -> GlobalReg -> b
f b
z (CmmGlobal GlobalReg
reg) = b -> GlobalReg -> b
f b
z GlobalReg
reg
instance Ord r => UserOfRegs r r where
foldRegsUsed :: forall b. Platform -> (b -> r -> b) -> b -> r -> b
foldRegsUsed Platform
_ b -> r -> b
f b
z r
r = b -> r -> b
f b
z r
r
instance Ord r => DefinerOfRegs r r where
foldRegsDefd :: forall b. Platform -> (b -> r -> b) -> b -> r -> b
foldRegsDefd Platform
_ b -> r -> b
f b
z r
r = b -> r -> b
f b
z r
r
instance (Ord r, UserOfRegs r CmmReg) => UserOfRegs r CmmExpr where
{-# INLINEABLE foldRegsUsed #-}
foldRegsUsed :: forall b. Platform -> (b -> r -> b) -> b -> CmmExpr -> b
foldRegsUsed Platform
platform b -> r -> b
f !b
z CmmExpr
e = b -> CmmExpr -> b
expr b
z CmmExpr
e
where expr :: b -> CmmExpr -> b
expr b
z (CmmLit CmmLit
_) = b
z
expr b
z (CmmLoad CmmExpr
addr CmmType
_ AlignmentSpec
_) = Platform -> (b -> r -> b) -> b -> CmmExpr -> b
forall b. Platform -> (b -> r -> b) -> b -> CmmExpr -> b
forall r a b.
UserOfRegs r a =>
Platform -> (b -> r -> b) -> b -> a -> b
foldRegsUsed Platform
platform b -> r -> b
f b
z CmmExpr
addr
expr b
z (CmmReg CmmReg
r) = Platform -> (b -> r -> b) -> b -> CmmReg -> b
forall b. Platform -> (b -> r -> b) -> b -> CmmReg -> b
forall r a b.
UserOfRegs r a =>
Platform -> (b -> r -> b) -> b -> a -> b
foldRegsUsed Platform
platform b -> r -> b
f b
z CmmReg
r
expr b
z (CmmMachOp MachOp
_ [CmmExpr]
exprs) = Platform -> (b -> r -> b) -> b -> [CmmExpr] -> b
forall b. Platform -> (b -> r -> b) -> b -> [CmmExpr] -> b
forall r a b.
UserOfRegs r a =>
Platform -> (b -> r -> b) -> b -> a -> b
foldRegsUsed Platform
platform b -> r -> b
f b
z [CmmExpr]
exprs
expr b
z (CmmRegOff CmmReg
r Int
_) = Platform -> (b -> r -> b) -> b -> CmmReg -> b
forall b. Platform -> (b -> r -> b) -> b -> CmmReg -> b
forall r a b.
UserOfRegs r a =>
Platform -> (b -> r -> b) -> b -> a -> b
foldRegsUsed Platform
platform b -> r -> b
f b
z CmmReg
r
expr b
z (CmmStackSlot Area
_ Int
_) = b
z
instance UserOfRegs r a => UserOfRegs r [a] where
foldRegsUsed :: forall b. Platform -> (b -> r -> b) -> b -> [a] -> b
foldRegsUsed Platform
platform b -> r -> b
f b
set [a]
as = (b -> a -> b) -> b -> [a] -> b
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (Platform -> (b -> r -> b) -> b -> a -> b
forall b. Platform -> (b -> r -> b) -> b -> a -> b
forall r a b.
UserOfRegs r a =>
Platform -> (b -> r -> b) -> b -> a -> b
foldRegsUsed Platform
platform b -> r -> b
f) b
set [a]
as
{-# INLINABLE foldRegsUsed #-}
instance DefinerOfRegs r a => DefinerOfRegs r [a] where
foldRegsDefd :: forall b. Platform -> (b -> r -> b) -> b -> [a] -> b
foldRegsDefd Platform
platform b -> r -> b
f b
set [a]
as = (b -> a -> b) -> b -> [a] -> b
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (Platform -> (b -> r -> b) -> b -> a -> b
forall b. Platform -> (b -> r -> b) -> b -> a -> b
forall r a b.
DefinerOfRegs r a =>
Platform -> (b -> r -> b) -> b -> a -> b
foldRegsDefd Platform
platform b -> r -> b
f) b
set [a]
as
{-# INLINABLE foldRegsDefd #-}
data VGcPtr = VGcPtr | VNonGcPtr deriving( VGcPtr -> VGcPtr -> Bool
(VGcPtr -> VGcPtr -> Bool)
-> (VGcPtr -> VGcPtr -> Bool) -> Eq VGcPtr
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VGcPtr -> VGcPtr -> Bool
== :: VGcPtr -> VGcPtr -> Bool
$c/= :: VGcPtr -> VGcPtr -> Bool
/= :: VGcPtr -> VGcPtr -> Bool
Eq, Int -> VGcPtr -> ShowS
[VGcPtr] -> ShowS
VGcPtr -> String
(Int -> VGcPtr -> ShowS)
-> (VGcPtr -> String) -> ([VGcPtr] -> ShowS) -> Show VGcPtr
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VGcPtr -> ShowS
showsPrec :: Int -> VGcPtr -> ShowS
$cshow :: VGcPtr -> String
show :: VGcPtr -> String
$cshowList :: [VGcPtr] -> ShowS
showList :: [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
(Int -> GlobalReg -> ShowS)
-> (GlobalReg -> String)
-> ([GlobalReg] -> ShowS)
-> Show GlobalReg
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GlobalReg -> ShowS
showsPrec :: Int -> GlobalReg -> ShowS
$cshow :: GlobalReg -> String
show :: GlobalReg -> String
$cshowList :: [GlobalReg] -> ShowS
showList :: [GlobalReg] -> ShowS
Show )
instance Eq GlobalReg where
VanillaReg Int
i VGcPtr
_ == :: GlobalReg -> GlobalReg -> Bool
== VanillaReg Int
j VGcPtr
_ = Int
iInt -> Int -> Bool
forall a. Eq a => a -> a -> Bool
==Int
j
FloatReg Int
i == FloatReg Int
j = Int
iInt -> Int -> Bool
forall a. Eq a => a -> a -> Bool
==Int
j
DoubleReg Int
i == DoubleReg Int
j = Int
iInt -> Int -> Bool
forall a. Eq a => a -> a -> Bool
==Int
j
LongReg Int
i == LongReg Int
j = Int
iInt -> Int -> Bool
forall a. Eq a => a -> a -> Bool
==Int
j
XmmReg Int
i == XmmReg Int
j = Int
iInt -> Int -> Bool
forall a. Eq a => a -> a -> Bool
==Int
j
YmmReg Int
i == YmmReg Int
j = Int
iInt -> Int -> Bool
forall a. Eq a => a -> a -> Bool
==Int
j
ZmmReg Int
i == ZmmReg Int
j = Int
iInt -> Int -> Bool
forall 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
_) = Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
i Int
j
compare (FloatReg Int
i) (FloatReg Int
j) = Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
i Int
j
compare (DoubleReg Int
i) (DoubleReg Int
j) = Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
i Int
j
compare (LongReg Int
i) (LongReg Int
j) = Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
i Int
j
compare (XmmReg Int
i) (XmmReg Int
j) = Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
i Int
j
compare (YmmReg Int
i) (YmmReg Int
j) = Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
i Int
j
compare (ZmmReg Int
i) (ZmmReg Int
j) = Int -> Int -> Ordering
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
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