{-# LANGUAGE CPP #-}
module GHC.CmmToAsm.Reg.Graph.TrivColorable (
trivColorable,
)
where
#include "HsVersions.h"
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 (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 forall a. Ord a => a -> a -> Bool
>= Int
maxCount = Int
count
acc Int
count (reg
r:[reg]
rs) = Int -> [reg] -> Int
acc (Int
count 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
Arch
ArchSPARC -> Int
14
Arch
ArchSPARC64 -> forall a. String -> a
panic String
"trivColorable ArchSPARC64"
ArchPPC_64 PPC_64ABI
_ -> Int
15
ArchARM ArmISA
_ [ArmISAExt]
_ ArmABI
_ -> forall a. String -> a
panic String
"trivColorable ArchARM"
Arch
ArchAArch64 -> Int
18
Arch
ArchAlpha -> forall a. String -> a
panic String
"trivColorable ArchAlpha"
Arch
ArchMipseb -> forall a. String -> a
panic String
"trivColorable ArchMipseb"
Arch
ArchMipsel -> forall a. String -> a
panic String
"trivColorable ArchMipsel"
Arch
ArchS390X -> forall a. String -> a
panic String
"trivColorable ArchS390X"
Arch
ArchRISCV64 -> forall a. String -> a
panic String
"trivColorable ArchRISCV64"
Arch
ArchJavaScript-> forall a. String -> a
panic String
"trivColorable ArchJavaScript"
Arch
ArchUnknown -> forall a. String -> a
panic String
"trivColorable ArchUnknown")
, Int
count2 <- 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 <- 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 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
Arch
ArchSPARC -> Int
22
Arch
ArchSPARC64 -> forall a. String -> a
panic String
"trivColorable ArchSPARC64"
ArchPPC_64 PPC_64ABI
_ -> Int
0
ArchARM ArmISA
_ [ArmISAExt]
_ ArmABI
_ -> forall a. String -> a
panic String
"trivColorable ArchARM"
Arch
ArchAArch64 -> Int
0
Arch
ArchAlpha -> forall a. String -> a
panic String
"trivColorable ArchAlpha"
Arch
ArchMipseb -> forall a. String -> a
panic String
"trivColorable ArchMipseb"
Arch
ArchMipsel -> forall a. String -> a
panic String
"trivColorable ArchMipsel"
Arch
ArchS390X -> forall a. String -> a
panic String
"trivColorable ArchS390X"
Arch
ArchRISCV64 -> forall a. String -> a
panic String
"trivColorable ArchRISCV64"
Arch
ArchJavaScript-> forall a. String -> a
panic String
"trivColorable ArchJavaScript"
Arch
ArchUnknown -> forall a. String -> a
panic String
"trivColorable ArchUnknown")
, Int
count2 <- 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 <- 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 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
Arch
ArchSPARC -> Int
11
Arch
ArchSPARC64 -> forall a. String -> a
panic String
"trivColorable ArchSPARC64"
ArchPPC_64 PPC_64ABI
_ -> Int
20
ArchARM ArmISA
_ [ArmISAExt]
_ ArmABI
_ -> forall a. String -> a
panic String
"trivColorable ArchARM"
Arch
ArchAArch64 -> Int
32
Arch
ArchAlpha -> forall a. String -> a
panic String
"trivColorable ArchAlpha"
Arch
ArchMipseb -> forall a. String -> a
panic String
"trivColorable ArchMipseb"
Arch
ArchMipsel -> forall a. String -> a
panic String
"trivColorable ArchMipsel"
Arch
ArchS390X -> forall a. String -> a
panic String
"trivColorable ArchS390X"
Arch
ArchRISCV64 -> forall a. String -> a
panic String
"trivColorable ArchRISCV64"
Arch
ArchJavaScript-> forall a. String -> a
panic String
"trivColorable ArchJavaScript"
Arch
ArchUnknown -> forall a. String -> a
panic String
"trivColorable ArchUnknown")
, Int
count2 <- 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 <- 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 forall a. Ord a => a -> a -> Bool
< Int
cALLOCATABLE_REGS_DOUBLE