Compilers (CSC-362 98F)

Class 36: Register Allocation

Held Friday, December 4, 1998



Register Allocation

Detour: NP-completeness

Optimistic Graph Coloring

An Example

Here's a graph (a list of edges) to try the algorithm on. We'll try to four-color it. Note that this is a modified version of the graph from Appel.

(A,B), (A,F), (A,G), (B,C), (B,D), (B,E), (B,K), (B,M), (C,M), (D,J), (D,K), (D,M), (E,F), (E,J), (E,M), (F,J), (F,M), (G,H), (G,I), (G,J), (G,K), (H,I), (H,J), (J,K), (J,L), (L,M)

(I haven't given the underlying program. I don't think we'll need to rewrite the program, but it may depend on choices we make.)


The algorithm

function allocReg(program p, regcount k) 
  build the interference graph for p
  build the list of move-pairs 
  while p is nonempty
        remove nodes of arity < k not in move pairs,
          pushing them on the stack
        join nodes in any move pairs if safe to do so
      if (we neither simplified nor coalesced)
          pick some move-pair node with arity < k, and
            remove all move-pairs with that node
    until no changes can be made
    if there are nodes of arity >= k
        remove some node of arity >= k, 
          pushing it on the stack
    end if
  end while
    while there are nodes on the stack
      if some color can be assigned to the top node on
        the stack then assign that color
      otherwise, note that the top node must be spilled
    if some node was spilled during the select phase,
      then update the program and call allocReg again.
end allocReg



Back to Liveness analysis. On to Student presentations.

Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

Source text last modified Fri Dec 4 10:19:09 1998.

This page generated on Fri Dec 4 10:21:15 1998 by SiteWeaver.

Contact our webmaster at