summaryrefslogtreecommitdiff
path: root/compiler/nativeGen/RegAlloc/Linear/FreeRegs.hs
blob: b442d069a4afb68c1d11114bc474259e401e3d6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

module RegAlloc.Linear.FreeRegs (
    FR(..),
    maxSpillSlots
)

#include "HsVersions.h"

where

import Reg
import RegClass

import Panic
import Platform

-- -----------------------------------------------------------------------------
-- The free register set
-- This needs to be *efficient*
-- Here's an inefficient 'executable specification' of the FreeRegs data type:
--
--	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

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 PPC.Instr
import qualified SPARC.Instr
import qualified X86.Instr

class Show freeRegs => FR freeRegs where
    frAllocateReg :: RealReg -> freeRegs -> freeRegs
    frGetFreeRegs :: RegClass -> freeRegs -> [RealReg]
    frInitFreeRegs :: freeRegs
    frReleaseReg :: RealReg -> freeRegs -> freeRegs

instance FR X86.FreeRegs where
    frAllocateReg  = X86.allocateReg
    frGetFreeRegs  = X86.getFreeRegs
    frInitFreeRegs = X86.initFreeRegs
    frReleaseReg   = X86.releaseReg

instance FR PPC.FreeRegs where
    frAllocateReg  = PPC.allocateReg
    frGetFreeRegs  = PPC.getFreeRegs
    frInitFreeRegs = PPC.initFreeRegs
    frReleaseReg   = PPC.releaseReg

instance FR SPARC.FreeRegs where
    frAllocateReg  = SPARC.allocateReg
    frGetFreeRegs  = SPARC.getFreeRegs
    frInitFreeRegs = SPARC.initFreeRegs
    frReleaseReg   = SPARC.releaseReg

-- TODO: We shouldn't be using defaultTargetPlatform here.
--       We should be passing DynFlags in instead, and looking at
--       its targetPlatform.

maxSpillSlots :: Int
maxSpillSlots = case platformArch defaultTargetPlatform of
                ArchX86     -> X86.Instr.maxSpillSlots
                ArchX86_64  -> X86.Instr.maxSpillSlots
                ArchPPC     -> PPC.Instr.maxSpillSlots
                ArchSPARC   -> SPARC.Instr.maxSpillSlots
                ArchPPC_64  -> panic "maxSpillSlots ArchPPC_64"
                ArchUnknown -> panic "maxSpillSlots ArchUnknown"