2 * Takes a interference graph and generates an ordering for coloring
3 * Author: Joshua Wise <jwise@andrew.cmu.edu>
4 * Author: Chris Lu <czl@aundrew.cmu.edu>
9 type igraph = (Temp.temp * x86.oper list) list
10 type ordering = Temp.temp list
12 val colororder : igraph -> ordering
15 structure ColorOrder :> COLORORDER =
20 type igraph = (Temp.temp * x86.oper list) list
21 type ordering = Temp.temp list
23 fun colororder graph =
25 val initialWeights = map (fn (t, _) => (t, 0)) graph
27 fun sortWeights weights = (* Sort the weights such that the largest is at left, ready to be grabbed. *)
28 ListMergeSort.sort (fn ((_, a), (_, b)) => a < b) weights
30 (* Chooses one temporary to pick, and updates the weights. *)
31 fun orderOne (weights : (Temp.temp * int) list) : Temp.temp * (Temp.temp * int) list =
33 val sorted = sortWeights weights
34 val (chosen, w) = List.hd sorted (* Grab the temp with the highest weight. *)
35 val remaining = List.tl sorted
36 val neighbors = (* Grab all the neighbors for some given temp. *)
38 (List.map (fn (_, neighbors) => neighbors)
39 (List.filter (fn (t, _) => T.compare (t, chosen) = EQUAL) graph))
45 (fn X.TEMP t' => (T.compare (t, t') = EQUAL)
56 (* Recursively order until we run out of things to order. *)
57 fun keepOrdering (nil : (Temp.temp * int) list) : Temp.temp list = nil
58 | keepOrdering (weights) =
60 val (chosen, newWeights) = orderOne weights
62 chosen :: (keepOrdering newWeights)
65 (keepOrdering initialWeights)