9af4712c299f05ec0dd7fa084c3ef7c318c2d3f5
[ghc.git] / compiler / codeGen / CodeGen / Platform.hs
1
2 module CodeGen.Platform
3 (callerSaves, activeStgRegs, haveRegBase, globalRegMaybe, freeReg)
4 where
5
6 import CmmExpr
7 import FastBool
8 import Platform
9 import Reg
10
11 import qualified CodeGen.Platform.ARM as ARM
12 import qualified CodeGen.Platform.ARM64 as ARM64
13 import qualified CodeGen.Platform.PPC as PPC
14 import qualified CodeGen.Platform.PPC_Darwin as PPC_Darwin
15 import qualified CodeGen.Platform.SPARC as SPARC
16 import qualified CodeGen.Platform.X86 as X86
17 import qualified CodeGen.Platform.X86_64 as X86_64
18 import qualified CodeGen.Platform.NoRegs as NoRegs
19
20 -- | Returns 'True' if this global register is stored in a caller-saves
21 -- machine register.
22
23 callerSaves :: Platform -> GlobalReg -> Bool
24 callerSaves platform
25 | platformUnregisterised platform = NoRegs.callerSaves
26 | otherwise
27 = case platformArch platform of
28 ArchX86 -> X86.callerSaves
29 ArchX86_64 -> X86_64.callerSaves
30 ArchSPARC -> SPARC.callerSaves
31 ArchARM {} -> ARM.callerSaves
32 ArchARM64 -> ARM64.callerSaves
33 arch
34 | arch `elem` [ArchPPC, ArchPPC_64 ELF_V1, ArchPPC_64 ELF_V2] ->
35 case platformOS platform of
36 OSDarwin -> PPC_Darwin.callerSaves
37 _ -> PPC.callerSaves
38
39 | otherwise -> NoRegs.callerSaves
40
41 -- | Here is where the STG register map is defined for each target arch.
42 -- The order matters (for the llvm backend anyway)! We must make sure to
43 -- maintain the order here with the order used in the LLVM calling conventions.
44 -- Note that also, this isn't all registers, just the ones that are currently
45 -- possbily mapped to real registers.
46 activeStgRegs :: Platform -> [GlobalReg]
47 activeStgRegs platform
48 | platformUnregisterised platform = NoRegs.activeStgRegs
49 | otherwise
50 = case platformArch platform of
51 ArchX86 -> X86.activeStgRegs
52 ArchX86_64 -> X86_64.activeStgRegs
53 ArchSPARC -> SPARC.activeStgRegs
54 ArchARM {} -> ARM.activeStgRegs
55 ArchARM64 -> ARM64.activeStgRegs
56 arch
57 | arch `elem` [ArchPPC, ArchPPC_64 ELF_V1, ArchPPC_64 ELF_V2] ->
58 case platformOS platform of
59 OSDarwin -> PPC_Darwin.activeStgRegs
60 _ -> PPC.activeStgRegs
61
62 | otherwise -> NoRegs.activeStgRegs
63
64 haveRegBase :: Platform -> Bool
65 haveRegBase platform
66 | platformUnregisterised platform = NoRegs.haveRegBase
67 | otherwise
68 = case platformArch platform of
69 ArchX86 -> X86.haveRegBase
70 ArchX86_64 -> X86_64.haveRegBase
71 ArchSPARC -> SPARC.haveRegBase
72 ArchARM {} -> ARM.haveRegBase
73 ArchARM64 -> ARM64.haveRegBase
74 arch
75 | arch `elem` [ArchPPC, ArchPPC_64 ELF_V1, ArchPPC_64 ELF_V2] ->
76 case platformOS platform of
77 OSDarwin -> PPC_Darwin.haveRegBase
78 _ -> PPC.haveRegBase
79
80 | otherwise -> NoRegs.haveRegBase
81
82 globalRegMaybe :: Platform -> GlobalReg -> Maybe RealReg
83 globalRegMaybe platform
84 | platformUnregisterised platform = NoRegs.globalRegMaybe
85 | otherwise
86 = case platformArch platform of
87 ArchX86 -> X86.globalRegMaybe
88 ArchX86_64 -> X86_64.globalRegMaybe
89 ArchSPARC -> SPARC.globalRegMaybe
90 ArchARM {} -> ARM.globalRegMaybe
91 ArchARM64 -> ARM64.globalRegMaybe
92 arch
93 | arch `elem` [ArchPPC, ArchPPC_64 ELF_V1, ArchPPC_64 ELF_V2] ->
94 case platformOS platform of
95 OSDarwin -> PPC_Darwin.globalRegMaybe
96 _ -> PPC.globalRegMaybe
97
98 | otherwise -> NoRegs.globalRegMaybe
99
100 freeReg :: Platform -> RegNo -> FastBool
101 freeReg platform
102 | platformUnregisterised platform = NoRegs.freeReg
103 | otherwise
104 = case platformArch platform of
105 ArchX86 -> X86.freeReg
106 ArchX86_64 -> X86_64.freeReg
107 ArchSPARC -> SPARC.freeReg
108 ArchARM {} -> ARM.freeReg
109 ArchARM64 -> ARM64.freeReg
110 arch
111 | arch `elem` [ArchPPC, ArchPPC_64 ELF_V1, ArchPPC_64 ELF_V2] ->
112 case platformOS platform of
113 OSDarwin -> PPC_Darwin.freeReg
114 _ -> PPC.freeReg
115
116 | otherwise -> NoRegs.freeReg
117