Skip to main content
Log in

Callee-save registers in continuation-passing style

  • Published:
LISP and Symbolic Computation

Abstract

Continuation-passing style (CPS) is a good abstract representation to use for compilation and optimization: it has a clean semantics and is easily manipulated. We examine how CPS expresses the saving and restoring of registers in source-language procedure calls. In most CPS-based compilers, the context of the calling procedure is saved in a “continuation closure”—a single variable that is passed as an argument to the function being called. This closure is a record containing bindings of all the free variables of the continuation; that is, registers that hold values needed by the caller “after the call” are written to memory in the closure, and fetched back after the call.

Consider the procedure-call mechanisms used by conventional compilers. In particular, registers holding values needed after the call must be saved and later restored. The responsibility for saving registers can lie with the caller (a “caller-saves” convention) or with the called function (“callee-saves”). In practice, to optimize memory traffic, compilers find it useful to have some caller-saves registers and some callee-saves.

“Conventional” CPS-based compilers that pass a pointer to a record containing all the variables needed after the call (i.e., the continuation closure), are using a caller-saves convention. We explain how to express callee-save registers in Continuation-Passing Style, and give measurements showing the resulting improvement in execution time.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Similar content being viewed by others

References

  1. Appel, Andrew W. Garbage collection can be faster than stack allocation.Information Processing Letters, 25, 4 (1987) 275–79.

    Google Scholar 

  2. Appel, Andrew W. Simple generational garbage collection and fast allocation.Software—Practice and Experience, 19, 2 (1989) 171–83.

    Google Scholar 

  3. Appel, Andrew W.Compiling with Continuations. Cambridge University Press (1992).

  4. Appel, Andrew W. and Jim, Trevor. Continuation-passing, closure-passing style. InSixteenth ACM Symp. on Principles of Programming Languages, ACM Press, New York (1989) 293–302.

    Google Scholar 

  5. Appel, Andrew W. and MacQueen, David B. A Standard ML compiler. In Kahn, Gilles, editor,Functional Programming Languages and Computer Architecture (LNCS 274), Springer-Verlag, New York (1987) 301–24.

    Google Scholar 

  6. Appel, Andrew W., Ellis, John R., and Li, Kai. Real-time concurrent collection on stock multiprocessors.SIGPLAN Notices (Proc. SIGPLAN '88 Conf. on Prog. Lang. Design and Implementation), 23, 7 (1988) 11–20.

    Google Scholar 

  7. Appel, Andrew W., Mattson, James S., and Tarditi, David R. A lexical analyzer generator for Standard ML. (December 1989). Distributed with Standard ML of New Jersey.

  8. Cardelli, Luca. Compiling a functional language. In1984 Symp. on LISP and Functional Programming, ACM Press, New York (1984) 208–17.

    Google Scholar 

  9. Chow, Fred C. Minimizing register usage penalty at procedure calls. InProc. SIGPLAN '88 Conf. on Prog. Lang. Design and Implementation, ACM Press, New York (June 1988) 85–94.

    Google Scholar 

  10. Cousineau, G., Curien, P. L., and Mauny, M. The categorical abstract machine. In Jouannaud, J. P., editor,Functional Programming Languages and Computer Architecture, LNCS Vol 201, Springer-Verlag, New York (1985) 50–64.

    Google Scholar 

  11. Crowley, W. P., Hendrickson, C. P., and Rudy, T. E.The SIMPLE Code. Technical Report UCID 17715, Lawrence Livermore Laboratory, Livermore, CA (February 1978).

    Google Scholar 

  12. Ekanadham, K. and Arvind.SIMPLE: An Exercise in Future Scientific Programming. Technical Report Computation Structures Group Memo 273, MIT, Cambridge, MA (July 1987). Simultaneously published as IBM/T.J. Watson Research Center Research Report 12686, Yorktown Heights, NY.

    Google Scholar 

  13. Hieb, Robert, Dybvig, R. Kent, and Bruggeman, Carl. Representing control in the presence of first-class continuations. InProc. ACM SIGPLAN '90 Conf. on Prog. Lang. Design and Implementation, ACM Press, New York (1990) 66–77.

    Google Scholar 

  14. Johnsson, Thomas. Lambda lifting: Transforming programs to recursive equations. InThe Second International Conference on Functional Programming Languages and Computer Architecture, Springer-Verlag, New York (September 1985) 190–203.

    Google Scholar 

  15. Kelsey, Richard and Hudak, Paul. Realistic compilation by program transformation. InSixteenth ACM Symp. on Principles of Programming Languages, ACM Press, New York (1989) 281–92.

    Google Scholar 

  16. Kranz, David.ORBIT: An optimizing compiler for Scheme. PhD thesis, Yale University, New Haven, CT (1987).

    Google Scholar 

  17. Kranz, D., Kelsey, R., Rees, J., Hudak, P., Philbin, J., and Adams, N. ORBIT: An optimizing compiler for Scheme.SIGPLAN Notices (Proc. Sigplan '86 Symp. on Compiler Construction), 21, 7 (July 1986) 219–33.

    Google Scholar 

  18. Landin, P. J. The mechanical evaluation of expressions.Computer J., 6, 4 (1964) 308–20.

    Google Scholar 

  19. Reade, Chris.Elements of Functional Programming. Addison-Wesley, Reading, MA (1989).

    Google Scholar 

  20. Steele, Guy L.Rabbit: a compiler for Scheme. Technical Report AI-TR-474, MIT, Cambridge, MA (1978).

    Google Scholar 

  21. Tarditi, David R. and Appel, Andrew W. ML-Yacc, version 2.0. (April 1990). Distributed with Standard ML of New Jersey.

Download references

Author information

Authors and Affiliations

Authors

Additional information

SUPPORTED IN PART BY NSF GRANT CCR-8914570.

Rights and permissions

Reprints and permissions

About this article

Cite this article

Appel, A.W., Shao, Z. Callee-save registers in continuation-passing style. Lisp and Symbolic Computation 5, 191–221 (1992). https://doi.org/10.1007/BF01807505

Download citation

  • Issue Date:

  • DOI: https://doi.org/10.1007/BF01807505

Keywords

Navigation