2 -- | Types for the general graph colorer.
18 -- | A fn to check if a node is trivially colorable
19 -- For graphs who's color classes are disjoint then a node is 'trivially colorable'
20 -- when it has less neighbors and exclusions than available colors for that node.
22 -- For graph's who's color classes overlap, ie some colors alias other colors, then
23 -- this can be a bit more tricky. There is a general way to calculate this, but
24 -- it's likely be too slow for use in the code. The coloring algorithm takes
25 -- a canned function which can be optimised by the user to be specific to the
26 -- specific graph being colored.
28 -- for details, see "A Generalised Algorithm for Graph-Coloring Register Allocation"
29 -- Smith, Ramsey, Holloway - PLDI 2004.
32 = cls -- ^ the class of the node we're trying to color.
33 -> UniqSet k -- ^ the node's neighbors.
34 -> UniqSet color -- ^ the node's exclusions.
38 -- | The Interference graph.
39 -- There used to be more fields, but they were turfed out in a previous revision.
40 -- maybe we'll want more later..
42 data Graph k cls color
44 -- | All active nodes in the graph.
45 graphMap :: UniqFM (Node k cls color) }
50 { graphMap = emptyUFM }
53 -- | Modify the finite map holding the nodes in the graph.
55 :: (UniqFM (Node k cls color) -> UniqFM (Node k cls color))
56 -> Graph k cls color -> Graph k cls color
58 graphMapModify f graph
59 = graph { graphMap = f (graphMap graph) }
64 -- Represents a thing that can conflict with another thing.
65 -- For the register allocater the nodes represent registers.
69 -- | A unique identifier for this node.
72 -- | The class of this node,
73 -- determines the set of colors that can be used.
76 -- | The color of this node, if any.
77 , nodeColor :: Maybe color
79 -- | Neighbors which must be colored differently to this node.
80 , nodeConflicts :: UniqSet k
82 -- | Colors that cannot be used by this node.
83 , nodeExclusions :: UniqSet color
85 -- | Colors that this node would prefer to be, in decending order.
86 , nodePreference :: [color]
88 -- | Neighbors that this node would like to be colored the same as.
89 , nodeCoalesce :: UniqSet k }
93 newNode :: k -> cls -> Node k cls color
99 , nodeConflicts = emptyUniqSet
100 , nodeExclusions = emptyUniqSet
101 , nodePreference = []
102 , nodeCoalesce = emptyUniqSet }