19 #include "nativeGen/NCG.h"
20 #include "HsVersions.h"
32 import Constants ( rESERVED_C_STACK_BYTES )
35 mkVReg :: Unique -> Size -> Reg
37 | not (isFloatSize size) = VirtualRegI u
45 data JumpDest = DestBlockId BlockId | DestImm Imm
48 canShortcut :: Instr -> Maybe JumpDest
49 canShortcut (JXX ALWAYS id) = Just (DestBlockId id)
50 canShortcut (JMP (OpImm imm)) = Just (DestImm imm)
51 canShortcut _ = Nothing
54 shortcutJump :: (BlockId -> Maybe JumpDest) -> Instr -> Instr
55 shortcutJump fn insn@(JXX cc id) =
58 Just (DestBlockId id') -> shortcutJump fn (JXX cc id')
59 Just (DestImm imm) -> shortcutJump fn (JXX_GBL cc imm)
61 shortcutJump _ other = other
66 spillSlotSize = IF_ARCH_i386(12, 8)
69 maxSpillSlots = ((rESERVED_C_STACK_BYTES - 64) `div` spillSlotSize) - 1
71 -- convert a spill slot number to a *byte* offset, with no sign:
72 -- decide on a per arch basis whether you are spilling above or below
73 -- the C stack pointer.
74 spillSlotToOffset :: Int -> Int
75 spillSlotToOffset slot
76 | slot >= 0 && slot < maxSpillSlots
77 = 64 + spillSlotSize * slot
79 = pprPanic "spillSlotToOffset:"
80 ( text "invalid spill location: " <> int slot
81 $$ text "maxSpillSlots: " <> int maxSpillSlots)
84 -- Here because it knows about JumpDest
85 shortcutStatic :: (BlockId -> Maybe JumpDest) -> CmmStatic -> CmmStatic
86 shortcutStatic fn (CmmStaticLit (CmmLabel lab))
87 | Just uq <- maybeAsmTemp lab
88 = CmmStaticLit (CmmLabel (shortBlockId fn (BlockId uq)))
89 shortcutStatic fn (CmmStaticLit (CmmLabelDiffOff lbl1 lbl2 off))
90 | Just uq <- maybeAsmTemp lbl1
91 = CmmStaticLit (CmmLabelDiffOff (shortBlockId fn (BlockId uq)) lbl2 off)
92 -- slightly dodgy, we're ignoring the second label, but this
93 -- works with the way we use CmmLabelDiffOff for jump tables now.
95 shortcutStatic _ other_static
99 :: (BlockId -> Maybe JumpDest)
103 shortBlockId fn blockid@(BlockId uq) =
105 Nothing -> mkAsmTempLabel uq
106 Just (DestBlockId blockid') -> shortBlockId fn blockid'
107 Just (DestImm (ImmCLbl lbl)) -> lbl
108 _other -> panic "shortBlockId"
112 -- reg colors for x86
114 regDotColor :: Reg -> SDoc
116 = let Just str = lookupUFM regColors reg
131 , (fake5, "#5500ff") ]
134 -- reg colors for x86_64
135 #elif x86_64_TARGET_ARCH
136 regDotColor :: Reg -> SDoc
138 = let Just str = lookupUFM regColors reg
143 $ [ (rax, "#00ff00"), (eax, "#00ff00")
144 , (rbx, "#0000ff"), (ebx, "#0000ff")
145 , (rcx, "#00ffff"), (ecx, "#00ffff")
146 , (rdx, "#0080ff"), (edx, "#00ffff")
156 ++ zip (map RealReg [16..31]) (repeat "red")
158 regDotColor :: Reg -> SDoc
159 regDotColor = panic "not defined"