X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FnativeGen%2FRegAllocInfo.hs;h=024774e822b7ef4926df7432bd7a948e9cc36971;hb=a50f11ebc0667355e5669c922adf70f926c1763a;hp=98c4e2dfe061310d19ec1cfc1481f1c1e819e5c7;hpb=0065d5ab628975892cea1ec7303f968c3338cbe1;p=ghc-hetmet.git diff --git a/compiler/nativeGen/RegAllocInfo.hs b/compiler/nativeGen/RegAllocInfo.hs index 98c4e2d..024774e 100644 --- a/compiler/nativeGen/RegAllocInfo.hs +++ b/compiler/nativeGen/RegAllocInfo.hs @@ -17,6 +17,8 @@ module RegAllocInfo ( patchJump, isRegRegMove, + JumpDest, canShortcut, shortcutJump, shortcutStatic, + maxSpillSlots, mkSpillInstr, mkLoadInstr, @@ -26,7 +28,8 @@ module RegAllocInfo ( #include "HsVersions.h" -import Cmm ( BlockId ) +import Cmm +import CLabel import MachOp ( MachRep(..), wordRep ) import MachInstrs import MachRegs @@ -156,6 +159,8 @@ regUsage instr = case instr of IDIV sz op -> mkRU (eax:edx:use_R op) [eax,edx] AND sz src dst -> usageRM src dst OR sz src dst -> usageRM src dst + XOR sz (OpReg src) (OpReg dst) + | src == dst -> mkRU [] [dst] XOR sz src dst -> usageRM src dst NOT sz op -> usageM op NEGI sz op -> usageM op @@ -170,6 +175,7 @@ regUsage instr = case instr of CMP sz src dst -> mkRUR (use_R src ++ use_R dst) SETCC cond op -> mkRU [] (def_W op) JXX cond lbl -> mkRU [] [] + JXX_GBL cond lbl -> mkRU [] [] JMP op -> mkRUR (use_R op) JMP_TBL op ids -> mkRUR (use_R op) CALL (Left imm) params -> mkRU params callClobberedRegs @@ -208,8 +214,8 @@ regUsage instr = case instr of #if x86_64_TARGET_ARCH CVTSS2SD src dst -> mkRU [src] [dst] CVTSD2SS src dst -> mkRU [src] [dst] - CVTSS2SI src dst -> mkRU (use_R src) [dst] - CVTSD2SI src dst -> mkRU (use_R src) [dst] + CVTTSS2SIQ src dst -> mkRU (use_R src) [dst] + CVTTSD2SIQ src dst -> mkRU (use_R src) [dst] CVTSI2SS src dst -> mkRU (use_R src) [dst] CVTSI2SD src dst -> mkRU (use_R src) [dst] FDIV sz src dst -> usageRM src dst @@ -224,12 +230,6 @@ regUsage instr = case instr of _other -> panic "regUsage: unrecognised instr" where -#if x86_64_TARGET_ARCH - -- call parameters: include %eax, because it is used - -- to pass the number of SSE reg arguments to varargs fns. - params = eax : allArgRegs ++ allFPArgRegs -#endif - -- 2 operand form; first operand Read; second Written usageRW :: Operand -> Operand -> RegUsage usageRW op (OpReg reg) = mkRU (use_R op) [reg] @@ -337,6 +337,7 @@ regUsage instr = case instr of CMP sz reg ri -> usage (reg : regRI ri,[]) CMPL sz reg ri -> usage (reg : regRI ri,[]) BCC cond lbl -> noUsage + BCCFAR cond lbl -> noUsage MTCTR reg -> usage ([reg],[]) BCTR targets -> noUsage BL imm params -> usage (params, callClobberedRegs) @@ -401,6 +402,7 @@ jumpDests insn acc JMP_TBL _ ids -> ids ++ acc #elif powerpc_TARGET_ARCH BCC _ id -> id : acc + BCCFAR _ id -> id : acc BCTR targets -> targets ++ acc #endif _other -> acc @@ -414,10 +416,50 @@ patchJump insn old new JMP_TBL op ids -> error "Cannot patch JMP_TBL" #elif powerpc_TARGET_ARCH BCC cc id | id == old -> BCC cc new + BCCFAR cc id | id == old -> BCCFAR cc new BCTR targets -> error "Cannot patch BCTR" #endif _other -> insn +data JumpDest = DestBlockId BlockId | DestImm Imm + +canShortcut :: Instr -> Maybe JumpDest +#if i386_TARGET_ARCH || x86_64_TARGET_ARCH +canShortcut (JXX ALWAYS id) = Just (DestBlockId id) +canShortcut (JMP (OpImm imm)) = Just (DestImm imm) +#endif +canShortcut _ = Nothing + +shortcutJump :: (BlockId -> Maybe JumpDest) -> Instr -> Instr +#if i386_TARGET_ARCH || x86_64_TARGET_ARCH +shortcutJump fn insn@(JXX cc id) = + case fn id of + Nothing -> insn + Just (DestBlockId id') -> shortcutJump fn (JXX cc id') + Just (DestImm imm) -> shortcutJump fn (JXX_GBL cc imm) +#endif +shortcutJump fn other = other + +-- Here because it knows about JumpDest +shortcutStatic :: (BlockId -> Maybe JumpDest) -> CmmStatic -> CmmStatic +shortcutStatic fn (CmmStaticLit (CmmLabel lab)) + | Just uq <- maybeAsmTemp lab + = CmmStaticLit (CmmLabel (shortBlockId fn (BlockId uq))) +shortcutStatic fn (CmmStaticLit (CmmLabelDiffOff lbl1 lbl2 off)) + | Just uq <- maybeAsmTemp lbl1 + = CmmStaticLit (CmmLabelDiffOff (shortBlockId fn (BlockId uq)) lbl2 off) + -- slightly dodgy, we're ignoring the second label, but this + -- works with the way we use CmmLabelDiffOff for jump tables now. +shortcutStatic fn other_static + = other_static + +shortBlockId fn blockid@(BlockId uq) = + case fn blockid of + Nothing -> mkAsmTempLabel uq + Just (DestBlockId blockid') -> shortBlockId fn blockid' + Just (DestImm (ImmCLbl lbl)) -> lbl + _other -> panic "shortBlockId" + -- ----------------------------------------------------------------------------- -- 'patchRegs' function @@ -546,8 +588,8 @@ patchRegs instr env = case instr of #if x86_64_TARGET_ARCH CVTSS2SD src dst -> CVTSS2SD (env src) (env dst) CVTSD2SS src dst -> CVTSD2SS (env src) (env dst) - CVTSS2SI src dst -> CVTSS2SI (patchOp src) (env dst) - CVTSD2SI src dst -> CVTSD2SI (patchOp src) (env dst) + CVTTSS2SIQ src dst -> CVTTSS2SIQ (patchOp src) (env dst) + CVTTSD2SIQ src dst -> CVTTSD2SIQ (patchOp src) (env dst) CVTSI2SS src dst -> CVTSI2SS (patchOp src) (env dst) CVTSI2SD src dst -> CVTSI2SD (patchOp src) (env dst) FDIV sz src dst -> FDIV sz (patchOp src) (patchOp dst) @@ -563,6 +605,7 @@ patchRegs instr env = case instr of COMMENT _ -> instr DELTA _ -> instr JXX _ _ -> instr + JXX_GBL _ _ -> instr CLTD _ -> instr _other -> panic "patchRegs: unrecognised instr" @@ -644,6 +687,7 @@ patchRegs instr env = case instr of CMP sz reg ri -> CMP sz (env reg) (fixRI ri) CMPL sz reg ri -> CMPL sz (env reg) (fixRI ri) BCC cond lbl -> BCC cond lbl + BCCFAR cond lbl -> BCCFAR cond lbl MTCTR reg -> MTCTR (env reg) BCTR targets -> BCTR targets BL imm argRegs -> BL imm argRegs -- argument regs