On further testing it turns out that using Chaitin's spill cost formula
of counting the number of uses of a var and then dividing by the degree
of the node isn't actually a win. Perhaps because this isn't counting
the number of actual spills inserted in the output code.
This would be worth revisiting if other work manages to increase the
register pressure in the native code.
-> Reg
chooseSpill info graph
-> Reg
chooseSpill info graph
- = let cost = spillCost info graph
+ = let cost = spillCost_length info graph
node = minimumBy (\n1 n2 -> compare (cost $ nodeId n1) (cost $ nodeId n2))
$ eltsUFM $ graphMap graph
node = minimumBy (\n1 n2 -> compare (cost $ nodeId n1) (cost $ nodeId n2))
$ eltsUFM $ graphMap graph
-- Without live range splitting, its's better to spill from the outside in so set the cost of very
-- long live ranges to zero
--
-- Without live range splitting, its's better to spill from the outside in so set the cost of very
-- long live ranges to zero
--
:: SpillCostInfo
-> Graph Reg RegClass Reg
-> Reg
-> Float
:: SpillCostInfo
-> Graph Reg RegClass Reg
-> Reg
-> Float
-spillCost info graph reg
+spillCost_chaitin info graph reg
-- Spilling a live range that only lives for 1 instruction isn't going to help
-- us at all - and we definately want to avoid trying to re-spill previously
-- inserted spill code.
-- Spilling a live range that only lives for 1 instruction isn't going to help
-- us at all - and we definately want to avoid trying to re-spill previously
-- inserted spill code.
| otherwise = fromIntegral (uses + defs) / fromIntegral (nodeDegree graph reg)
where (_, defs, uses, lifetime)
= fromMaybe (reg, 0, 0, 0) $ lookupUFM info reg
| otherwise = fromIntegral (uses + defs) / fromIntegral (nodeDegree graph reg)
where (_, defs, uses, lifetime)
= fromMaybe (reg, 0, 0, 0) $ lookupUFM info reg
+-}
+
+-- Just spill the longest live range.
+spillCost_length
+ :: SpillCostInfo
+ -> Graph Reg RegClass Reg
+ -> Reg
+ -> Float
+
+spillCost_length info _ reg
+ | lifetime <= 1 = 1/0
+ | otherwise = 1 / fromIntegral lifetime
+ where (_, _, _, lifetime)
+ = fromMaybe (reg, 0, 0, 0) $ lookupUFM info reg
+
lifeMapFromSpillCostInfo :: SpillCostInfo -> UniqFM (Reg, Int)
lifeMapFromSpillCostInfo :: SpillCostInfo -> UniqFM (Reg, Int)
-- coalescing stage at the front.
(graph_coalesced, kksCoalesce1)
= if not iterative
-- coalescing stage at the front.
(graph_coalesced, kksCoalesce1)
= if not iterative
- then coalesceGraph False triv graph0
+ then coalesceGraph True triv graph0
else (graph0, [])
-- run the scanner to slurp out all the trivially colorable nodes
else (graph0, [])
-- run the scanner to slurp out all the trivially colorable nodes