Register Allocation: What Does the NP-Completeness Proof of Chaitin et al. Really Prove? Or Revisiting Register Allocation: Why and How

  • Florent Bouchez
  • Alain Darte
  • Christophe Guillon
  • Fabrice Rastello
Part of the Lecture Notes in Computer Science book series (LNCS, volume 4382)


Register allocation is one of the most studied problems in compilation. It is considered NP-complete since Chaitin et al., in 1981, modeled the problem of assigning temporary variables to k machine registers as the problem of coloring, with k colors, the interference graph associated to the variables. The fact that this graph can be arbitrary proves the NP-completeness of this formulation. However, this original proof does not really show where the complexity of register allocation comes from. Recently, the re-discovery that interference graphs of SSA programs can be colored in polynomial time raised the question: Can we use SSA to do register allocation in polynomial time, without contradicting Chaitin et al’s NP-completeness result? To address this question and, more generally, the complexity of register allocation, we revisit Chaitin et al’s proof to identify the interactions between spilling (load/store insertion), coalescing/splitting (removal/insertion of register moves), critical edges (property of the control flow), and coloring (assignment to registers). In particular, we show that, in general, it is easy to decide if temporary variables can be assigned to k registers or if some spilling is necessary. In other words, the real complexity does not come from the coloring itself (as a misinterpretation Chaitin et al’s proof may suggest) but comes from critical edges and from the optimizations of spilling and coalescing.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Appel, A.W., George, L.: Optimal spilling for CISC machines with few registers. In: Proceedings of PLDI’01, Snowbird, Utah, USA, June 2001, pp. 243–253. ACM Press, Snowbird (2001)Google Scholar
  2. 2.
    Bouchez, F., et al.: Register allocation and spill complexity under SSA. Technical Report RR2005-33, LIP, ENS-Lyon, France, (Aug. 2005)Google Scholar
  3. 3.
    Bouchez, F., et al.: On the complexity of register coalescing. Technical Report RR2006-15, LIP, ENS-Lyon, France (Apr. 2006)Google Scholar
  4. 4.
    Briggs, P., Cooper, K., Torczon, L.: Improvements to graph coloring register allocation. ACM Transactions on Programming Languages and Systems 16(3), 428–455 (1994)CrossRefGoogle Scholar
  5. 5.
    Briggs, P., et al.: Practical improvements to the construction and destruction of static single assignment form. Software: Practice and Experience 28(8), 859–881 (1998)CrossRefGoogle Scholar
  6. 6.
    Brisk, P., et al.: Polynomial time graph coloring register allocation. In: 14th International Workshop on Logic and Synthesis, June (2005)Google Scholar
  7. 7.
    Budimlić, Z., et al.: Fast copy coalescing and live range identification. In: Proc. of PLDI’02, pp. 25–32. ACM Press, New York (2002)Google Scholar
  8. 8.
    Chaitin, G.J.: Register allocation & spilling via graph coloring. SIGPLAN Notices, Proceedings of Compiler Construction (CC’82) 17(6), 98–105 (1982)CrossRefMathSciNetGoogle Scholar
  9. 9.
    Chaitin, G.J., et al.: Register allocation via coloring. Computer Languages 6, 47–57 (1981)CrossRefGoogle Scholar
  10. 10.
    Cooper, K.D., Simpson, L.T.: Live range splitting in a graph coloring register allocator. In: Koskimies, K. (ed.) CC 1998 and ETAPS 1998. LNCS, vol. 1383, pp. 174–187. Springer, Heidelberg (1998)CrossRefGoogle Scholar
  11. 11.
    Cytron, R., Ferrante, J.: What’s in a name? Or the value of renaming for parallelism detection and storage allocation. In: Proceedings of the 1987 International Conference on Parallel Processing, Aug. 1987, pp. 19–27. IEEE Computer Society Press, Los Alamitos (1987)Google Scholar
  12. 12.
    Cytron, R., et al.: Efficiently computing static single assignment form and the control dependence graph. ACM Transactions on Programming Languages and Systems 13(4), 451–490 (1991)CrossRefGoogle Scholar
  13. 13.
    Darte, A., Rastello, F.: Personal communication with Benoît Dupont de Dinechin, Jeanne Ferrante, and Christophe Guillon (2002)Google Scholar
  14. 14.
    Farach-Colton, M., Liberatore, V.: On local register allocation. Journal of Algorithms 37(1), 37–65 (2000)MATHCrossRefMathSciNetGoogle Scholar
  15. 15.
    Garey, M.R., Johnson, D.S.: Computers and Intractability: A Guide to the Theory of NP-Completeness. W.H. Freeman and Company, New York (1979)MATHGoogle Scholar
  16. 16.
    Garey, M.R., et al.: The complexity of coloring circular arcs and chords. SIAM J. of Algebr. Discrete Methods 1(2), 216–227 (1980)MATHCrossRefMathSciNetGoogle Scholar
  17. 17.
    George, L., Appel, A.W.: Iterated register coalescing. ACM Transactions on Programming Languages and Systems 18(3), 300–324 (1996)CrossRefGoogle Scholar
  18. 18.
    Golumbic, M.C.: Algorithmic Graph Theory and Perfect Graphs. Academic Press, New York (1980)MATHGoogle Scholar
  19. 19.
    Hack, S., Grund, D., Goos, G.: Register allocation for programs in SSA-form. In: Mycroft, A., Zeller, A. (eds.) CC 2006 and ETAPS 2006. LNCS, vol. 3923, Springer, Heidelberg (2006)CrossRefGoogle Scholar
  20. 20.
    Knobe, K., Zadeck, K.: Register allocation using control trees. Technical Report No. CS-92-13, Brown University (1992)Google Scholar
  21. 21.
    Leung, A., George, L.: Static single assignment form for machine code. In: Proceedings of PLDI’99, pp. 204–214. ACM Press, New York (1999)Google Scholar
  22. 22.
    Liberatore, V., Farach-Colton, M., Kremer, U.: Evaluation of algorithms for local register allocation. In: Jähnichen, S. (ed.) CC 1999 and ETAPS 1999. LNCS, vol. 1575, pp. 137–152. Springer, Heidelberg (1999)Google Scholar
  23. 23.
    Lueh, G.-Y., Gross, T., Adl-Tabatabai, A.-R.: Fusion-based register allocation. ACM Transactions on Programming Languages and Systems 22(3), 431–470 (2000)CrossRefGoogle Scholar
  24. 24.
    Park, J., Moon, S.-M.: Optimistic register coalescing. In: Proceedings of PACT’98, pp. 196–204. IEEE Computer Society Press, Los Alamitos (1998)Google Scholar
  25. 25.
    Pereira, F.M.Q., Palsberg, J.: Register allocation via coloring of chordal graphs. In: Yi, K. (ed.) APLAS 2005. LNCS, vol. 3780, pp. 315–329. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  26. 26.
    Pereira, F.M.Q., Palsberg, J.: Register allocation after classical SSA elimination is NP-complete. In: Aceto, L., Ingólfsdóttir, A. (eds.) FOSSACS 2006 and ETAPS 2006. LNCS, vol. 3921, Springer, Heidelberg (2006)CrossRefGoogle Scholar
  27. 27.
    Rastello, F., de Ferrière, F., Guillon, C.: Optimizing translation out of SSA using renaming constraints. In: Proceedings of CGO’04, pp. 265–278. IEEE Computer Society Press, Los Alamitos (2004)Google Scholar
  28. 28.
    Sreedhar, V.C., et al.: Translating out of static single assignment form. In: Cortesi, A., Filé, G. (eds.) SAS 1999. LNCS, vol. 1694, pp. 194–210. Springer, Heidelberg (1999)CrossRefGoogle Scholar

Copyright information

© Springer Berlin Heidelberg 2007

Authors and Affiliations

  • Florent Bouchez
    • 1
  • Alain Darte
    • 1
  • Christophe Guillon
    • 2
  • Fabrice Rastello
    • 1
  1. 1.LIP, UMR CNRS-ENS Lyon-UCB Lyon-INRIA 5668France
  2. 2.Compiler Group, ST/HPC/STS GrenobleFrance

Personalised recommendations