+-- | Dump a table of how many spill loads / stores were inserted for each vreg.
+pprStatsSpills
+ :: [RegAllocStats] -> SDoc
+
+pprStatsSpills stats
+ = let -- slurp out the stats from all the spiller stages
+ spillStats = [ s | s@RegAllocStatsSpill{} <- stats]
+
+ -- build a map of how many spill load/stores were inserted for each vreg
+ spillSL = foldl' (plusUFM_C accSpillSL) emptyUFM
+ $ map (spillStoreLoad . raSpillStats) spillStats
+
+ -- print the count of load/spills as a tuple so we can read back from the file easilly
+ pprSpillSL (r, loads, stores)
+ = (parens $ (hcat $ punctuate (text ", ") [doubleQuotes (ppr r), int loads, int stores]))
+
+ -- sum up the total number of spill instructions inserted
+ spillList = eltsUFM spillSL
+ spillTotal = foldl' (\(s1, l1) (s2, l2) -> (s1 + s2, l1 + l2))
+ (0, 0)
+ $ map (\(n, s, l) -> (s, l))
+ $ spillList
+
+ in ( text "-- spills-added-total"
+ $$ text "-- (stores, loads)"
+ $$ (ppr spillTotal)
+ $$ text ""
+ $$ text "-- spills-added"
+ $$ text "-- (reg_name, stores, loads)"
+ $$ (vcat $ map pprSpillSL $ spillList)
+ $$ text "")
+
+
+-- | Dump a table of how long vregs tend to live for in the initial code.
+pprStatsLifetimes
+ :: [RegAllocStats] -> SDoc
+
+pprStatsLifetimes stats
+ = let lifeMap = foldl' plusUFM emptyUFM
+ [ raLifetimes s | s@RegAllocStatsStart{} <- stats ]
+ lifeBins = binLifetimeCount lifeMap
+
+ in ( text "-- vreg-population-lifetimes"
+ $$ text "-- (instruction_count, number_of_vregs_that_lived_that_long)"
+ $$ (vcat $ map ppr $ eltsUFM lifeBins)
+ $$ text "\n")
+