NCG: Split RegAllocInfo into arch specific modules
[ghc-hetmet.git] / compiler / nativeGen / RegAllocInfo.hs
1 {-# OPTIONS -w #-}
2 -- The above warning supression flag is a temporary kludge.
3 -- While working on this module you are encouraged to remove it and fix
4 -- any warnings in the module. See
5 --     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
6 -- for details
7
8 -----------------------------------------------------------------------------
9 --
10 -- Machine-specific parts of the register allocator
11 --
12 -- (c) The University of Glasgow 1996-2004
13 --
14 -----------------------------------------------------------------------------
15
16
17 module RegAllocInfo (
18         -- shared code
19         shortcutStatic,
20         
21         -- machine specific 
22         RegUsage(..),
23         noUsage,
24         regUsage,
25         patchRegs,
26         jumpDests,
27         isJumpish,
28         patchJump,
29         isRegRegMove,
30
31         JumpDest, 
32         canShortcut, 
33         shortcutJump, 
34
35         mkSpillInstr,
36         mkLoadInstr,
37         mkRegRegMoveInstr,
38         mkBranchInstr,
39
40         maxSpillSlots,
41         spillSlotToOffset
42     ) where
43
44 #include "nativeGen/NCG.h"
45 #include "HsVersions.h"
46
47 import BlockId
48 import Cmm
49 import CLabel
50 import Instrs
51 import Regs
52 import Outputable
53 import Constants        ( rESERVED_C_STACK_BYTES )
54 import FastBool
55
56 #if   alpha_TARGET_ARCH
57 import Alpha.RegInfo
58
59 #elif i386_TARGET_ARCH || x86_64_TARGET_ARCH
60 import X86.RegInfo
61
62 #elif powerpc_TARGET_ARCH
63 import PPC.RegInfo
64
65 #elif sparc_TARGET_ARCH
66 import SPARC.RegInfo
67
68 #endif
69
70
71 -- Here because it knows about JumpDest
72 shortcutStatic :: (BlockId -> Maybe JumpDest) -> CmmStatic -> CmmStatic
73 shortcutStatic fn (CmmStaticLit (CmmLabel lab))
74   | Just uq <- maybeAsmTemp lab 
75   = CmmStaticLit (CmmLabel (shortBlockId fn (BlockId uq)))
76 shortcutStatic fn (CmmStaticLit (CmmLabelDiffOff lbl1 lbl2 off))
77   | Just uq <- maybeAsmTemp lbl1
78   = CmmStaticLit (CmmLabelDiffOff (shortBlockId fn (BlockId uq)) lbl2 off)
79         -- slightly dodgy, we're ignoring the second label, but this
80         -- works with the way we use CmmLabelDiffOff for jump tables now.
81 shortcutStatic fn other_static
82         = other_static
83
84 shortBlockId fn blockid@(BlockId uq) =
85    case fn blockid of
86       Nothing -> mkAsmTempLabel uq
87       Just (DestBlockId blockid')  -> shortBlockId fn blockid'
88       Just (DestImm (ImmCLbl lbl)) -> lbl
89       _other -> panic "shortBlockId"
90
91
92
93
94