ShortcutJump.hs 2.13 KB
Newer Older
1

Ian Lynagh's avatar
Ian Lynagh committed
2 3 4 5 6 7 8
{-# OPTIONS -fno-warn-tabs #-}
-- The above warning supression flag is a temporary kludge.
-- While working on this module you are encouraged to remove it and
-- detab the module (please do the detabbing in a separate patch). See
--     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces
-- for details

9
module SPARC.ShortcutJump (
10
	JumpDest(..), getJumpDestBlockId,
11 12
	canShortcut,
	shortcutJump,
13
	shortcutStatics,
14 15 16 17 18 19 20 21 22 23
	shortBlockId
)

where

import SPARC.Instr
import SPARC.Imm

import CLabel
import BlockId
24
import OldCmm
25 26

import Panic
27
import Unique
28 29 30 31 32 33 34



data JumpDest 
	= DestBlockId BlockId 
	| DestImm Imm

35 36 37 38
getJumpDestBlockId :: JumpDest -> Maybe BlockId
getJumpDestBlockId (DestBlockId bid) = Just bid
getJumpDestBlockId _                 = Nothing

39 40 41 42 43 44 45 46 47 48

canShortcut :: Instr -> Maybe JumpDest
canShortcut _ = Nothing


shortcutJump :: (BlockId -> Maybe JumpDest) -> Instr -> Instr
shortcutJump _ other = other



49 50 51 52 53
shortcutStatics :: (BlockId -> Maybe JumpDest) -> CmmStatics -> CmmStatics
shortcutStatics fn (Statics lbl statics)
  = Statics lbl $ map (shortcutStatic fn) statics
  -- we need to get the jump tables, so apply the mapping to the entries
  -- of a CmmData too.
54

55 56 57 58
shortcutLabel :: (BlockId -> Maybe JumpDest) -> CLabel -> CLabel
shortcutLabel fn lab
  | Just uq <- maybeAsmTemp lab = shortBlockId fn (mkBlockId uq)
  | otherwise                   = lab
59

60 61 62 63 64
shortcutStatic :: (BlockId -> Maybe JumpDest) -> CmmStatic -> CmmStatic
shortcutStatic fn (CmmStaticLit (CmmLabel lab))
	= CmmStaticLit (CmmLabel (shortcutLabel fn lab))
shortcutStatic fn (CmmStaticLit (CmmLabelDiffOff lbl1 lbl2 off))
	= CmmStaticLit (CmmLabelDiffOff (shortcutLabel fn lbl1) lbl2 off)
65 66 67 68 69 70 71
-- slightly dodgy, we're ignoring the second label, but this
-- works with the way we use CmmLabelDiffOff for jump tables now.
shortcutStatic _ other_static
        = other_static


shortBlockId :: (BlockId -> Maybe JumpDest) -> BlockId -> CLabel
72
shortBlockId fn blockid =
73
   case fn blockid of
74
      Nothing -> mkAsmTempLabel (getUnique blockid)
75 76 77 78 79 80
      Just (DestBlockId blockid')  -> shortBlockId fn blockid'
      Just (DestImm (ImmCLbl lbl)) -> lbl
      _other -> panic "shortBlockId"