HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleghc-9.10.3GHC2021

GHC.Data.Graph.Ops

Basic operations on graphs.

  • 24 values
  • Packageghc-9.10.3
  • Exports24
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceOps.hs
valuegetNode :: Uniquable k => Graph k cls color -> k -> Node k cls color
#

Get a node from the graph, throwing an error if it's not there

valuesize :: Graph k cls color -> Int
#

Get the size of the graph, O(n)

valueunion :: Graph k cls color -> Graph k cls color -> Graph k cls color
#

Union two graphs together.

valueaddConflict
  1. :: Uniquable k
  2. => (k, cls)
  3. -> (k, cls)
  4. -> Graph k cls color
  5. -> Graph k cls color
#

Add a conflict between nodes to the graph, creating the nodes required. Conflicts are virtual regs which need to be colored differently.

valueaddConflicts
  1. :: Uniquable k
  2. => UniqSet k
  3. -> k -> cls
  4. -> Graph k cls color
  5. -> Graph k cls color
#

Add some conflicts to the graph, creating nodes if required. All the nodes in the set are taken to conflict with each other.

valueaddCoalesce
  1. :: Uniquable k
  2. => (k, cls)
  3. -> (k, cls)
  4. -> Graph k cls color
  5. -> Graph k cls color
#

Add a coalescence edge to the graph, creating nodes if required. It is considered advantageous to assign the same color to nodes in a coalescence.

valueaddExclusion
  1. :: (Uniquable k, Uniquable color)
  2. => k
  3. -> k -> cls
  4. -> color
  5. -> Graph k cls color
  6. -> Graph k cls color
#

Add an exclusion to the graph, creating nodes if required. These are extra colors that the node cannot use.

valueaddPreference
  1. :: Uniquable k
  2. => (k, cls)
  3. -> color
  4. -> Graph k cls color
  5. -> Graph k cls color
#

Add a color preference to the graph, creating nodes if required. The most recently added preference is the most preferred. The algorithm tries to assign a node it's preferred color if possible.

valuecoalesceNodes
  1. :: (Uniquable k, Ord k, Eq cls)
  2. => Bool

    If True, coalesce nodes even if this might make the graph less colorable (aggressive coalescing)

  3. -> Triv k cls color
  4. -> Graph k cls color
  5. -> (k, k)

    keys of the nodes to be coalesced

  6. -> (Graph k cls color, Maybe (k, k))
#

Coalesce this pair of nodes unconditionally / aggressively. The resulting node is the one with the least key.

returns: Just the pair of keys if the nodes were coalesced the second element of the pair being the least one

Nothing if either of the nodes weren't in the graph

valuecoalesceGraph
  1. :: (Uniquable k, Ord k, Eq cls, Outputable k)
  2. => Bool

    If True, coalesce nodes even if this might make the graph less colorable (aggressive coalescing)

  3. -> Triv k cls color
  4. -> Graph k cls color
  5. -> (Graph k cls color, [(k, k)])
#

Do aggressive coalescing on this graph. returns the new graph and the list of pairs of nodes that got coalesced together. for each pair, the resulting node will have the least key and be second in the pair.

valuefreezeNode
  1. :: Uniquable k
  2. => k

    key of the node to freeze

  3. -> Graph k cls color

    the graph

  4. -> Graph k cls color

    graph with that node frozen

#

Freeze a node This is for the iterative coalescer. By freezing a node we give up on ever coalescing it. Move all its coalesce edges into the frozen set - and update back edges from other nodes.

valuefreezeOneInGraph
  1. :: Uniquable k
  2. => Graph k cls color
  3. -> (Graph k cls color, Bool)
#

Freeze one node in the graph This if for the iterative coalescer. Look for a move related node of low degree and freeze it.

We probably don't need to scan the whole graph looking for the node of absolute lowest degree. Just sample the first few and choose the one with the lowest degree out of those. Also, we don't make any distinction between conflicts of different classes.. this is just a heuristic, after all.

IDEA: freezing a node might free it up for Simplify.. would be good to check for triv right here, and add it to a worklist if known triv/non-move nodes.

valuescanGraph
  1. :: Node k cls color -> Bool
  2. -> Graph k cls color
  3. -> [Node k cls color]
#

Find all the nodes in the graph that meet some criteria

valuevalidateGraph
  1. :: (Uniquable k, Outputable k, Eq color)
  2. => SDoc

    extra debugging info to display on error

  3. -> Bool

    whether this graph is supposed to be colored.

  4. -> Graph k cls color

    graph to validate

  5. -> Graph k cls color

    validated graph

#

validate the internal structure of a graph all its edges should point to valid nodes If they don't then throw an error