Revert "Remove ArchUnknown"
[ghc.git] / compiler / nativeGen / RegAlloc / Linear / FreeRegs.hs
1
2 module RegAlloc.Linear.FreeRegs (
3 FR(..),
4 maxSpillSlots
5 )
6
7 #include "HsVersions.h"
8
9 where
10
11 import Reg
12 import RegClass
13
14 import Panic
15 import Platform
16
17 -- -----------------------------------------------------------------------------
18 -- The free register set
19 -- This needs to be *efficient*
20 -- Here's an inefficient 'executable specification' of the FreeRegs data type:
21 --
22 -- type FreeRegs = [RegNo]
23 -- noFreeRegs = 0
24 -- releaseReg n f = if n `elem` f then f else (n : f)
25 -- initFreeRegs = allocatableRegs
26 -- getFreeRegs cls f = filter ( (==cls) . regClass . RealReg ) f
27 -- allocateReg f r = filter (/= r) f
28
29 import qualified RegAlloc.Linear.PPC.FreeRegs as PPC
30 import qualified RegAlloc.Linear.SPARC.FreeRegs as SPARC
31 import qualified RegAlloc.Linear.X86.FreeRegs as X86
32
33 import qualified PPC.Instr
34 import qualified SPARC.Instr
35 import qualified X86.Instr
36
37 class Show freeRegs => FR freeRegs where
38 frAllocateReg :: RealReg -> freeRegs -> freeRegs
39 frGetFreeRegs :: RegClass -> freeRegs -> [RealReg]
40 frInitFreeRegs :: freeRegs
41 frReleaseReg :: RealReg -> freeRegs -> freeRegs
42
43 instance FR X86.FreeRegs where
44 frAllocateReg = X86.allocateReg
45 frGetFreeRegs = X86.getFreeRegs
46 frInitFreeRegs = X86.initFreeRegs
47 frReleaseReg = X86.releaseReg
48
49 instance FR PPC.FreeRegs where
50 frAllocateReg = PPC.allocateReg
51 frGetFreeRegs = PPC.getFreeRegs
52 frInitFreeRegs = PPC.initFreeRegs
53 frReleaseReg = PPC.releaseReg
54
55 instance FR SPARC.FreeRegs where
56 frAllocateReg = SPARC.allocateReg
57 frGetFreeRegs = SPARC.getFreeRegs
58 frInitFreeRegs = SPARC.initFreeRegs
59 frReleaseReg = SPARC.releaseReg
60
61 maxSpillSlots :: Platform -> Int
62 maxSpillSlots platform
63 = case platformArch platform of
64 ArchX86 -> X86.Instr.maxSpillSlots
65 ArchX86_64 -> X86.Instr.maxSpillSlots
66 ArchPPC -> PPC.Instr.maxSpillSlots
67 ArchSPARC -> SPARC.Instr.maxSpillSlots
68 ArchARM _ _ -> panic "maxSpillSlots ArchARM"
69 ArchPPC_64 -> panic "maxSpillSlots ArchPPC_64"
70 ArchUnknown -> panic "maxSpillSlots ArchUnknown"
71