module GHC.CmmToAsm.Reg.Graph.TrivColorable (
trivColorable,
)
where
import GHC.Prelude
import GHC.Platform.Reg.Class
import GHC.Platform.Reg
import GHC.Data.Graph.Base
import GHC.Types.Unique.Set
import GHC.Platform
import GHC.Utils.Panic
accSqueeze
:: Int
-> Int
-> (reg -> Int)
-> UniqSet reg
-> Int
accSqueeze :: forall reg. Int -> Int -> (reg -> Int) -> UniqSet reg -> Int
accSqueeze Int
count Int
maxCount reg -> Int
squeeze UniqSet reg
us = Int -> [reg] -> Int
acc Int
count (UniqSet reg -> [reg]
forall elt. UniqSet elt -> [elt]
nonDetEltsUniqSet UniqSet reg
us)
where acc :: Int -> [reg] -> Int
acc Int
count [] = Int
count
acc Int
count [reg]
_ | Int
count Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
maxCount = Int
count
acc Int
count (reg
r:[reg]
rs) = Int -> [reg] -> Int
acc (Int
count Int -> Int -> Int
forall a. Num a => a -> a -> a
+ reg -> Int
squeeze reg
r) [reg]
rs
trivColorable
:: Platform
-> (RegClass -> VirtualReg -> Int)
-> (RegClass -> RealReg -> Int)
-> Triv VirtualReg RegClass RealReg
trivColorable :: Platform
-> (RegClass -> VirtualReg -> Int)
-> (RegClass -> RealReg -> Int)
-> Triv VirtualReg RegClass RealReg
trivColorable Platform
platform RegClass -> VirtualReg -> Int
virtualRegSqueeze RegClass -> RealReg -> Int
realRegSqueeze RegClass
RcInteger UniqSet VirtualReg
conflicts UniqSet RealReg
exclusions
| let cALLOCATABLE_REGS_INTEGER :: Int
cALLOCATABLE_REGS_INTEGER
= (case Platform -> Arch
platformArch Platform
platform of
Arch
ArchX86 -> Int
3
Arch
ArchX86_64 -> Int
5
Arch
ArchPPC -> Int
16
ArchPPC_64 PPC_64ABI
_ -> Int
15
ArchARM ArmISA
_ [ArmISAExt]
_ ArmABI
_ -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchARM"
Arch
ArchAArch64 -> Int
18
Arch
ArchAlpha -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchAlpha"
Arch
ArchMipseb -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchMipseb"
Arch
ArchMipsel -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchMipsel"
Arch
ArchS390X -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchS390X"
Arch
ArchRISCV64 -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchRISCV64"
Arch
ArchLoongArch64->String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchLoongArch64"
Arch
ArchJavaScript-> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchJavaScript"
Arch
ArchWasm32 -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchWasm32"
Arch
ArchUnknown -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchUnknown")
, Int
count2 <- Int -> Int -> (VirtualReg -> Int) -> UniqSet VirtualReg -> Int
forall reg. Int -> Int -> (reg -> Int) -> UniqSet reg -> Int
accSqueeze Int
0 Int
cALLOCATABLE_REGS_INTEGER
(RegClass -> VirtualReg -> Int
virtualRegSqueeze RegClass
RcInteger)
UniqSet VirtualReg
conflicts
, Int
count3 <- Int -> Int -> (RealReg -> Int) -> UniqSet RealReg -> Int
forall reg. Int -> Int -> (reg -> Int) -> UniqSet reg -> Int
accSqueeze Int
count2 Int
cALLOCATABLE_REGS_INTEGER
(RegClass -> RealReg -> Int
realRegSqueeze RegClass
RcInteger)
UniqSet RealReg
exclusions
= Int
count3 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
cALLOCATABLE_REGS_INTEGER
trivColorable Platform
platform RegClass -> VirtualReg -> Int
virtualRegSqueeze RegClass -> RealReg -> Int
realRegSqueeze RegClass
RcFloat UniqSet VirtualReg
conflicts UniqSet RealReg
exclusions
| let cALLOCATABLE_REGS_FLOAT :: Int
cALLOCATABLE_REGS_FLOAT
= (case Platform -> Arch
platformArch Platform
platform of
Arch
ArchX86 -> Int
0
Arch
ArchX86_64 -> Int
0
Arch
ArchPPC -> Int
0
ArchPPC_64 PPC_64ABI
_ -> Int
0
ArchARM ArmISA
_ [ArmISAExt]
_ ArmABI
_ -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchARM"
Arch
ArchAArch64 -> Int
0
Arch
ArchAlpha -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchAlpha"
Arch
ArchMipseb -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchMipseb"
Arch
ArchMipsel -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchMipsel"
Arch
ArchS390X -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchS390X"
Arch
ArchRISCV64 -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchRISCV64"
Arch
ArchLoongArch64->String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchLoongArch64"
Arch
ArchJavaScript-> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchJavaScript"
Arch
ArchWasm32 -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchWasm32"
Arch
ArchUnknown -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchUnknown")
, Int
count2 <- Int -> Int -> (VirtualReg -> Int) -> UniqSet VirtualReg -> Int
forall reg. Int -> Int -> (reg -> Int) -> UniqSet reg -> Int
accSqueeze Int
0 Int
cALLOCATABLE_REGS_FLOAT
(RegClass -> VirtualReg -> Int
virtualRegSqueeze RegClass
RcFloat)
UniqSet VirtualReg
conflicts
, Int
count3 <- Int -> Int -> (RealReg -> Int) -> UniqSet RealReg -> Int
forall reg. Int -> Int -> (reg -> Int) -> UniqSet reg -> Int
accSqueeze Int
count2 Int
cALLOCATABLE_REGS_FLOAT
(RegClass -> RealReg -> Int
realRegSqueeze RegClass
RcFloat)
UniqSet RealReg
exclusions
= Int
count3 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
cALLOCATABLE_REGS_FLOAT
trivColorable Platform
platform RegClass -> VirtualReg -> Int
virtualRegSqueeze RegClass -> RealReg -> Int
realRegSqueeze RegClass
RcDouble UniqSet VirtualReg
conflicts UniqSet RealReg
exclusions
| let cALLOCATABLE_REGS_DOUBLE :: Int
cALLOCATABLE_REGS_DOUBLE
= (case Platform -> Arch
platformArch Platform
platform of
Arch
ArchX86 -> Int
8
Arch
ArchX86_64 -> Int
10
Arch
ArchPPC -> Int
26
ArchPPC_64 PPC_64ABI
_ -> Int
20
ArchARM ArmISA
_ [ArmISAExt]
_ ArmABI
_ -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchARM"
Arch
ArchAArch64 -> Int
32
Arch
ArchAlpha -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchAlpha"
Arch
ArchMipseb -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchMipseb"
Arch
ArchMipsel -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchMipsel"
Arch
ArchS390X -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchS390X"
Arch
ArchRISCV64 -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchRISCV64"
Arch
ArchLoongArch64->String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchLoongArch64"
Arch
ArchJavaScript-> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchJavaScript"
Arch
ArchWasm32 -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchWasm32"
Arch
ArchUnknown -> String -> Int
forall a. HasCallStack => String -> a
panic String
"trivColorable ArchUnknown")
, Int
count2 <- Int -> Int -> (VirtualReg -> Int) -> UniqSet VirtualReg -> Int
forall reg. Int -> Int -> (reg -> Int) -> UniqSet reg -> Int
accSqueeze Int
0 Int
cALLOCATABLE_REGS_DOUBLE
(RegClass -> VirtualReg -> Int
virtualRegSqueeze RegClass
RcDouble)
UniqSet VirtualReg
conflicts
, Int
count3 <- Int -> Int -> (RealReg -> Int) -> UniqSet RealReg -> Int
forall reg. Int -> Int -> (reg -> Int) -> UniqSet reg -> Int
accSqueeze Int
count2 Int
cALLOCATABLE_REGS_DOUBLE
(RegClass -> RealReg -> Int
realRegSqueeze RegClass
RcDouble)
UniqSet RealReg
exclusions
= Int
count3 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
cALLOCATABLE_REGS_DOUBLE