2 -- | Types for the general graph colorer.
20 -- | A fn to check if a node is trivially colorable
21 -- For graphs who's color classes are disjoint then a node is 'trivially colorable'
22 -- when it has less neighbors and exclusions than available colors for that node.
24 -- For graph's who's color classes overlap, ie some colors alias other colors, then
25 -- this can be a bit more tricky. There is a general way to calculate this, but
26 -- it's likely be too slow for use in the code. The coloring algorithm takes
27 -- a canned function which can be optimised by the user to be specific to the
28 -- specific graph being colored.
30 -- for details, see "A Generalised Algorithm for Graph-Coloring Register Allocation"
31 -- Smith, Ramsey, Holloway - PLDI 2004.
34 = cls -- ^ the class of the node we're trying to color.
35 -> UniqSet k -- ^ the node's neighbors.
36 -> UniqSet color -- ^ the node's exclusions.
40 -- | The Interference graph.
41 -- There used to be more fields, but they were turfed out in a previous revision.
42 -- maybe we'll want more later..
44 data Graph k cls color
46 -- | All active nodes in the graph.
47 graphMap :: UniqFM (Node k cls color) }
51 initGraph :: Graph k cls color
54 { graphMap = emptyUFM }
57 -- | Modify the finite map holding the nodes in the graph.
59 :: (UniqFM (Node k cls color) -> UniqFM (Node k cls color))
60 -> Graph k cls color -> Graph k cls color
62 graphMapModify f graph
63 = graph { graphMap = f (graphMap graph) }
68 -- Represents a thing that can conflict with another thing.
69 -- For the register allocater the nodes represent registers.
73 -- | A unique identifier for this node.
76 -- | The class of this node,
77 -- determines the set of colors that can be used.
80 -- | The color of this node, if any.
81 , nodeColor :: Maybe color
83 -- | Neighbors which must be colored differently to this node.
84 , nodeConflicts :: UniqSet k
86 -- | Colors that cannot be used by this node.
87 , nodeExclusions :: UniqSet color
89 -- | Colors that this node would prefer to be, in decending order.
90 , nodePreference :: [color]
92 -- | Neighbors that this node would like to be colored the same as.
93 , nodeCoalesce :: UniqSet k }
97 newNode :: k -> cls -> Node k cls color
102 , nodeColor = Nothing
103 , nodeConflicts = emptyUniqSet
104 , nodeExclusions = emptyUniqSet
105 , nodePreference = []
106 , nodeCoalesce = emptyUniqSet }