<strong>Iterated</strong> <strong>Register</strong> <strong>Coalescing</strong> · 323if okColors = {} thenspilledNodes := spilledNodes ∪{n}elsecoloredNodes := coloredNodes ∪{n}let c ∈ okColorscolor[n] :=cforall n ∈ coalescedNodescolor[n] := color[GetAlias(n)]procedure RewriteProgram()Allocate memory locations for each v ∈ spilledNodes,Create a new temporary v i for each definition and each use,In the program (instructions), insert a store after eachdefinition <strong>of</strong> a v i, a fetch before each use <strong>of</strong> a v i.Put all the v i into a set newTemps.spilledNodes := {}initial := coloredNodes ∪ coalescedNodes ∪ newTempscoloredNodes := {}coalescedNodes := {}RewriteProgramWe show a variant <strong>of</strong> the algorithm in which all coalesces are discarded if the programmust be rewritten to incorporate spill fetches and stores. But as Section 5.1explains, we recommend keeping all the coalesces found before the first call toSelectSpill and rewriting the program to eliminate the coalesced move instructionsand temporaries.ACKNOWLEDGMENTSKenneth Zadeck provided many detailed and insightful criticisms and suggestionsabout the algorithm. Steven Walk, Chris Fraser, and Kent Wilken gave us feedbackon an early draft <strong>of</strong> the manuscript. Preston Briggs, Max Hailperin, and LukeBlanshard helpfully commented on later drafts.REFERENCESAppel, A. W. 1992. Compiling with Continuations. Cambridge University Press. Cambridge,England.Appel, A. W. and MacQueen, D. B. 1991. Standard ML <strong>of</strong> New Jersey. In the 3rd InternationalSymposium on Programming Language Implementation and Logic Programming, M.Wirsing,Ed. Springer-Verlag, New York, 1–13.Appel, A. W. and Shao, Z. 1992. Callee-save registers in continuation-passing style. Lisp Symb.Comput. 5, 3, 191–221.Briggs, P. and Torczon, L. 1993. An efficient representation for sparse sets. ACM Lett.Program. Lang. Syst. 2, 1-4 (Mar.-Dec.), 59–69.Briggs, P., Cooper, K. D., and Torczon, L. 1994. Improvements to graph coloring registerallocation. ACM Trans. Program. Lang. Syst. 16, 3 (May), 428–455.Chaitin, G. J. 1982. <strong>Register</strong> allocation and spilling via graph coloring. Proceedings <strong>of</strong> the ACMSIGPLAN ’82 Symposium on Compiler Construction. SIGPLAN Not. 17, 6, 98–105.Chaitin, G. J., Auslander, M. A., Chandra, A. K., Cocke, J., Hopkins, M. E., and Markstein,P. W. 1981. <strong>Register</strong> allocation via coloring. Comput. Lang. 6, 47–57.Chow, F. C. 1988. Minimizing register usage penalty at procedure calls. Proceedings <strong>of</strong> SIGPLAN’88 Conference on Programming Language Design and Implementation. SIGPLAN Not. 23, 7(July), 85–94.ACM Transactions on Programming Languages and Systems, Vol. 18, No. 3, May 1996, Pages 300-324.
324 · Lal George and Andrew AppelCytron, R., Ferrante, J., Rosen, B. K., Wegman, M. N., and Zadeck, F. K. 1991. Efficientlycomputing static single assignment form and the control dependence graph. ACMTrans. Program. Lang. Syst. 13, 4 (Oct.), 451–490.Garey, M. R. and Johnson, D. S. 1979. <strong>Computer</strong>s and Intractability, A Guide to the Theory<strong>of</strong> NP-completeness. W. H. Freeman, New York.Kempe, A. B. 1879. On the geographical problem <strong>of</strong> the four colors. Am.J.Math.2, 193–200.Kranz, D., Kelsey, R., Rees, J., Hudak, P., Philbin, J., and Adams, N. 1986. ORBIT:An optimizing compiler for Scheme. Proceedings <strong>of</strong> the ACM SIGPLAN ’86 Symposium onCompiler Construction. SIGPLAN Not. 21, 7 (July), 219–233.Leroy, X. 1992. Unboxed objects and polymorphic typing. In the 19th Annual ACM Symposiumon Principles <strong>of</strong> Programming Languages. ACM Press, New York, 177–188.Shao, Z. and Appel, A. W. 1994. Space-efficient closure representations. In Proceedings <strong>of</strong> the1994 ACM Conference on Lisp and Functional Programming. ACM Press, New York, 150–161.Shao, Z. and Appel, A. W. 1995. A type-based compiler for Standard ML. In Proceedings <strong>of</strong> the1995 ACM Conference on Programming Language Design and Implementation. ACM Press,New York, 116–129.Received October 1995; accepted February 1996ACM Transactions on Programming Languages and Systems, Vol. 18, No. 3, May 1996, Pages 300-324.