Optimizing the stack size of recursive functions

  • Authors:
  • Stefan Schaeckeler;Weijia Shang

  • Affiliations:
  • Computer Engineering Department, Santa Clara University, 500 El Camino Real, Santa Clara, CA 95053, USA;Computer Engineering Department, Santa Clara University, 500 El Camino Real, Santa Clara, CA 95053, USA

  • Venue:
  • Computer Languages, Systems and Structures
  • Year:
  • 2009

Quantified Score

Hi-index 0.00

Visualization

Abstract

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.