skip to main content
article
Free Access

On the conversion of indirect to direct recursion

Published:01 March 1993Publication History
Skip Abstract Section

Abstract

Procedure inlining can be used to convert mutual recursion to direct recursion. This allows use of optimization techniques that are most easily applied to directly recursive procedures, in addition to the well-known benefits of inlining. We present tight (necessary and sufficient) conditions under which inlining can transform all mutual recursion to direct recursion, and those under which heuristics to eliminate mutual recursion always terminate. We also present a technique to eliminate mutually recursive circuits that consist of only tail calls. From this, we conclude that tail recursion elimination should be interleaved with inlining.

References

  1. BALL, J. 1982. Program improvement by the selective integration of procedure calls. Ph.D. thesis, Univ. of Rochester, Rochester, N.Y. Google ScholarGoogle Scholar
  2. CHANG, P., MAHLKE, S., CHEN, W., AND HWU, W. 1992. Profile-guided automatic inline expansion for C programs. Softw. Prac. Exp. 25, 5, 349-369. Google ScholarGoogle Scholar
  3. DAVIDSON, J., AND HOLLER, A. 1988. A study of a C function inliner. Soflw. Prac. Exp. 18, 8, 775-790. Google ScholarGoogle Scholar
  4. HARTLEY, S. 1988. Compile-time program restructuring in multiprogrammed virtual memory systems. IEEE Trans. Softw. Eng. 14, 11, 1640-1644. Google ScholarGoogle Scholar
  5. Hwu, W., AND CHANG, P. 1989a. Achieving high instruction cache performance with an optimizing compiler. In Proceedings of the 16th Annual Symposzum on Computer Architecture. ACM, New York, 242-251. Google ScholarGoogle Scholar
  6. Hwu, W., AND CHANG, P. 1989b. Inline function expansion for compiling C programs. In Procee&ngs of the SIGPLAN "89 Conference on Programming Language Design and Implementation. ACM, New York, 246-255. Google ScholarGoogle Scholar
  7. KASER, O. 1993. Inlining to reduce stack space. In the International Symposium on Programming Language Implementation and Logic Programming. Lecture Notes in Computer Science, vol. 714. Springer-Verlag, New York. Google ScholarGoogle Scholar
  8. KASER, O., PAWAGI, S., RAMAKRISHNAN, C., RAMAKRISHNAN, I., AND SEKAR, R. 1992a. Fast parallel implementations of lazy languages--the EQUALS experience. In Proceedings of the ACM Conference on LISP and Functional Programming. ACM, New York, 335-344. Google ScholarGoogle Scholar
  9. KASER, O., RAMAKRISHNAN, C., AND PAWAGI, S. 1992b. A new approach to inlining. Tech. Rep. 92/06, State Univ. of New York, Stony Brook, N.Y.Google ScholarGoogle Scholar
  10. MCFARLING, S. 1991. Procedure merging with instruction caches. In Proceedings of the SIG- PLAN '91 Conference on Programming Language Design and Implementation. ACM, New York, 71-79. Google ScholarGoogle Scholar
  11. PLUMER, L. 1990. Termination proofs for logic programs based on predicate inequalities. In Proceedings of the 7th international Conference on Logic Programming. 634-648. Google ScholarGoogle Scholar
  12. SCHEIFLER, R. 1977. An analysis of inline substitution for a structured programming language. Commun. ACM 20, 647-654. Google ScholarGoogle Scholar
  13. SKIENA, S. 1985. Compiler optimization by detecting recursive subprograms. In the 1985 ACM Annual Conference. ACM, New York, 403-411. Google ScholarGoogle Scholar
  14. THULASIRAMAN, K., AND SWAMI, M. 1992. Graphs: Theory and Algorithms. John Wiley and Sons, New York. Google ScholarGoogle Scholar
  15. WALTP.R, K. 1976. RecurMon analysi~ for compiler optimization. Commun. ACM 19, 514-516. Google ScholarGoogle Scholar

Index Terms

  1. On the conversion of indirect to direct recursion

      Recommendations

      Reviews

      R. Clayton

      Inline expansion replaces a call to a procedure with the procedure's body. Inline expansion, among other benefits, eliminates procedure call overhead and improves addressing locality. Recursion presents a problem, since a recursive call has an infinite inline expansion. In direct recursion, a procedure contains a call to itself; in indirect recursion, procedure A calls procedure B which (calls procedure C which…) calls procedure A. Direct recursion is preferred over indirect recursion because direct recursion is simpler to eliminate or simulate, and some program analyses can handle only direct recursion. The authors develop a nontrivial condition indicating when it is possible to convert indirect recursion to direct recursion, and give an algorithm for the conversion. They examine the interactions between expansion and tail-call elimination and show that the special case of indirect recursion involving only tail recursion can always be converted to direct recursion. The authors also show that the termination rule of not expanding directly recursive procedures is not by itself strong enough to avoid infinite expansion. The assumptions used in the paper are modest, the data structures used are common to compilers, and the analysis techniques are not expensive. The paper itself is short and clear.

      Access critical reviews of Computing literature here

      Become a reviewer for Computing Reviews.

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader