Optimizing the stack size of recursive functions

For memory constrained environments, optimization for program size is often as important as, if not more important than, optimization for execution speed. Commonly, compilers try to reduce the code segment but neglect the stack segment, although the stack can significantly grow during the execution of recursive functions because a separate activation record is required for each recursive call. If a formal parameter or local variable is dead at all recursive calls, then it can be declared global so that only one instance exists independent of the recursion depth. We found that in 70% of our benchmark functions, it is possible to reduce the stack size by declaring formal parameters and local variables global. Often, live ranges of formal parameters and local variables can be split at recursive calls through program transformations. These splitting transformations allowed us to further optimize the stack size of all our benchmark functions. If all formal parameters and local variables can be declared global, then such functions may be transformable into iterations. This was possible for all such benchmark functions.

[1]  Michael F. P. O'Boyle,et al.  Automatic performance model construction for the fast software exploration of new hardware designs , 2006, CASES '06.

[2]  Yanhong A. Liu,et al.  Systematic Derivation of Incremental Programs , 1995, Sci. Comput. Program..

[3]  Weijia Shang,et al.  Stack size reduction of recursive programs , 2007, CASES '07.

[4]  Yanhong A. Liu,et al.  From recursion to iteration: what are the optimizations? , 1999, PEPM '00.

[5]  Michael Leuschel Proceedings of the 2003 ACM SIGPLAN Workshop on Partial Evaluation and Semantics-based Program Manipulation, 2003, San Diego, California, USA, June 7, 2003 , 2003, PEPM.

[6]  John Darlington,et al.  A Transformation System for Developing Recursive Programs , 1977, J. ACM.

[7]  Weijia Shang,et al.  Live Range Splitting at Recursive Function Calls , 2007, 2007 Innovations in Information Technologies (IIT).

[8]  Jack B. Dennis Record of the Project MAC conference on concurrent systems and parallel computation , 1970 .

[9]  Alfred V. Aho,et al.  Compilers: Principles, Techniques, and Tools , 1986, Addison-Wesley series in computer science / World student series edition.

[10]  Yanhong A. Liu,et al.  Optimizing Ackermann's function by incrementalization , 2003, PPoPP 2003.

[11]  Yanhong A. Liu,et al.  Optimizing Ackermann's function by incrementalization , 2003, PEPM.

[12]  Helmuth Partsch,et al.  Specification and Transformation of Programs - A Formal Approach to Software Development , 1990, Texts and Monographs in Computer Science.

[13]  Seth D. Bergmann,et al.  Compilers , 1973, CSC '73.

[14]  Carl Hewitt,et al.  Comparative Schematology , 1970 .