If you find a violation, just call ErrorMsg.impossible with an appropriately informative string. The more informative the better, because this will help you debug your coloring algorithm!
The use of the RegSet module makes it very easy to deal with sets of registers. This means you can have an elegant and natural implementation of the algorithm described in Section 11.1 of the textbook.
The heart of your algorithm can be a function like this,
fun f (lowdegs: RS.set, highdegs: RS.set) : coloringwhere lowdegs is the set of nonprecolored registers still in the interference graph that have degree <K, and highdegs is the set of nonprecolored registers still in the interference graph that have degree ≥K. (K is the number of colors in the palette.)
If lowdegs is not empty, apply the Simplify heuristic described on page 229 of the textbook. Instead of "push on a stack", just do a recursive call to the function f. (By the way, choose a better name than f!)
If lowdegs is empty and highdegs is not empty, apply the Spill heuristic described on page 229 of the textbook. Spill the node with the lowest spill cost. Again, instead of "push on a stack" just do a recursive call.
Take into account that Simplify and Spill both modify the degree of existing nodes when making the recursive call.
If both are empty, then return from f and, on the way back out of the deep recursion, colors will be assigned.
DO NOT implement coalescing heuristics. That's another programming assignment entirely; save your ingenuity for that one.
Due date: | Monday, 25 April 2016, 9:00 PM |