module GHC.CmmToAsm.SPARC.Regs (
showReg,
virtualRegSqueeze,
realRegSqueeze,
classOfRealReg,
allRealRegs,
gReg, iReg, lReg, oReg, fReg,
fp, sp, g0, g1, g2, o0, o1, f0, f1, f6, f8, f22, f26, f27,
allocatableRegs,
argRegs,
allArgRegs,
callClobberedRegs,
mkVirtualReg,
regDotColor
)
where
import GHC.Prelude
import GHC.Platform.SPARC
import GHC.Platform.Reg
import GHC.Platform.Reg.Class
import GHC.CmmToAsm.Format
import GHC.Types.Unique
import GHC.Utils.Outputable
showReg :: RegNo -> String
showReg :: Int -> String
showReg Int
n
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0 Bool -> Bool -> Bool
&& Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
8 = String
"%g" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
n
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
8 Bool -> Bool -> Bool
&& Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
16 = String
"%o" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
8)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
16 Bool -> Bool -> Bool
&& Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
24 = String
"%l" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
16)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
24 Bool -> Bool -> Bool
&& Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
32 = String
"%i" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
24)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
32 Bool -> Bool -> Bool
&& Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
64 = String
"%f" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
32)
| Bool
otherwise = String -> String
forall a. String -> a
panic String
"SPARC.Regs.showReg: unknown sparc register"
classOfRealReg :: RealReg -> RegClass
classOfRealReg :: RealReg -> RegClass
classOfRealReg RealReg
reg
= case RealReg
reg of
RealRegSingle Int
i
| Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
32 -> RegClass
RcInteger
| Bool
otherwise -> RegClass
RcFloat
RealRegPair{} -> RegClass
RcDouble
{-# INLINE virtualRegSqueeze #-}
virtualRegSqueeze :: RegClass -> VirtualReg -> Int
virtualRegSqueeze :: RegClass -> VirtualReg -> Int
virtualRegSqueeze RegClass
cls VirtualReg
vr
= case RegClass
cls of
RegClass
RcInteger
-> case VirtualReg
vr of
VirtualRegI{} -> Int
1
VirtualRegHi{} -> Int
1
VirtualReg
_other -> Int
0
RegClass
RcFloat
-> case VirtualReg
vr of
VirtualRegF{} -> Int
1
VirtualRegD{} -> Int
2
VirtualReg
_other -> Int
0
RegClass
RcDouble
-> case VirtualReg
vr of
VirtualRegF{} -> Int
1
VirtualRegD{} -> Int
1
VirtualReg
_other -> Int
0
{-# INLINE realRegSqueeze #-}
realRegSqueeze :: RegClass -> RealReg -> Int
realRegSqueeze :: RegClass -> RealReg -> Int
realRegSqueeze RegClass
cls RealReg
rr
= case RegClass
cls of
RegClass
RcInteger
-> case RealReg
rr of
RealRegSingle Int
regNo
| Int
regNo Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
32 -> Int
1
| Bool
otherwise -> Int
0
RealRegPair{} -> Int
0
RegClass
RcFloat
-> case RealReg
rr of
RealRegSingle Int
regNo
| Int
regNo Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
32 -> Int
0
| Bool
otherwise -> Int
1
RealRegPair{} -> Int
2
RegClass
RcDouble
-> case RealReg
rr of
RealRegSingle Int
regNo
| Int
regNo Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
32 -> Int
0
| Bool
otherwise -> Int
1
RealRegPair{} -> Int
1
allRealRegs :: [RealReg]
allRealRegs :: [RealReg]
allRealRegs
= [ (Int -> RealReg
RealRegSingle Int
i) | Int
i <- [Int
0..Int
63] ]
[RealReg] -> [RealReg] -> [RealReg]
forall a. [a] -> [a] -> [a]
++ [ (Int -> Int -> RealReg
RealRegPair Int
i (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)) | Int
i <- [Int
32, Int
34 .. Int
62 ] ]
gReg, lReg, iReg, oReg, fReg :: Int -> RegNo
gReg :: Int -> Int
gReg Int
x = Int
x
oReg :: Int -> Int
oReg Int
x = (Int
8 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
x)
lReg :: Int -> Int
lReg Int
x = (Int
16 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
x)
iReg :: Int -> Int
iReg Int
x = (Int
24 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
x)
fReg :: Int -> Int
fReg Int
x = (Int
32 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
x)
g0, g1, g2, fp, sp, o0, o1, f0, f1, f6, f8, f22, f26, f27 :: Reg
f6 :: Reg
f6 = RealReg -> Reg
RegReal (Int -> RealReg
RealRegSingle (Int -> Int
fReg Int
6))
f8 :: Reg
f8 = RealReg -> Reg
RegReal (Int -> RealReg
RealRegSingle (Int -> Int
fReg Int
8))
f22 :: Reg
f22 = RealReg -> Reg
RegReal (Int -> RealReg
RealRegSingle (Int -> Int
fReg Int
22))
f26 :: Reg
f26 = RealReg -> Reg
RegReal (Int -> RealReg
RealRegSingle (Int -> Int
fReg Int
26))
f27 :: Reg
f27 = RealReg -> Reg
RegReal (Int -> RealReg
RealRegSingle (Int -> Int
fReg Int
27))
g0 :: Reg
g0 = RealReg -> Reg
RegReal (Int -> RealReg
RealRegSingle (Int -> Int
gReg Int
0))
g1 :: Reg
g1 = RealReg -> Reg
RegReal (Int -> RealReg
RealRegSingle (Int -> Int
gReg Int
1))
g2 :: Reg
g2 = RealReg -> Reg
RegReal (Int -> RealReg
RealRegSingle (Int -> Int
gReg Int
2))
fp :: Reg
fp = RealReg -> Reg
RegReal (Int -> RealReg
RealRegSingle (Int -> Int
iReg Int
6))
sp :: Reg
sp = RealReg -> Reg
RegReal (Int -> RealReg
RealRegSingle (Int -> Int
oReg Int
6))
o0 :: Reg
o0 = RealReg -> Reg
RegReal (Int -> RealReg
RealRegSingle (Int -> Int
oReg Int
0))
o1 :: Reg
o1 = RealReg -> Reg
RegReal (Int -> RealReg
RealRegSingle (Int -> Int
oReg Int
1))
f0 :: Reg
f0 = RealReg -> Reg
RegReal (Int -> RealReg
RealRegSingle (Int -> Int
fReg Int
0))
f1 :: Reg
f1 = RealReg -> Reg
RegReal (Int -> RealReg
RealRegSingle (Int -> Int
fReg Int
1))
allocatableRegs :: [RealReg]
allocatableRegs :: [RealReg]
allocatableRegs
= let isFree :: RealReg -> Bool
isFree RealReg
rr
= case RealReg
rr of
RealRegSingle Int
r -> Int -> Bool
freeReg Int
r
RealRegPair Int
r1 Int
r2 -> Int -> Bool
freeReg Int
r1 Bool -> Bool -> Bool
&& Int -> Bool
freeReg Int
r2
in (RealReg -> Bool) -> [RealReg] -> [RealReg]
forall a. (a -> Bool) -> [a] -> [a]
filter RealReg -> Bool
isFree [RealReg]
allRealRegs
argRegs :: RegNo -> [Reg]
argRegs :: Int -> [Reg]
argRegs Int
r
= case Int
r of
Int
0 -> []
Int
1 -> (Int -> Reg) -> [Int] -> [Reg]
forall a b. (a -> b) -> [a] -> [b]
map (RealReg -> Reg
RegReal (RealReg -> Reg) -> (Int -> RealReg) -> Int -> Reg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> RealReg
RealRegSingle (Int -> RealReg) -> (Int -> Int) -> Int -> RealReg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int
oReg) [Int
0]
Int
2 -> (Int -> Reg) -> [Int] -> [Reg]
forall a b. (a -> b) -> [a] -> [b]
map (RealReg -> Reg
RegReal (RealReg -> Reg) -> (Int -> RealReg) -> Int -> Reg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> RealReg
RealRegSingle (Int -> RealReg) -> (Int -> Int) -> Int -> RealReg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int
oReg) [Int
0,Int
1]
Int
3 -> (Int -> Reg) -> [Int] -> [Reg]
forall a b. (a -> b) -> [a] -> [b]
map (RealReg -> Reg
RegReal (RealReg -> Reg) -> (Int -> RealReg) -> Int -> Reg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> RealReg
RealRegSingle (Int -> RealReg) -> (Int -> Int) -> Int -> RealReg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int
oReg) [Int
0,Int
1,Int
2]
Int
4 -> (Int -> Reg) -> [Int] -> [Reg]
forall a b. (a -> b) -> [a] -> [b]
map (RealReg -> Reg
RegReal (RealReg -> Reg) -> (Int -> RealReg) -> Int -> Reg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> RealReg
RealRegSingle (Int -> RealReg) -> (Int -> Int) -> Int -> RealReg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int
oReg) [Int
0,Int
1,Int
2,Int
3]
Int
5 -> (Int -> Reg) -> [Int] -> [Reg]
forall a b. (a -> b) -> [a] -> [b]
map (RealReg -> Reg
RegReal (RealReg -> Reg) -> (Int -> RealReg) -> Int -> Reg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> RealReg
RealRegSingle (Int -> RealReg) -> (Int -> Int) -> Int -> RealReg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int
oReg) [Int
0,Int
1,Int
2,Int
3,Int
4]
Int
6 -> (Int -> Reg) -> [Int] -> [Reg]
forall a b. (a -> b) -> [a] -> [b]
map (RealReg -> Reg
RegReal (RealReg -> Reg) -> (Int -> RealReg) -> Int -> Reg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> RealReg
RealRegSingle (Int -> RealReg) -> (Int -> Int) -> Int -> RealReg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int
oReg) [Int
0,Int
1,Int
2,Int
3,Int
4,Int
5]
Int
_ -> String -> [Reg]
forall a. String -> a
panic String
"MachRegs.argRegs(sparc): don't know about >6 arguments!"
allArgRegs :: [Reg]
allArgRegs :: [Reg]
allArgRegs
= (Int -> Reg) -> [Int] -> [Reg]
forall a b. (a -> b) -> [a] -> [b]
map (RealReg -> Reg
RegReal (RealReg -> Reg) -> (Int -> RealReg) -> Int -> Reg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> RealReg
RealRegSingle) [Int -> Int
oReg Int
i | Int
i <- [Int
0..Int
5]]
callClobberedRegs :: [Reg]
callClobberedRegs :: [Reg]
callClobberedRegs
= (Int -> Reg) -> [Int] -> [Reg]
forall a b. (a -> b) -> [a] -> [b]
map (RealReg -> Reg
RegReal (RealReg -> Reg) -> (Int -> RealReg) -> Int -> Reg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> RealReg
RealRegSingle)
( Int -> Int
oReg Int
7 Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:
[Int -> Int
oReg Int
i | Int
i <- [Int
0..Int
5]] [Int] -> [Int] -> [Int]
forall a. [a] -> [a] -> [a]
++
[Int -> Int
gReg Int
i | Int
i <- [Int
1..Int
7]] [Int] -> [Int] -> [Int]
forall a. [a] -> [a] -> [a]
++
[Int -> Int
fReg Int
i | Int
i <- [Int
0..Int
31]] )
mkVirtualReg :: Unique -> Format -> VirtualReg
mkVirtualReg :: Unique -> Format -> VirtualReg
mkVirtualReg Unique
u Format
format
| Bool -> Bool
not (Format -> Bool
isFloatFormat Format
format)
= Unique -> VirtualReg
VirtualRegI Unique
u
| Bool
otherwise
= case Format
format of
Format
FF32 -> Unique -> VirtualReg
VirtualRegF Unique
u
Format
FF64 -> Unique -> VirtualReg
VirtualRegD Unique
u
Format
_ -> String -> VirtualReg
forall a. String -> a
panic String
"mkVReg"
regDotColor :: RealReg -> SDoc
regDotColor :: RealReg -> SDoc
regDotColor RealReg
reg
= case RealReg -> RegClass
classOfRealReg RealReg
reg of
RegClass
RcInteger -> String -> SDoc
text String
"blue"
RegClass
RcFloat -> String -> SDoc
text String
"red"
RegClass
_other -> String -> SDoc
text String
"green"