Merge in new code generator branch.
[ghc-hetmet.git] / compiler / nativeGen / SPARC / ShortcutJump.hs
1
2 module SPARC.ShortcutJump (
3         JumpDest(..),
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
29 canShortcut :: Instr -> Maybe JumpDest
30 canShortcut _ = Nothing
31
32
33 shortcutJump :: (BlockId -> Maybe JumpDest) -> Instr -> Instr
34 shortcutJump _ other = other
35
36
37 shortcutStatic :: (BlockId -> Maybe JumpDest) -> CmmStatic -> CmmStatic
38
39 shortcutStatic fn (CmmStaticLit (CmmLabel lab))
40         | Just uq <- maybeAsmTemp lab 
41         = CmmStaticLit (CmmLabel (shortBlockId fn (mkBlockId uq)))
42
43 shortcutStatic fn (CmmStaticLit (CmmLabelDiffOff lbl1 lbl2 off))
44         | Just uq <- maybeAsmTemp lbl1
45         = CmmStaticLit (CmmLabelDiffOff (shortBlockId fn (mkBlockId uq)) lbl2 off)
46
47 -- slightly dodgy, we're ignoring the second label, but this
48 -- works with the way we use CmmLabelDiffOff for jump tables now.
49 shortcutStatic _ other_static
50         = other_static
51
52
53 shortBlockId :: (BlockId -> Maybe JumpDest) -> BlockId -> CLabel
54 shortBlockId fn blockid =
55    case fn blockid of
56       Nothing -> mkAsmTempLabel (getUnique blockid)
57       Just (DestBlockId blockid')  -> shortBlockId fn blockid'
58       Just (DestImm (ImmCLbl lbl)) -> lbl
59       _other -> panic "shortBlockId"
60
61
62