2 -----------------------------------------------------------------------------
4 -- Machine-specific parts of the register allocator
6 -- (c) The University of Glasgow 1996-2004
8 -----------------------------------------------------------------------------
10 module SPARC.RegInfo (
34 import Constants (wORD_SIZE)
42 -- | Make a virtual reg with this size.
43 mkVReg :: Unique -> Size -> Reg
45 | not (isFloatSize size)
55 -- | Check if a RI represents a zero value.
57 -- - register %g0, which is always zero.
60 riZero (RIImm (ImmInt 0)) = True
61 riZero (RIImm (ImmInteger 0)) = True
62 riZero (RIReg (RealReg 0)) = True
66 -- | Calculate the effective address which would be used by the
67 -- corresponding fpRel sequence. fpRel is in MachRegs.lhs,
68 -- alas -- can't have fpRelEA here because of module dependencies.
69 fpRelEA :: Int -> Reg -> Instr
71 = ADD False False fp (RIImm (ImmInt (n * wORD_SIZE))) dst
74 -- | Code to shift the stack pointer by n words.
75 moveSp :: Int -> Instr
77 = ADD False False sp (RIImm (ImmInt (n * wORD_SIZE))) sp
80 -- | Produce the second-half-of-a-double register given the first half.
81 fPair :: Reg -> Maybe Reg
83 | n >= 32 && n `mod` 2 == 0 = Just (RealReg (n+1))
86 = Just (VirtualRegHi u)
89 = trace ("MachInstrs.fPair: can't get high half of supposed double reg ")
92 -- Here because it knows about JumpDest
93 shortcutStatic :: (BlockId -> Maybe JumpDest) -> CmmStatic -> CmmStatic
94 shortcutStatic fn (CmmStaticLit (CmmLabel lab))
95 | Just uq <- maybeAsmTemp lab
96 = CmmStaticLit (CmmLabel (shortBlockId fn (BlockId uq)))
97 shortcutStatic fn (CmmStaticLit (CmmLabelDiffOff lbl1 lbl2 off))
98 | Just uq <- maybeAsmTemp lbl1
99 = CmmStaticLit (CmmLabelDiffOff (shortBlockId fn (BlockId uq)) lbl2 off)
100 -- slightly dodgy, we're ignoring the second label, but this
101 -- works with the way we use CmmLabelDiffOff for jump tables now.
102 shortcutStatic _ other_static
105 shortBlockId :: (BlockId -> Maybe JumpDest) -> BlockId -> CLabel
106 shortBlockId fn blockid@(BlockId uq) =
108 Nothing -> mkAsmTempLabel uq
109 Just (DestBlockId blockid') -> shortBlockId fn blockid'
110 Just (DestImm (ImmCLbl lbl)) -> lbl
111 _other -> panic "shortBlockId"
114 regDotColor :: Reg -> SDoc
116 = case regClass reg of
117 RcInteger -> text "blue"
118 RcFloat -> text "red"
119 RcDouble -> text "green"
123 data JumpDest = DestBlockId BlockId | DestImm Imm
125 canShortcut :: Instr -> Maybe JumpDest
126 canShortcut _ = Nothing
128 shortcutJump :: (BlockId -> Maybe JumpDest) -> Instr -> Instr
129 shortcutJump _ other = other