ShortcutJump.hs 1.81 KB
Newer Older
1 2

module SPARC.ShortcutJump (
3
	JumpDest(..), getJumpDestBlockId,
4 5
	canShortcut,
	shortcutJump,
6
	shortcutStatics,
7 8 9 10 11 12 13 14 15 16
	shortBlockId
)

where

import SPARC.Instr
import SPARC.Imm

import CLabel
import BlockId
17
import OldCmm
18 19

import Panic
20
import Unique
21 22 23 24 25 26 27



data JumpDest 
	= DestBlockId BlockId 
	| DestImm Imm

28 29 30 31
getJumpDestBlockId :: JumpDest -> Maybe BlockId
getJumpDestBlockId (DestBlockId bid) = Just bid
getJumpDestBlockId _                 = Nothing

32 33 34 35 36 37 38 39 40 41

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


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



42 43 44 45 46
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.
47

48 49 50 51
shortcutLabel :: (BlockId -> Maybe JumpDest) -> CLabel -> CLabel
shortcutLabel fn lab
  | Just uq <- maybeAsmTemp lab = shortBlockId fn (mkBlockId uq)
  | otherwise                   = lab
52

53 54 55 56 57
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)
58 59 60 61 62 63 64
-- 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
65
shortBlockId fn blockid =
66
   case fn blockid of
67
      Nothing -> mkAsmTempLabel (getUnique blockid)
68 69 70 71 72 73
      Just (DestBlockId blockid')  -> shortBlockId fn blockid'
      Just (DestImm (ImmCLbl lbl)) -> lbl
      _other -> panic "shortBlockId"