Register allocation via coloring of chordal graphs

  • Authors:
  • Jens Palsberg

  • Affiliations:
  • University of California, Los Angeles

  • Venue:
  • CATS '07 Proceedings of the thirteenth Australasian symposium on Theory of computing - Volume 65
  • Year:
  • 2007

Quantified Score

Hi-index 0.00

Visualization

Abstract

A revolution in register allocation is going on right now: compared to the state of the art, the new register allocators are much simpler and generate code of equivalent quality. In 2005, Bouchez, Brisk et al., and Hack independently discovered that if a program is in static-single assignment (SSA) form, then a core register allocation problem can be solved in polynomial time. Many compilers and virtual machines represent programs in SSA form internally, including gcc version 4.0, Sun Microsystem's Java HotSpot Virtual Machine, and IBM's Java virtual machine Jikes RVM. A compiler can translate any program to SSA form in polynomial time, and amazingly thereby change the register allocation problem from NP-complete to polynomial time; the reason is that the transformation may change the need for registers. Luckily, the program in SSA form needs a number of registers which is the same or smaller than that of the original program. We have a win-win situation here: translating to SSA form changes an NP-complete problem to a simple polynomial-time problem and it decreases the need for registers. The key insight is that a program in SSA form has a chordal interference graph. A greedy algorithm can optimally color a chordal graph in linear time in the number of edges. Completing the picture, Hack et al. have presented a new SSA-elimination algorithm that does not demand extra registers. The combined result is a simple, optimal, polynomial-time algorithm for a core register allocation problem. The new SSA-elimination algorithm of Hack et al. is essential because classical SSA elimination leads to an NP-complete core register allocation problem, as shown by Palsberg and Pereira. Register allocation with spilling for SSA form remains NP-complete. We can get most of the advantages of SSA form without actually transforming to SSA form: a vast majority of realistic benchmark programs have chordal interference graphs. For example, 95% of the methods in the Java 1.5 library have chordal interference graphs when compiled with the JoeQ compiler. Pereira and Palsberg have shown how to add simple heuristics for spilling and coalescing to the greedy coloring algorithm. The result is a simple and efficient register allocation algorithm which compares well with the iterated register coalescing algorithm of George and Appel.