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