2 -- | Types for the general graph colorer.
19 -- | A fn to check if a node is trivially colorable
20 -- For graphs who's color classes are disjoint then a node is 'trivially colorable'
21 -- when it has less neighbors and exclusions than available colors for that node.
23 -- For graph's who's color classes overlap, ie some colors alias other colors, then
24 -- this can be a bit more tricky. There is a general way to calculate this, but
25 -- it's likely be too slow for use in the code. The coloring algorithm takes
26 -- a canned function which can be optimised by the user to be specific to the
27 -- specific graph being colored.
29 -- for details, see "A Generalised Algorithm for Graph-Coloring Register Allocation"
30 -- Smith, Ramsey, Holloway - PLDI 2004.
33 = cls -- ^ the class of the node we're trying to color.
34 -> UniqSet k -- ^ the node's neighbors.
35 -> UniqSet color -- ^ the node's exclusions.
39 -- | The Interference graph.
40 -- There used to be more fields, but they were turfed out in a previous revision.
41 -- maybe we'll want more later..
43 data Graph k cls color
45 -- | All active nodes in the graph.
46 graphMap :: UniqFM (Node k cls color) }
49 initGraph :: Graph k cls color
52 { graphMap = emptyUFM }
55 -- | Modify the finite map holding the nodes in the graph.
57 :: (UniqFM (Node k cls color) -> UniqFM (Node k cls color))
58 -> Graph k cls color -> Graph k cls color
60 graphMapModify f graph
61 = graph { graphMap = f (graphMap graph) }
66 -- Represents a thing that can conflict with another thing.
67 -- For the register allocater the nodes represent registers.
71 -- | A unique identifier for this node.
74 -- | The class of this node,
75 -- determines the set of colors that can be used.
78 -- | The color of this node, if any.
79 , nodeColor :: Maybe color
81 -- | Neighbors which must be colored differently to this node.
82 , nodeConflicts :: UniqSet k
84 -- | Colors that cannot be used by this node.
85 , nodeExclusions :: UniqSet color
87 -- | Colors that this node would prefer to be, in decending order.
88 , nodePreference :: [color]
90 -- | Neighbors that this node would like to be colored the same as.
91 , nodeCoalesce :: UniqSet k }
95 newNode :: k -> cls -> Node k cls color
100 , nodeColor = Nothing
101 , nodeConflicts = emptyUniqSet
102 , nodeExclusions = emptyUniqSet
103 , nodePreference = []
104 , nodeCoalesce = emptyUniqSet }