Commit 15856e97 authored by ian@well-typed.com's avatar ian@well-typed.com
Browse files

Add haveRegBase to CodeGen.Platform

parent 75700644
......@@ -308,14 +308,15 @@ callerSaveVolatileRegs dflags vols = (caller_save, caller_load)
callerSaveGlobalReg reg next
| callerSaves platform reg =
CmmStore (get_GlobalReg_addr reg)
CmmStore (get_GlobalReg_addr platform reg)
(CmmReg (CmmGlobal reg)) : next
| otherwise = next
callerRestoreGlobalReg reg next
| callerSaves platform reg =
CmmAssign (CmmGlobal reg)
(CmmLoad (get_GlobalReg_addr reg) (globalRegType reg))
(CmmLoad (get_GlobalReg_addr platform reg)
(globalRegType reg))
: next
| otherwise = next
......@@ -810,10 +811,11 @@ srt_escape = -1
-- to real machine registers or stored as offsets from BaseReg. Given
-- a GlobalReg, get_GlobalReg_addr always produces the
-- register table address for it.
get_GlobalReg_addr :: GlobalReg -> CmmExpr
get_GlobalReg_addr BaseReg = regTableOffset 0
get_GlobalReg_addr mid = get_Regtable_addr_from_offset
(globalRegType mid) (baseRegOffset mid)
get_GlobalReg_addr :: Platform -> GlobalReg -> CmmExpr
get_GlobalReg_addr _ BaseReg = regTableOffset 0
get_GlobalReg_addr platform mid
= get_Regtable_addr_from_offset platform
(globalRegType mid) (baseRegOffset mid)
-- Calculate a literal representing an offset into the register table.
-- Used when we don't have an actual BaseReg to offset from.
......@@ -821,13 +823,11 @@ regTableOffset :: Int -> CmmExpr
regTableOffset n =
CmmLit (CmmLabelOff mkMainCapabilityLabel (oFFSET_Capability_r + n))
get_Regtable_addr_from_offset :: CmmType -> Int -> CmmExpr
get_Regtable_addr_from_offset _ offset =
#ifdef REG_Base
CmmRegOff (CmmGlobal BaseReg) offset
#else
regTableOffset offset
#endif
get_Regtable_addr_from_offset :: Platform -> CmmType -> Int -> CmmExpr
get_Regtable_addr_from_offset platform _ offset =
if haveRegBase platform
then CmmRegOff (CmmGlobal BaseReg) offset
else regTableOffset offset
-- | Fixup global registers so that they assign to locations within the
-- RegTable if they aren't pinned for the current target.
......@@ -848,7 +848,7 @@ fixStgRegStmt platform stmt
= case stmt of
CmmAssign (CmmGlobal reg) src ->
let src' = fixStgRegExpr platform src
baseAddr = get_GlobalReg_addr reg
baseAddr = get_GlobalReg_addr platform reg
in case reg `elem` activeStgRegs platform of
True -> CmmAssign (CmmGlobal reg) src'
False -> CmmStore baseAddr src'
......@@ -896,7 +896,7 @@ fixStgRegExpr platform expr
case reg `elem` activeStgRegs platform of
True -> expr
False ->
let baseAddr = get_GlobalReg_addr reg
let baseAddr = get_GlobalReg_addr platform reg
in case reg of
BaseReg -> fixStgRegExpr platform baseAddr
_other -> fixStgRegExpr platform
......
module CodeGen.Platform (callerSaves, activeStgRegs) where
module CodeGen.Platform (callerSaves, activeStgRegs, haveRegBase) where
import CmmExpr
import Platform
......@@ -50,3 +50,18 @@ activeStgRegs platform
| otherwise -> NoRegs.activeStgRegs
haveRegBase :: Platform -> Bool
haveRegBase platform
= case platformArch platform of
ArchX86 -> X86.haveRegBase
ArchX86_64 -> X86_64.haveRegBase
ArchSPARC -> SPARC.haveRegBase
ArchARM {} -> ARM.haveRegBase
arch
| arch `elem` [ArchPPC, ArchPPC_64] ->
case platformOS platform of
OSDarwin -> PPC_Darwin.haveRegBase
_ -> PPC.haveRegBase
| otherwise -> NoRegs.haveRegBase
......@@ -143,3 +143,10 @@ activeStgRegs = [
#endif
]
haveRegBase :: Bool
#ifdef REG_Base
haveRegBase = True
#else
haveRegBase = False
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment