FreeRegs.hs 2.99 KB
Newer Older
1
{-# LANGUAGE CPP #-}
2 3

module RegAlloc.Linear.FreeRegs (
4 5
    FR(..),
    maxSpillSlots
6 7 8 9 10 11
)

#include "HsVersions.h"

where

12 13
import GhcPrelude

14 15 16
import Reg
import RegClass

17
import DynFlags
18
import Panic
John Ericson's avatar
John Ericson committed
19
import GHC.Platform
20

21 22 23 24 25
-- -----------------------------------------------------------------------------
-- The free register set
-- This needs to be *efficient*
-- Here's an inefficient 'executable specification' of the FreeRegs data type:
--
benl's avatar
benl committed
26 27 28 29 30 31
--      type FreeRegs = [RegNo]
--      noFreeRegs = 0
--      releaseReg n f = if n `elem` f then f else (n : f)
--      initFreeRegs = allocatableRegs
--      getFreeRegs cls f = filter ( (==cls) . regClass . RealReg ) f
--      allocateReg f r = filter (/= r) f
32

ian@well-typed.com's avatar
ian@well-typed.com committed
33 34 35 36
import qualified RegAlloc.Linear.PPC.FreeRegs    as PPC
import qualified RegAlloc.Linear.SPARC.FreeRegs  as SPARC
import qualified RegAlloc.Linear.X86.FreeRegs    as X86
import qualified RegAlloc.Linear.X86_64.FreeRegs as X86_64
37 38 39 40 41 42

import qualified PPC.Instr
import qualified SPARC.Instr
import qualified X86.Instr

class Show freeRegs => FR freeRegs where
43
    frAllocateReg :: Platform -> RealReg -> freeRegs -> freeRegs
44
    frGetFreeRegs :: Platform -> RegClass -> freeRegs -> [RealReg]
45
    frInitFreeRegs :: Platform -> freeRegs
46
    frReleaseReg :: Platform -> RealReg -> freeRegs -> freeRegs
47

48
instance FR X86.FreeRegs where
49
    frAllocateReg  = \_ -> X86.allocateReg
50 51
    frGetFreeRegs  = X86.getFreeRegs
    frInitFreeRegs = X86.initFreeRegs
52
    frReleaseReg   = \_ -> X86.releaseReg
53

ian@well-typed.com's avatar
ian@well-typed.com committed
54 55 56 57 58 59
instance FR X86_64.FreeRegs where
    frAllocateReg  = \_ -> X86_64.allocateReg
    frGetFreeRegs  = X86_64.getFreeRegs
    frInitFreeRegs = X86_64.initFreeRegs
    frReleaseReg   = \_ -> X86_64.releaseReg

60
instance FR PPC.FreeRegs where
61
    frAllocateReg  = \_ -> PPC.allocateReg
62
    frGetFreeRegs  = \_ -> PPC.getFreeRegs
63 64
    frInitFreeRegs = PPC.initFreeRegs
    frReleaseReg   = \_ -> PPC.releaseReg
65

66 67
instance FR SPARC.FreeRegs where
    frAllocateReg  = SPARC.allocateReg
68
    frGetFreeRegs  = \_ -> SPARC.getFreeRegs
69
    frInitFreeRegs = SPARC.initFreeRegs
70
    frReleaseReg   = SPARC.releaseReg
71

72 73 74 75 76 77 78
maxSpillSlots :: DynFlags -> Int
maxSpillSlots dflags
              = case platformArch (targetPlatform dflags) of
                ArchX86       -> X86.Instr.maxSpillSlots dflags
                ArchX86_64    -> X86.Instr.maxSpillSlots dflags
                ArchPPC       -> PPC.Instr.maxSpillSlots dflags
                ArchSPARC     -> SPARC.Instr.maxSpillSlots dflags
79
                ArchSPARC64   -> panic "maxSpillSlots ArchSPARC64"
80
                ArchARM _ _ _ -> panic "maxSpillSlots ArchARM"
Colin Watson's avatar
Colin Watson committed
81
                ArchARM64     -> panic "maxSpillSlots ArchARM64"
82
                ArchPPC_64 _  -> PPC.Instr.maxSpillSlots dflags
83 84 85
                ArchAlpha     -> panic "maxSpillSlots ArchAlpha"
                ArchMipseb    -> panic "maxSpillSlots ArchMipseb"
                ArchMipsel    -> panic "maxSpillSlots ArchMipsel"
thoughtpolice's avatar
thoughtpolice committed
86
                ArchJavaScript-> panic "maxSpillSlots ArchJavaScript"
87
                ArchUnknown   -> panic "maxSpillSlots ArchUnknown"
88