2 -- Carries interesting info for debugging / profiling of the
3 -- graph coloring register allocator.
13 #include "nativeGen/NCG.h"
15 import qualified GraphColor as Color
28 { raLiveCmm :: [LiveCmmTop] -- ^ code we tried to allocate regs for
29 , raGraph :: Color.Graph Reg RegClass Reg -- ^ the partially colored graph
30 , raSpillStats :: SpillStats -- ^ spiller stats
31 , raLifetimes :: UniqFM (Reg, Int) } -- ^ number of instrs each reg lives for
33 -- a successful coloring
34 | RegAllocStatsColored
35 { raLiveCmm :: [LiveCmmTop] -- ^ the code we allocated regs for
36 , raGraph :: Color.Graph Reg RegClass Reg -- ^ the colored graph
37 , raPatchedCmm :: [LiveCmmTop] -- ^ code with register allocation
38 , raLifetimes :: UniqFM (Reg, Int) } -- ^ number of instrs each reg lives for
41 instance Outputable RegAllocStats where
43 ppr (s@RegAllocStatsSpill{})
46 $$ text "-- Native code with liveness information."
50 $$ text "-- Register conflict graph."
51 $$ Color.dotGraph regDotColor trivColorable (raGraph s)
53 $$ text "-- Spill statistics."
54 $$ ppr (raSpillStats s)
57 ppr (s@RegAllocStatsColored{})
60 $$ text "-- Native code with liveness information."
64 $$ text "-- Register conflict graph."
65 $$ Color.dotGraph regDotColor trivColorable (raGraph s)
67 $$ text "-- Native code after register allocation."
68 $$ ppr (raPatchedCmm s)
72 binLifetimeCount :: UniqFM (Reg, Int) -> UniqFM (Int, Int)
74 = let lifes = map (\l -> (l, (l, 1)))
79 (\(l1, c1) (l2, c2) -> (l1, c1 + c2))
84 -- Register colors for drawing conflict graphs
85 -- Keep this out of MachRegs.hs because it's specific to the graph coloring allocator.
90 regDotColor :: Reg -> SDoc
92 = let Just str = lookupUFM regColors reg
107 , (fake5, "#5500ff") ]
111 -- reg colors for x86_64
112 #if x86_64_TARGET_ARCH
113 regDotColor :: Reg -> SDoc
115 = let Just str = lookupUFM regColors reg
120 $ [ (rax, "#00ff00"), (eax, "#00ff00")
121 , (rbx, "#0000ff"), (ebx, "#0000ff")
122 , (rcx, "#00ffff"), (ecx, "#00ffff")
123 , (rdx, "#0080ff"), (edx, "#00ffff")
133 ++ zip (map RealReg [16..31]) (repeat "red")
137 -- reg colors for ppc
138 #if powerpc_TARGET_ARCH
139 regDotColor :: Reg -> SDoc
141 = case regClass reg of
142 RcInteger -> text "blue"
143 RcFloat -> text "red"
149 = let rs = padL 2 '0' (showHex r "")
150 gs = padL 2 '0' (showHex r "")
151 bs = padL 2 '0' (showHex r "")
154 = replicate (n - length s) c ++ s
155 in "#" ++ rs ++ gs ++ bs