merge GHC HEAD
[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 ), getJumpDestBlockId,
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 getJumpDestBlockId :: JumpDest -> Maybe BlockId
35 getJumpDestBlockId (DestBlockId bid) = Just bid
36 getJumpDestBlockId _                 = Nothing
37
38 canShortcut :: Instr -> Maybe JumpDest
39 canShortcut _ = Nothing
40
41 shortcutJump :: (BlockId -> Maybe JumpDest) -> Instr -> Instr
42 shortcutJump _ other = other
43
44
45 -- Here because it knows about JumpDest
46 shortcutStatic :: (BlockId -> Maybe JumpDest) -> CmmStatic -> CmmStatic
47
48 shortcutStatic fn (CmmStaticLit (CmmLabel lab))
49   | Just uq <- maybeAsmTemp lab 
50   = CmmStaticLit (CmmLabel (shortBlockId fn (mkBlockId uq)))
51
52 shortcutStatic fn (CmmStaticLit (CmmLabelDiffOff lbl1 lbl2 off))
53   | Just uq <- maybeAsmTemp lbl1
54   = CmmStaticLit (CmmLabelDiffOff (shortBlockId fn (mkBlockId uq)) lbl2 off)
55         -- slightly dodgy, we're ignoring the second label, but this
56         -- works with the way we use CmmLabelDiffOff for jump tables now.
57
58 shortcutStatic _ other_static
59         = other_static
60
61 shortBlockId 
62         :: (BlockId -> Maybe JumpDest)
63         -> BlockId
64         -> CLabel
65
66 shortBlockId fn blockid =
67    case fn blockid of
68       Nothing -> mkAsmTempLabel uq
69       Just (DestBlockId blockid')  -> shortBlockId fn blockid'
70       Just (DestImm (ImmCLbl lbl)) -> lbl
71       _other -> panic "shortBlockId"
72    where uq = getUnique blockid
73