{-# LANGUAGE CPP #-}
module RegAlloc.Graph.TrivColorable (
trivColorable,
)
where
#include "GhclibHsVersions.h"
import GhcPrelude
import RegClass
import Reg
import GraphBase
import UniqSet
import GHC.Platform
import Panic
accSqueeze
:: Int
-> Int
-> (reg -> Int)
-> UniqSet reg
-> Int
accSqueeze :: 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
Arch
ArchSPARC -> Int
14
Arch
ArchSPARC64 -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchSPARC64"
ArchPPC_64 PPC_64ABI
_ -> Int
15
ArchARM ArmISA
_ [ArmISAExt]
_ ArmABI
_ -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchARM"
Arch
ArchAArch64 -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchAArch64"
Arch
ArchAlpha -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchAlpha"
Arch
ArchMipseb -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchMipseb"
Arch
ArchMipsel -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchMipsel"
Arch
ArchS390X -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchS390X"
Arch
ArchJavaScript-> String -> Int
forall a. String -> a
panic String
"trivColorable ArchJavaScript"
Arch
ArchUnknown -> String -> Int
forall a. 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
Arch
ArchSPARC -> Int
22
Arch
ArchSPARC64 -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchSPARC64"
ArchPPC_64 PPC_64ABI
_ -> Int
0
ArchARM ArmISA
_ [ArmISAExt]
_ ArmABI
_ -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchARM"
Arch
ArchAArch64 -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchAArch64"
Arch
ArchAlpha -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchAlpha"
Arch
ArchMipseb -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchMipseb"
Arch
ArchMipsel -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchMipsel"
Arch
ArchS390X -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchS390X"
Arch
ArchJavaScript-> String -> Int
forall a. String -> a
panic String
"trivColorable ArchJavaScript"
Arch
ArchUnknown -> String -> Int
forall a. 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
Arch
ArchSPARC -> Int
11
Arch
ArchSPARC64 -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchSPARC64"
ArchPPC_64 PPC_64ABI
_ -> Int
20
ArchARM ArmISA
_ [ArmISAExt]
_ ArmABI
_ -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchARM"
Arch
ArchAArch64 -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchAArch64"
Arch
ArchAlpha -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchAlpha"
Arch
ArchMipseb -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchMipseb"
Arch
ArchMipsel -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchMipsel"
Arch
ArchS390X -> String -> Int
forall a. String -> a
panic String
"trivColorable ArchS390X"
Arch
ArchJavaScript-> String -> Int
forall a. String -> a
panic String
"trivColorable ArchJavaScript"
Arch
ArchUnknown -> String -> Int
forall a. 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