2 -- | Free regs map for i386 and x86_64
3 module RegAlloc.Linear.X86.FreeRegs
18 noFreeRegs :: FreeRegs
21 releaseReg :: RealReg -> FreeRegs -> FreeRegs
22 releaseReg (RealRegSingle n) f
23 = f .|. (1 `shiftL` n)
26 = panic "RegAlloc.Linear.X86.FreeRegs.realeaseReg: no reg"
28 initFreeRegs :: FreeRegs
30 = foldr releaseReg noFreeRegs allocatableRegs
32 getFreeRegs :: RegClass -> FreeRegs -> [RealReg] -- lazilly
33 getFreeRegs cls f = go f 0
37 | n .&. 1 /= 0 && classOfRealReg (RealRegSingle m) == cls
38 = RealRegSingle m : (go (n `shiftR` 1) $! (m+1))
41 = go (n `shiftR` 1) $! (m+1)
42 -- ToDo: there's no point looking through all the integer registers
43 -- in order to find a floating-point one.
45 allocateReg :: RealReg -> FreeRegs -> FreeRegs
46 allocateReg (RealRegSingle r) f
47 = f .&. complement (1 `shiftL` fromIntegral r)
50 = panic "RegAlloc.Linear.X86.FreeRegs.allocateReg: no reg"