2 module SPARC.ShortcutJump (
3 JumpDest(..), getJumpDestBlockId,
28 getJumpDestBlockId :: JumpDest -> Maybe BlockId
29 getJumpDestBlockId (DestBlockId bid) = Just bid
30 getJumpDestBlockId _ = Nothing
33 canShortcut :: Instr -> Maybe JumpDest
34 canShortcut _ = Nothing
37 shortcutJump :: (BlockId -> Maybe JumpDest) -> Instr -> Instr
38 shortcutJump _ other = other
41 shortcutStatic :: (BlockId -> Maybe JumpDest) -> CmmStatic -> CmmStatic
43 shortcutStatic fn (CmmStaticLit (CmmLabel lab))
44 | Just uq <- maybeAsmTemp lab
45 = CmmStaticLit (CmmLabel (shortBlockId fn (mkBlockId uq)))
47 shortcutStatic fn (CmmStaticLit (CmmLabelDiffOff lbl1 lbl2 off))
48 | Just uq <- maybeAsmTemp lbl1
49 = CmmStaticLit (CmmLabelDiffOff (shortBlockId fn (mkBlockId uq)) lbl2 off)
51 -- slightly dodgy, we're ignoring the second label, but this
52 -- works with the way we use CmmLabelDiffOff for jump tables now.
53 shortcutStatic _ other_static
57 shortBlockId :: (BlockId -> Maybe JumpDest) -> BlockId -> CLabel
58 shortBlockId fn blockid =
60 Nothing -> mkAsmTempLabel (getUnique blockid)
61 Just (DestBlockId blockid') -> shortBlockId fn blockid'
62 Just (DestImm (ImmCLbl lbl)) -> lbl
63 _other -> panic "shortBlockId"