751c556f51dc11c13accc1be85865dddf65d282a
[ghc-hetmet.git] / compiler / nativeGen / RegAllocStats.hs
1
2 -- Carries interesting info for debugging / profiling of the 
3 --      graph coloring register allocator.
4
5 module RegAllocStats (
6         RegAllocStats (..),
7         regDotColor
8 )
9
10 where
11
12 #include "nativeGen/NCG.h"
13
14 import qualified GraphColor as Color
15 import RegLiveness
16 import RegSpill
17 import MachRegs
18
19 import Outputable
20 import UniqFM
21
22
23 data RegAllocStats
24
25         -- a spill stage
26         = RegAllocStatsSpill
27         { raLiveCmm     :: [LiveCmmTop]                 -- ^ code we tried to allocate regs for
28         , raGraph       :: Color.Graph Reg RegClass Reg -- ^ the partially colored graph
29         , raSpillStats  :: SpillStats }                 -- ^ spiller stats
30
31         -- a successful coloring
32         | RegAllocStatsColored
33         { raLiveCmm     :: [LiveCmmTop]                 -- ^ the code we allocated regs for
34         , raGraph       :: Color.Graph Reg RegClass Reg -- ^ the colored graph
35         , raPatchedCmm  :: [LiveCmmTop] }               -- ^ code with register allocation
36
37
38 instance Outputable RegAllocStats where
39
40  ppr (s@RegAllocStatsSpill{})
41         = text "-- Spill"
42
43         $$ text "-- Native code with liveness information."
44         $$ ppr (raLiveCmm s)
45         $$ text " "
46
47         $$ text "-- Register conflict graph."
48         $$ Color.dotGraph regDotColor trivColorable (raGraph s)
49
50         $$ text "-- Spill statistics."
51         $$ ppr (raSpillStats s)
52
53
54  ppr (s@RegAllocStatsColored{})
55         = text "-- Colored"
56
57         $$ text "-- Native code with liveness information."
58         $$ ppr (raLiveCmm s)
59         $$ text " "
60
61         $$ text "-- Register conflict graph."
62         $$ Color.dotGraph regDotColor trivColorable (raGraph s)
63
64         $$ text "-- Native code after register allocation."
65         $$ ppr (raPatchedCmm s)
66
67
68 -----
69 -- Register colors for drawing conflict graphs
70 --      Keep this out of MachRegs.hs because it's specific to the graph coloring allocator.
71
72
73 -- reg colors for x86
74 #if i386_TARGET_ARCH
75 regDotColor :: Reg -> SDoc
76 regDotColor reg
77  = let  Just    str     = lookupUFM regColors reg
78    in   text str
79
80 regColors
81  = listToUFM
82  $      [ (eax, "#00ff00")
83         , (ebx, "#0000ff")
84         , (ecx, "#00ffff")
85         , (edx, "#0080ff")
86
87         , (fake0, "#ff00ff")
88         , (fake1, "#ff00aa")
89         , (fake2, "#aa00ff")
90         , (fake3, "#aa00aa")
91         , (fake4, "#ff0055")
92         , (fake5, "#5500ff") ]
93 #endif
94
95
96 -- reg colors for x86_64
97 #if x86_64_TARGET_ARCH
98 regDotColor :: Reg -> SDoc
99 regDotColor reg
100  = let  Just    str     = lookupUFM regColors reg
101    in   text str
102
103 regColors
104  = listToUFM
105  $      [ (rax, "#00ff00"), (eax, "#00ff00")
106         , (rbx, "#0000ff"), (ebx, "#0000ff")
107         , (rcx, "#00ffff"), (ecx, "#00ffff")
108         , (rdx, "#0080ff"), (edx, "#00ffff")
109         , (r8,  "#00ff80")
110         , (r9,  "#008080")
111         , (r10, "#0040ff")
112         , (r11, "#00ff40")
113         , (r12, "#008040")
114         , (r13, "#004080")
115         , (r14, "#004040")
116         , (r15, "#002080") ]
117
118         ++ zip (map RealReg [16..31]) (repeat "red")
119 #endif
120
121
122 -- reg colors for ppc
123 #if powerpc_TARGET_ARCH
124 regDotColor :: Reg -> SDoc
125 regDotColor reg
126  = case regClass reg of
127         RcInteger       -> text "blue"
128         RcFloat         -> text "red"
129 #endif
130
131
132 {-
133 toX11Color (r, g, b)
134  = let  rs      = padL 2 '0' (showHex r "")
135         gs      = padL 2 '0' (showHex r "")
136         bs      = padL 2 '0' (showHex r "")
137
138         padL n c s
139                 = replicate (n - length s) c ++ s
140   in    "#" ++ rs ++ gs ++ bs
141 -}