2 -- | Free regs map for PowerPC
3 module RegAlloc.Linear.PPC.FreeRegs
14 -- The PowerPC has 32 integer and 32 floating point registers.
15 -- This is 32bit PowerPC, so Word64 is inefficient - two Word32s are much
17 -- Note that when getFreeRegs scans for free registers, it starts at register
18 -- 31 and counts down. This is a hack for the PowerPC - the higher-numbered
19 -- registers are callee-saves, while the lower regs are caller-saves, so it
20 -- makes sense to start at the high end.
21 -- Apart from that, the code does nothing PowerPC-specific, so feel free to
22 -- add your favourite platform to the #if (if you have 64 registers but only
25 data FreeRegs = FreeRegs !Word32 !Word32
26 deriving( Show ) -- The Show is used in an ASSERT
28 noFreeRegs :: FreeRegs
29 noFreeRegs = FreeRegs 0 0
31 releaseReg :: RegNo -> FreeRegs -> FreeRegs
32 releaseReg r (FreeRegs g f)
33 | r > 31 = FreeRegs g (f .|. (1 `shiftL` (fromIntegral r - 32)))
34 | otherwise = FreeRegs (g .|. (1 `shiftL` fromIntegral r)) f
36 initFreeRegs :: FreeRegs
37 initFreeRegs = foldr releaseReg noFreeRegs allocatableRegs
39 getFreeRegs :: RegClass -> FreeRegs -> [RegNo] -- lazilly
40 getFreeRegs cls (FreeRegs g f)
41 | RcDouble <- cls = go f (0x80000000) 63
42 | RcInteger <- cls = go g (0x80000000) 31
43 | otherwise = pprPanic "RegAllocLinear.getFreeRegs: Bad register class" (ppr cls)
46 go x m i | x .&. m /= 0 = i : (go x (m `shiftR` 1) $! i-1)
47 | otherwise = go x (m `shiftR` 1) $! i-1
49 allocateReg :: RegNo -> FreeRegs -> FreeRegs
50 allocateReg r (FreeRegs g f)
51 | r > 31 = FreeRegs g (f .&. complement (1 `shiftL` (fromIntegral r - 32)))
52 | otherwise = FreeRegs (g .&. complement (1 `shiftL` fromIntegral r)) f