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