Merge in new code generator branch.
[ghc-hetmet.git] / compiler / nativeGen / PPC / RegInfo.hs
1 -----------------------------------------------------------------------------
2 --
3 -- Machine-specific parts of the register allocator
4 --
5 -- (c) The University of Glasgow 1996-2004
6 --
7 -----------------------------------------------------------------------------
8
9 module PPC.RegInfo (
10         JumpDest( DestBlockId ), 
11         canShortcut, 
12         shortcutJump, 
13
14         shortcutStatic
15 )
16
17 where
18
19 #include "nativeGen/NCG.h"
20 #include "HsVersions.h"
21
22 import PPC.Regs
23 import PPC.Instr
24
25 import BlockId
26 import OldCmm
27 import CLabel
28
29 import Outputable
30 import Unique
31
32 data JumpDest = DestBlockId BlockId | DestImm Imm
33
34 canShortcut :: Instr -> Maybe JumpDest
35 canShortcut _ = Nothing
36
37 shortcutJump :: (BlockId -> Maybe JumpDest) -> Instr -> Instr
38 shortcutJump _ other = other
39
40
41 -- Here because it knows about JumpDest
42 shortcutStatic :: (BlockId -> Maybe JumpDest) -> CmmStatic -> CmmStatic
43
44 shortcutStatic fn (CmmStaticLit (CmmLabel lab))
45   | Just uq <- maybeAsmTemp lab 
46   = CmmStaticLit (CmmLabel (shortBlockId fn (mkBlockId uq)))
47
48 shortcutStatic fn (CmmStaticLit (CmmLabelDiffOff lbl1 lbl2 off))
49   | Just uq <- maybeAsmTemp lbl1
50   = 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
54 shortcutStatic _ other_static
55         = other_static
56
57 shortBlockId 
58         :: (BlockId -> Maybe JumpDest)
59         -> BlockId
60         -> CLabel
61
62 shortBlockId fn blockid =
63    case fn blockid of
64       Nothing -> mkAsmTempLabel uq
65       Just (DestBlockId blockid')  -> shortBlockId fn blockid'
66       Just (DestImm (ImmCLbl lbl)) -> lbl
67       _other -> panic "shortBlockId"
68    where uq = getUnique blockid
69