Fix callerSaves, activeStgRegs, haveRegBase when unregisterised
[ghc.git] / compiler / codeGen / CodeGen / Platform.hs
1
2 module CodeGen.Platform (callerSaves, activeStgRegs, haveRegBase) where
3
4 import CmmExpr
5 import Platform
6
7 import qualified CodeGen.Platform.ARM as ARM
8 import qualified CodeGen.Platform.PPC as PPC
9 import qualified CodeGen.Platform.PPC_Darwin as PPC_Darwin
10 import qualified CodeGen.Platform.SPARC as SPARC
11 import qualified CodeGen.Platform.X86 as X86
12 import qualified CodeGen.Platform.X86_64 as X86_64
13 import qualified CodeGen.Platform.NoRegs as NoRegs
14
15 -- | Returns 'True' if this global register is stored in a caller-saves
16 -- machine register.
17
18 callerSaves :: Platform -> GlobalReg -> Bool
19 callerSaves platform
20 | platformUnregisterised platform = NoRegs.callerSaves
21 | otherwise
22 = case platformArch platform of
23 ArchX86 -> X86.callerSaves
24 ArchX86_64 -> X86_64.callerSaves
25 ArchSPARC -> SPARC.callerSaves
26 ArchARM {} -> ARM.callerSaves
27 arch
28 | arch `elem` [ArchPPC, ArchPPC_64] ->
29 case platformOS platform of
30 OSDarwin -> PPC_Darwin.callerSaves
31 _ -> PPC.callerSaves
32
33 | otherwise -> NoRegs.callerSaves
34
35 -- | Here is where the STG register map is defined for each target arch.
36 -- The order matters (for the llvm backend anyway)! We must make sure to
37 -- maintain the order here with the order used in the LLVM calling conventions.
38 -- Note that also, this isn't all registers, just the ones that are currently
39 -- possbily mapped to real registers.
40 activeStgRegs :: Platform -> [GlobalReg]
41 activeStgRegs platform
42 | platformUnregisterised platform = NoRegs.activeStgRegs
43 | otherwise
44 = case platformArch platform of
45 ArchX86 -> X86.activeStgRegs
46 ArchX86_64 -> X86_64.activeStgRegs
47 ArchSPARC -> SPARC.activeStgRegs
48 ArchARM {} -> ARM.activeStgRegs
49 arch
50 | arch `elem` [ArchPPC, ArchPPC_64] ->
51 case platformOS platform of
52 OSDarwin -> PPC_Darwin.activeStgRegs
53 _ -> PPC.activeStgRegs
54
55 | otherwise -> NoRegs.activeStgRegs
56
57 haveRegBase :: Platform -> Bool
58 haveRegBase platform
59 | platformUnregisterised platform = NoRegs.haveRegBase
60 | otherwise
61 = case platformArch platform of
62 ArchX86 -> X86.haveRegBase
63 ArchX86_64 -> X86_64.haveRegBase
64 ArchSPARC -> SPARC.haveRegBase
65 ArchARM {} -> ARM.haveRegBase
66 arch
67 | arch `elem` [ArchPPC, ArchPPC_64] ->
68 case platformOS platform of
69 OSDarwin -> PPC_Darwin.haveRegBase
70 _ -> PPC.haveRegBase
71
72 | otherwise -> NoRegs.haveRegBase
73