never executed always true always false
1 module GHC.CmmToAsm.Reg.Linear.FreeRegs (
2 FR(..),
3 maxSpillSlots
4 )
5 where
6
7 import GHC.Prelude
8
9 import GHC.Platform.Reg
10 import GHC.Platform.Reg.Class
11
12 import GHC.CmmToAsm.Config
13 import GHC.Utils.Panic
14 import GHC.Platform
15
16 -- -----------------------------------------------------------------------------
17 -- The free register set
18 -- This needs to be *efficient*
19 -- Here's an inefficient 'executable specification' of the FreeRegs data type:
20 --
21 -- type FreeRegs = [RegNo]
22 -- noFreeRegs = 0
23 -- releaseReg n f = if n `elem` f then f else (n : f)
24 -- initFreeRegs = allocatableRegs
25 -- getFreeRegs cls f = filter ( (==cls) . regClass . RealReg ) f
26 -- allocateReg f r = filter (/= r) f
27
28 import qualified GHC.CmmToAsm.Reg.Linear.PPC as PPC
29 import qualified GHC.CmmToAsm.Reg.Linear.SPARC as SPARC
30 import qualified GHC.CmmToAsm.Reg.Linear.X86 as X86
31 import qualified GHC.CmmToAsm.Reg.Linear.X86_64 as X86_64
32 import qualified GHC.CmmToAsm.Reg.Linear.AArch64 as AArch64
33
34 import qualified GHC.CmmToAsm.PPC.Instr as PPC.Instr
35 import qualified GHC.CmmToAsm.SPARC.Instr as SPARC.Instr
36 import qualified GHC.CmmToAsm.X86.Instr as X86.Instr
37 import qualified GHC.CmmToAsm.AArch64.Instr as AArch64.Instr
38
39 class Show freeRegs => FR freeRegs where
40 frAllocateReg :: Platform -> RealReg -> freeRegs -> freeRegs
41 frGetFreeRegs :: Platform -> RegClass -> freeRegs -> [RealReg]
42 frInitFreeRegs :: Platform -> freeRegs
43 frReleaseReg :: Platform -> RealReg -> freeRegs -> freeRegs
44
45 instance FR X86.FreeRegs where
46 frAllocateReg = \_ -> X86.allocateReg
47 frGetFreeRegs = X86.getFreeRegs
48 frInitFreeRegs = X86.initFreeRegs
49 frReleaseReg = \_ -> X86.releaseReg
50
51 instance FR X86_64.FreeRegs where
52 frAllocateReg = \_ -> X86_64.allocateReg
53 frGetFreeRegs = X86_64.getFreeRegs
54 frInitFreeRegs = X86_64.initFreeRegs
55 frReleaseReg = \_ -> X86_64.releaseReg
56
57 instance FR PPC.FreeRegs where
58 frAllocateReg = \_ -> PPC.allocateReg
59 frGetFreeRegs = \_ -> PPC.getFreeRegs
60 frInitFreeRegs = PPC.initFreeRegs
61 frReleaseReg = \_ -> PPC.releaseReg
62
63 instance FR AArch64.FreeRegs where
64 frAllocateReg = \_ -> AArch64.allocateReg
65 frGetFreeRegs = \_ -> AArch64.getFreeRegs
66 frInitFreeRegs = AArch64.initFreeRegs
67 frReleaseReg = \_ -> AArch64.releaseReg
68
69 instance FR SPARC.FreeRegs where
70 frAllocateReg = SPARC.allocateReg
71 frGetFreeRegs = \_ -> SPARC.getFreeRegs
72 frInitFreeRegs = SPARC.initFreeRegs
73 frReleaseReg = SPARC.releaseReg
74
75 maxSpillSlots :: NCGConfig -> Int
76 maxSpillSlots config = case platformArch (ncgPlatform config) of
77 ArchX86 -> X86.Instr.maxSpillSlots config
78 ArchX86_64 -> X86.Instr.maxSpillSlots config
79 ArchPPC -> PPC.Instr.maxSpillSlots config
80 ArchS390X -> panic "maxSpillSlots ArchS390X"
81 ArchSPARC -> SPARC.Instr.maxSpillSlots config
82 ArchSPARC64 -> panic "maxSpillSlots ArchSPARC64"
83 ArchARM _ _ _ -> panic "maxSpillSlots ArchARM"
84 ArchAArch64 -> AArch64.Instr.maxSpillSlots config
85 ArchPPC_64 _ -> PPC.Instr.maxSpillSlots config
86 ArchAlpha -> panic "maxSpillSlots ArchAlpha"
87 ArchMipseb -> panic "maxSpillSlots ArchMipseb"
88 ArchMipsel -> panic "maxSpillSlots ArchMipsel"
89 ArchRISCV64 -> panic "maxSpillSlots ArchRISCV64"
90 ArchJavaScript-> panic "maxSpillSlots ArchJavaScript"
91 ArchUnknown -> panic "maxSpillSlots ArchUnknown"