X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FnativeGen%2FRegAlloc%2FLinear%2FPPC%2FFreeRegs.hs;fp=compiler%2FnativeGen%2FRegAlloc%2FLinear%2FPPC%2FFreeRegs.hs;h=1e31625c37a9587e72d3152e722ab28ab52f33e7;hb=cbc96da034482b769889c109f6cc822f42b12027;hp=0000000000000000000000000000000000000000;hpb=d7d09c18459983be1ef690e0d9136a8736b1976f;p=ghc-hetmet.git diff --git a/compiler/nativeGen/RegAlloc/Linear/PPC/FreeRegs.hs b/compiler/nativeGen/RegAlloc/Linear/PPC/FreeRegs.hs new file mode 100644 index 0000000..1e31625 --- /dev/null +++ b/compiler/nativeGen/RegAlloc/Linear/PPC/FreeRegs.hs @@ -0,0 +1,54 @@ + +-- | Free regs map for PowerPC +module RegAlloc.Linear.PPC.FreeRegs +where + +import MachRegs + +import Outputable + +import Data.Word +import Data.Bits +import Data.List + +-- The PowerPC has 32 integer and 32 floating point registers. +-- This is 32bit PowerPC, so Word64 is inefficient - two Word32s are much +-- better. +-- Note that when getFreeRegs scans for free registers, it starts at register +-- 31 and counts down. This is a hack for the PowerPC - the higher-numbered +-- registers are callee-saves, while the lower regs are caller-saves, so it +-- makes sense to start at the high end. +-- Apart from that, the code does nothing PowerPC-specific, so feel free to +-- add your favourite platform to the #if (if you have 64 registers but only +-- 32-bit words). + +data FreeRegs = FreeRegs !Word32 !Word32 + deriving( Show ) -- The Show is used in an ASSERT + +noFreeRegs :: FreeRegs +noFreeRegs = FreeRegs 0 0 + +releaseReg :: RegNo -> FreeRegs -> FreeRegs +releaseReg r (FreeRegs g f) + | r > 31 = FreeRegs g (f .|. (1 `shiftL` (fromIntegral r - 32))) + | otherwise = FreeRegs (g .|. (1 `shiftL` fromIntegral r)) f + +initFreeRegs :: FreeRegs +initFreeRegs = foldr releaseReg noFreeRegs allocatableRegs + +getFreeRegs :: RegClass -> FreeRegs -> [RegNo] -- lazilly +getFreeRegs cls (FreeRegs g f) + | RcDouble <- cls = go f (0x80000000) 63 + | RcInteger <- cls = go g (0x80000000) 31 + | otherwise = pprPanic "RegAllocLinear.getFreeRegs: Bad register class" (ppr cls) + where + go _ 0 _ = [] + go x m i | x .&. m /= 0 = i : (go x (m `shiftR` 1) $! i-1) + | otherwise = go x (m `shiftR` 1) $! i-1 + +allocateReg :: RegNo -> FreeRegs -> FreeRegs +allocateReg r (FreeRegs g f) + | r > 31 = FreeRegs g (f .&. complement (1 `shiftL` (fromIntegral r - 32))) + | otherwise = FreeRegs (g .&. complement (1 `shiftL` fromIntegral r)) f + +