blob: 2b69da0093bd27bf39c2420d405f48574432b857 (
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
|
-- | Free regs map for i386 and x86_64
module RegAlloc.Linear.X86.FreeRegs
where
import X86.Regs
import RegClass
import Reg
import Data.Word
import Data.Bits
import Data.List
type FreeRegs
= Word32
noFreeRegs :: FreeRegs
noFreeRegs = 0
releaseReg :: RegNo -> FreeRegs -> FreeRegs
releaseReg n f = f .|. (1 `shiftL` n)
initFreeRegs :: FreeRegs
initFreeRegs = foldr releaseReg noFreeRegs allocatableRegs
getFreeRegs :: RegClass -> FreeRegs -> [RegNo] -- lazilly
getFreeRegs cls f = go f 0
where go 0 _ = []
go n m
| n .&. 1 /= 0 && regClass (regSingle m) == cls
= m : (go (n `shiftR` 1) $! (m+1))
| otherwise
= go (n `shiftR` 1) $! (m+1)
-- ToDo: there's no point looking through all the integer registers
-- in order to find a floating-point one.
allocateReg :: RegNo -> FreeRegs -> FreeRegs
allocateReg r f = f .&. complement (1 `shiftL` fromIntegral r)
|