-- record what happened in this stage for debugging
let stat =
RegAllocStatsColored
- { raGraph = graph_colored_lint
- , raCoalesced = rmCoalesce
- , raPatched = code_patched
- , raSpillClean = code_spillclean
- , raFinal = code_final
- , raSRMs = foldl' addSRM (0, 0, 0) $ map countSRMs code_spillclean }
+ { raGraph = graph
+ , raGraphColored = graph_colored_lint
+ , raCoalesced = rmCoalesce
+ , raPatched = code_patched
+ , raSpillClean = code_spillclean
+ , raFinal = code_final
+ , raSRMs = foldl' addSRM (0, 0, 0) $ map countSRMs code_spillclean }
let statList =
-- a successful coloring
| RegAllocStatsColored
- { raGraph :: Color.Graph Reg RegClass Reg -- ^ the colored graph
+ { raGraph :: Color.Graph Reg RegClass Reg -- ^ the uncolored graph
+ , raGraphColored :: Color.Graph Reg RegClass Reg -- ^ the coalesced and colored graph
, raCoalesced :: UniqFM Reg -- ^ the regs that were coaleced
, raPatched :: [LiveCmmTop] -- ^ code with vregs replaced by hregs
, raSpillClean :: [LiveCmmTop] -- ^ code with unneeded spill/reloads cleaned out
ppr (s@RegAllocStatsColored { raSRMs = (spills, reloads, moves) })
= text "# Colored"
- $$ text "# Register conflict graph."
+ $$ text "# Register conflict graph (initial)."
$$ Color.dotGraph regDotColor trivColorable (raGraph s)
$$ text ""
+ $$ text "# Register conflict graph (colored)."
+ $$ Color.dotGraph regDotColor trivColorable (raGraphColored s)
+ $$ text ""
+
$$ (if (not $ isNullUFM $ raCoalesced s)
then text "# Registers coalesced."
$$ (vcat $ map ppr $ ufmToList $ raCoalesced s)
-- if the graph is empty then we're done
| isNullUFM $ graphMap graph
- = (ksTriv, ksSpill, kksCoalesce)
+ = (ksTriv, ksSpill, reverse kksCoalesce)
-- Simplify:
-- Look for trivially colorable nodes.
-- go back to Simplify and see if this frees up more nodes to be trivially colorable.
(graph2, kksCoalesceFound @(_:_))
-> colorScan_spin iterative triv spill graph2
- ksTriv ksSpill (kksCoalesceFound ++ kksCoalesce)
+ ksTriv ksSpill (reverse kksCoalesceFound ++ kksCoalesce)
-- Freeze:
-- nothing could be coalesced (or was triv),
-- less colorable (aggressive coalescing)
-> Triv k cls color
-> Graph k cls color
- -> (Graph k cls color, [(k, k)])
+ -> ( Graph k cls color
+ , [(k, k)]) -- pairs of nodes that were coalesced, in the order that the
+ -- coalescing was applied.
coalesceGraph aggressive triv graph
= coalesceGraph' aggressive triv graph []
-- keep running until there are no more coalesces can be found
in case catMaybes mPairs of
- [] -> (graph', kkPairsAcc)
- pairs -> coalesceGraph' aggressive triv graph' (pairs ++ kkPairsAcc)
+ [] -> (graph', reverse kkPairsAcc)
+ pairs -> coalesceGraph' aggressive triv graph' (reverse pairs ++ kkPairsAcc)
-- | Coalesce this pair of nodes unconditionally / agressively.