Whitespace only in nativeGen/RegAlloc/Graph/TrivColorable.hs
[ghc-hetmet.git] / compiler / nativeGen / SPARC / ShortcutJump.hs
1
2 module SPARC.ShortcutJump (
3         JumpDest(..), getJumpDestBlockId,
4         canShortcut,
5         shortcutJump,
6         shortcutStatic,
7         shortBlockId
8 )
9
10 where
11
12 import SPARC.Instr
13 import SPARC.Imm
14
15 import CLabel
16 import BlockId
17 import OldCmm
18
19 import Panic
20 import Unique
21
22
23
24 data JumpDest 
25         = DestBlockId BlockId 
26         | DestImm Imm
27
28 getJumpDestBlockId :: JumpDest -> Maybe BlockId
29 getJumpDestBlockId (DestBlockId bid) = Just bid
30 getJumpDestBlockId _                 = Nothing
31
32
33 canShortcut :: Instr -> Maybe JumpDest
34 canShortcut _ = Nothing
35
36
37 shortcutJump :: (BlockId -> Maybe JumpDest) -> Instr -> Instr
38 shortcutJump _ other = other
39
40
41 shortcutStatic :: (BlockId -> Maybe JumpDest) -> CmmStatic -> CmmStatic
42
43 shortcutStatic fn (CmmStaticLit (CmmLabel lab))
44         | Just uq <- maybeAsmTemp lab 
45         = CmmStaticLit (CmmLabel (shortBlockId fn (mkBlockId uq)))
46
47 shortcutStatic fn (CmmStaticLit (CmmLabelDiffOff lbl1 lbl2 off))
48         | Just uq <- maybeAsmTemp lbl1
49         = CmmStaticLit (CmmLabelDiffOff (shortBlockId fn (mkBlockId uq)) lbl2 off)
50
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
54         = other_static
55
56
57 shortBlockId :: (BlockId -> Maybe JumpDest) -> BlockId -> CLabel
58 shortBlockId fn blockid =
59    case fn blockid of
60       Nothing -> mkAsmTempLabel (getUnique blockid)
61       Just (DestBlockId blockid')  -> shortBlockId fn blockid'
62       Just (DestImm (ImmCLbl lbl)) -> lbl
63       _other -> panic "shortBlockId"
64
65
66