X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2FnativeGen%2FRegAlloc%2FLinear%2FFreeRegs.hs;fp=compiler%2FnativeGen%2FRegAlloc%2FLinear%2FFreeRegs.hs;h=b442d069a4afb68c1d11114bc474259e401e3d6e;hp=b357160c9628c54d13bf89078b998217edeffc76;hb=3c2a7f3515ca15cdebb6242967f89e633cb59494;hpb=59244201b672b9d6f728edcf7e2e02a61fbe278f diff --git a/compiler/nativeGen/RegAlloc/Linear/FreeRegs.hs b/compiler/nativeGen/RegAlloc/Linear/FreeRegs.hs index b357160..b442d06 100644 --- a/compiler/nativeGen/RegAlloc/Linear/FreeRegs.hs +++ b/compiler/nativeGen/RegAlloc/Linear/FreeRegs.hs @@ -1,18 +1,19 @@ module RegAlloc.Linear.FreeRegs ( - FreeRegs(), - noFreeRegs, - releaseReg, - initFreeRegs, - getFreeRegs, - allocateReg, - maxSpillSlots + FR(..), + maxSpillSlots ) #include "HsVersions.h" where +import Reg +import RegClass + +import Panic +import Platform + -- ----------------------------------------------------------------------------- -- The free register set -- This needs to be *efficient* @@ -25,21 +26,48 @@ where -- getFreeRegs cls f = filter ( (==cls) . regClass . RealReg ) f -- allocateReg f r = filter (/= r) f +import qualified RegAlloc.Linear.PPC.FreeRegs as PPC +import qualified RegAlloc.Linear.SPARC.FreeRegs as SPARC +import qualified RegAlloc.Linear.X86.FreeRegs as X86 + +import qualified PPC.Instr +import qualified SPARC.Instr +import qualified X86.Instr + +class Show freeRegs => FR freeRegs where + frAllocateReg :: RealReg -> freeRegs -> freeRegs + frGetFreeRegs :: RegClass -> freeRegs -> [RealReg] + frInitFreeRegs :: freeRegs + frReleaseReg :: RealReg -> freeRegs -> freeRegs -#if defined(powerpc_TARGET_ARCH) -import RegAlloc.Linear.PPC.FreeRegs -import PPC.Instr (maxSpillSlots) +instance FR X86.FreeRegs where + frAllocateReg = X86.allocateReg + frGetFreeRegs = X86.getFreeRegs + frInitFreeRegs = X86.initFreeRegs + frReleaseReg = X86.releaseReg -#elif defined(sparc_TARGET_ARCH) -import RegAlloc.Linear.SPARC.FreeRegs -import SPARC.Instr (maxSpillSlots) +instance FR PPC.FreeRegs where + frAllocateReg = PPC.allocateReg + frGetFreeRegs = PPC.getFreeRegs + frInitFreeRegs = PPC.initFreeRegs + frReleaseReg = PPC.releaseReg -#elif defined(i386_TARGET_ARCH) || defined(x86_64_TARGET_ARCH) -import RegAlloc.Linear.X86.FreeRegs -import X86.Instr (maxSpillSlots) +instance FR SPARC.FreeRegs where + frAllocateReg = SPARC.allocateReg + frGetFreeRegs = SPARC.getFreeRegs + frInitFreeRegs = SPARC.initFreeRegs + frReleaseReg = SPARC.releaseReg -#else -#error "RegAlloc.Linear.FreeRegs not defined for this architecture." +-- TODO: We shouldn't be using defaultTargetPlatform here. +-- We should be passing DynFlags in instead, and looking at +-- its targetPlatform. -#endif +maxSpillSlots :: Int +maxSpillSlots = case platformArch defaultTargetPlatform of + ArchX86 -> X86.Instr.maxSpillSlots + ArchX86_64 -> X86.Instr.maxSpillSlots + ArchPPC -> PPC.Instr.maxSpillSlots + ArchSPARC -> SPARC.Instr.maxSpillSlots + ArchPPC_64 -> panic "maxSpillSlots ArchPPC_64" + ArchUnknown -> panic "maxSpillSlots ArchUnknown"