2 -- | Free regs map for i386 and x86_64
3 module RegAlloc.Linear.X86.FreeRegs
15 #ifdef i386_TARGET_ARCH
21 noFreeRegs :: FreeRegs
24 releaseReg :: RealReg -> FreeRegs -> FreeRegs
25 releaseReg (RealRegSingle n) f
26 = f .|. (1 `shiftL` n)
29 = panic "RegAlloc.Linear.X86.FreeRegs.realeaseReg: no reg"
31 initFreeRegs :: FreeRegs
33 = foldr releaseReg noFreeRegs allocatableRegs
35 getFreeRegs :: RegClass -> FreeRegs -> [RealReg] -- lazilly
36 getFreeRegs cls f = go f 0
40 | n .&. 1 /= 0 && classOfRealReg (RealRegSingle m) == cls
41 = RealRegSingle m : (go (n `shiftR` 1) $! (m+1))
44 = go (n `shiftR` 1) $! (m+1)
45 -- ToDo: there's no point looking through all the integer registers
46 -- in order to find a floating-point one.
48 allocateReg :: RealReg -> FreeRegs -> FreeRegs
49 allocateReg (RealRegSingle r) f
50 = f .&. complement (1 `shiftL` fromIntegral r)
53 = panic "RegAlloc.Linear.X86.FreeRegs.allocateReg: no reg"