Follow vreg/hreg patch in PPC NCG
[ghc.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,
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 Cmm
27 import CLabel
28
29 import Outputable
30
31 data JumpDest = DestBlockId BlockId | DestImm Imm
32
33 canShortcut :: Instr -> Maybe JumpDest
34 canShortcut _ = Nothing
35
36 shortcutJump :: (BlockId -> Maybe JumpDest) -> Instr -> Instr
37 shortcutJump _ other = other
38
39
40 -- Here because it knows about JumpDest
41 shortcutStatic :: (BlockId -> Maybe JumpDest) -> CmmStatic -> CmmStatic
42
43 shortcutStatic fn (CmmStaticLit (CmmLabel lab))
44 | Just uq <- maybeAsmTemp lab
45 = CmmStaticLit (CmmLabel (shortBlockId fn (BlockId uq)))
46
47 shortcutStatic fn (CmmStaticLit (CmmLabelDiffOff lbl1 lbl2 off))
48 | Just uq <- maybeAsmTemp lbl1
49 = CmmStaticLit (CmmLabelDiffOff (shortBlockId fn (BlockId uq)) lbl2 off)
50 -- slightly dodgy, we're ignoring the second label, but this
51 -- works with the way we use CmmLabelDiffOff for jump tables now.
52
53 shortcutStatic _ other_static
54 = other_static
55
56 shortBlockId
57 :: (BlockId -> Maybe JumpDest)
58 -> BlockId
59 -> CLabel
60
61 shortBlockId fn blockid@(BlockId uq) =
62 case fn blockid of
63 Nothing -> mkAsmTempLabel uq
64 Just (DestBlockId blockid') -> shortBlockId fn blockid'
65 Just (DestImm (ImmCLbl lbl)) -> lbl
66 _other -> panic "shortBlockId"
67